-
Notifications
You must be signed in to change notification settings - Fork 13.3k
Note atan2
can return -PI
#140487
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
base: master
Are you sure you want to change the base?
Note atan2
can return -PI
#140487
Conversation
rustbot has assigned @workingjubilee. Use |
atan2
can return -PI
/// * `x <= -0`, `y <= -0` -> `[-pi, -pi/2]` | ||
/// * `x >= +0`, `y <= -0` -> `[-pi/2, -0]` | ||
/// | ||
/// Note that positive and negative 0 are distinct floating point values. |
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.
This is always true, what's more important is that this description is not treating them as equal.
/// * `x = 0`, `y = 0`: `0` | ||
/// * `x >= 0`: `arctan(y/x)` -> `[-pi/2, pi/2]` | ||
/// * `y >= 0`: `arctan(y/x) + pi` -> `(pi/2, pi]` | ||
/// * `y < 0`: `arctan(y/x) - pi` -> `(-pi, -pi/2)` | ||
/// * `x >= +0`, `y >= +0` -> `[+0, pi/2]` | ||
/// * `x <= -0`, `y >= +0` -> `[pi/2, pi]` | ||
/// * `x <= -0`, `y <= -0` -> `[-pi, -pi/2]` | ||
/// * `x >= +0`, `y <= -0` -> `[-pi/2, -0]` |
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.
println!("{}", f32::atan2(-0.0, 0.0)); // -0
println!("{}", f32::atan2(0.0, -0.0)); // 3.1415927
println!("{}", f32::atan2(0.0, 0.0)); // 0
println!("{}", f32::atan2(-0.0, -0.0)); // -3.1415927
...that's kinda fucked up huh.
I think placing the comment about negative versus positive zero after this table-ish-thing makes it harder to read. We should lead with the comment that the sign of 0.0 can affect the result, rather than being treated as equal, even though (0.0 == -0.0) == true
.
Fixes #136275