-
Notifications
You must be signed in to change notification settings - Fork 25
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
atan #207
atan #207
Conversation
dsp/src/trig.rs
Outdated
/// The angle between the x-axis and the ray to the point (x,y). The | ||
/// result range is from i32::MIN to i32::MAX, where i32::MIN | ||
/// corresponds to an angle of -pi and i32::MAX corresponds to an | ||
/// angle of +pi. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is that really correct? i32::MAX != -i32::MIN
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think it's actually i32::MIN == -pi
and at the same time also i32::MIN == pi
. Then i32::MAX == pi*(1 - 1/(1 << 31))
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh, right that makes sense. It's also worth noting that i32::MIN
is not actually reachable. I can get i32::MAX
with atan2(0, i32::MIN)
. The closest results are 2147461318 and -2147461318 with atan2(1 << 16, i32::MIN))
and atan2(-1 << 16, i32::MIN))
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Minor nit.
Looks good!
dsp/src/trig.rs
Outdated
/// The angle between the x-axis and the ray to the point (x,y). The | ||
/// result range is from i32::MIN to i32::MAX, where i32::MIN | ||
/// corresponds to an angle of -pi and i32::MAX corresponds to an | ||
/// angle of +pi. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think it's actually i32::MIN == -pi
and at the same time also i32::MIN == pi
. Then i32::MAX == pi*(1 - 1/(1 << 31))
Bors r+ |
207: atan r=jordens a=matthuszagh Adds 2-argument arctangent function. Parameters and result are `i32` integers for fast computation. Only the 16 MSBs of the inputs are used (16 LSBs are discarded). The x and y inputs can range from -1 to 1, which corresponds to `i32::MIN` and `i32::MAX`, respectively. The output ranges from -pi to pi, which corresponds to `i32::MIN` and `i32::MAX`, respectively. - [godbolt](https://rust.godbolt.org/z/nahKrT) # Related - #206 Co-authored-by: Matt Huszagh <huszaghmatt@gmail.com>
Canceled. |
Bors r+ |
Build succeeded: |
Adds 2-argument arctangent function. Parameters and result are
i32
integers for fast computation. Only the 16 MSBs of the inputs are used (16 LSBs are discarded). The x and y inputs can range from -1 to 1, which corresponds toi32::MIN
andi32::MAX
, respectively. The output ranges from -pi to pi, which corresponds toi32::MIN
andi32::MAX
, respectively.Related