Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Reorder expression of better accuracy #17

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

IanBriggs
Copy link

I think there is a typo in sincos.h that dramatically increases error for the sin and cos functions by parenthesizing an expression the wrong way. You can see a more detailed exploration in https://github.com/IanBriggs/vdt_cos_error, but in short, in sincos.h, line 123 is:

c = 1.0 - zz * .5 + zz * zz * get_cos_px(zz);

This adds 1.0 and -zz * .5 together first, but it's more accurate to go from smallest to largest magnitude, like this:

c = 1.0 + zz * (-.5 + zz * get_cos_px(zz));

This cuts the worst case error approximately in half for fast_cos on the domain $[0, \frac{\pi}{2}]$.

Here's a plot of error values versus MPFR over this interval:
Original_vs_Reordered_Absolute_Error

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant