-
Notifications
You must be signed in to change notification settings - Fork 110
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
M_NORMALIZE_RADIANS doesn't work #118
Comments
I noticed that p_cos_f32 uses M_NORMALIZE_RADIANS, but p_sin_f32 does not. |
I think they both should not use it, since functions are meant to calculate value for input from range: 0 to 2pi (as stated here) |
@mateunho Yeah I saw that. I think that should be revisited. Any client code using the functions would likely have to normalise the angles before calling and so we might as well do it, well and fast. |
I believe we can do this with a few bitwise operations/shifts and two multiplies: (from PR #117)
|
Those functions must have well defined domain of operation. For example: what if client code passes |
What am I looking at on that link? |
I'm just saying passing -2*pi should not be an issue the client code should have to worry about. It's outside the [0..2PI] range, but so what, it's perfectly valid for sin and cos and is confusing to have this arbitrary range imposed. And yes for As for throwing errors, that goes against the 'Super fast but no "belt AND suspenders"' approach of the project. |
@westonized
|
@mateunho Why are the normal IEEE-754 infinities not used? But I repeat, wouldn't checking go against that design goal? |
On a related note, the current implementations of sin and cos are inaccurate outside of about -pi to pi (and not even that great near +/0 pi). sin is off by about 0.6 at 2*pi, but only off by 2e-5 at pi. cos is worse. Unfortunately the test vectors currently used for the trig functions seem to be in the range [-1,1], where the approximations are quite good. I did a quick check where I expanded the range of the test vector for sincos to be [-pi, pi]. cos fails with a value of -1.001829 at -3.141593. That seems pretty bad to me. |
@kfitch yes I noticed that. I think that they are based on a series calculation, with not enough iterations. Buy that's not generally regarded as a good way to do it anyway. For one it's all floating point multiplies.
|
Claims to normalize to [-pi..pi]
Bad example:
M_NORMALIZE_RADIANS(3.141593)=-21.991148
In this PR #117 I have alternate function.
The text was updated successfully, but these errors were encountered: