Skip to content

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

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

Conversation

whirlwindaster
Copy link

Fixes #136275

@rustbot
Copy link
Collaborator

rustbot commented Apr 29, 2025

r? @workingjubilee

rustbot has assigned @workingjubilee.
They will have a look at your PR within the next two weeks and either review your PR or reassign to another reviewer.

Use r? to explicitly pick a reviewer

@rustbot rustbot added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. T-libs Relevant to the library team, which will review and decide on the PR/issue. labels Apr 29, 2025
@workingjubilee workingjubilee changed the title Fix inaccurate atan2 documentation Note atan2 can return -PI Apr 30, 2025
/// * `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.
Copy link
Member

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.

Comment on lines -901 to +904
/// * `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]`
Copy link
Member

@workingjubilee workingjubilee Apr 30, 2025

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.

@rustbot rustbot added S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Apr 30, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. T-libs Relevant to the library team, which will review and decide on the PR/issue.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

f64::atan2 documentation error
3 participants