Skip to content

Conversation

DimitriiTrater
Copy link
Contributor

@DimitriiTrater DimitriiTrater commented Sep 11, 2025

Fixes #136275

@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 Sep 11, 2025
@rustbot
Copy link
Collaborator

rustbot commented Sep 11, 2025

r? @tgross35

rustbot has assigned @tgross35.
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

Copy link
Contributor

@GrigorenkoPV GrigorenkoPV left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe it would make more sense to rephrase the existing part in terms of >= +0.0 and <= -0.0 instead of adding a new section?

View changes since this review

@DimitriiTrater
Copy link
Contributor Author

If you take into account the signs of zeros in the function definition, then it will not make mathematical sense.
Signs of zeros in this context make sense only if we are talking about IEEE-754.
If you do it the way you say, then I need to remove the mathematical definition of the function from arctan and leave only the areas of incoming and outgoing values.

@DimitriiTrater
Copy link
Contributor Author

DimitriiTrater commented Sep 12, 2025

I can suggest this:
x >= +0, y >= +0: [0, π/2]
x <= -0, y >= +0: [π/2, π]
x >= +0, y <= -0: [-π/2, 0]
x <= -0, y <= -0: [-π, -π/2]

@GrigorenkoPV what do you think?

@GrigorenkoPV
Copy link
Contributor

Yes, this is what I had in mind, more or less. Though, probably with the sign included in the output too.

Also, not sure if the pi should be changed to π here.

@DimitriiTrater DimitriiTrater force-pushed the atan2_correctness_docs branch 2 times, most recently from b4d0c32 to 7236b23 Compare September 21, 2025 01:14
@GrigorenkoPV
Copy link
Contributor

GrigorenkoPV commented Sep 24, 2025

LGTM, but let's wait for the assigned reviewer

Comment on lines 560 to 563
/// * `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, -0]`
/// * `x <= -0`, `y >= +0`: `[+pi/2, +pi]`
/// * `x <= -0`, `y <= -0`: `[-pi, -pi/2]`
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think the mathematical representation is helpful to keep for the intuition. Maybe a table format would work nicely?

/// | `x`     | `y`     | Equivalent    | Range        |
/// |---------|---------|---------------|--------------|
/// | `>= +0` | `>= +0` | `arctan(y/x)` | `[+0, +π/2]` |
/// ...

Basically a combination of the piecewise bit from https://en.wikipedia.org/wiki/Atan2#Definition_and_computation with the format of https://en.wikipedia.org/wiki/Inverse_trigonometric_functions#Domains.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

While you're here, would you mind also adding a note about how self and other map to x and y? The (y, x) argument order can be a bit surprising.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I didn't understand. It's already has note about self (y), other(x).

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

With your approach, I can suggest this:

    ///  | `x`     | `y`     | Equivalent        | Range         |
    ///  |---------|---------|-------------------|---------------|
    ///  | `>= +0` | `>= +0` | `arctan(y/x)`     | `[+0, +π/2]`  |
    ///  | `>= +0` | `<= -0` | `arctan(y/x)`     | `[-pi/2, -0]` |
    ///  | `<= -0` | `>= +0` | `arctan(y/x) + pi`| `[+pi/2, +pi]`|
    ///  | `<= -0` | `<= -0` | `arctan(y/x) - pi`| `[-pi, -pi/2]`|

But from a mathematical point of view, the signed zero here has no meaning, so it looks a bit confusing. And equivalent here is not a true for x, y in this inequalities.
I can change "Equivalent" to "Expression used" or "Definition" so this will more reliable.

What do you think?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I didn't understand. It's already has note about self (y), other(x).

Ah yeah, totally overlooked that.

But from a mathematical point of view, the signed zero here has no meaning, so it looks a bit confusing.

What specifically? The current PR already makes use of +/-0, this seems reasonable to me.

I can change "Equivalent" to "Expression used" or "Definition" so this will more reliable.

"Definition" seems reasonable to me. Or maybe "Piecewise Definition".

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have updated PR, "Piecewise Definition" - really good.

@DimitriiTrater
Copy link
Contributor Author

So, what's next?

@tgross35
Copy link
Contributor

tgross35 commented Oct 3, 2025

So, what's next?

Me getting a chance to circle back :)

Looks excellent! Thank you for the updates, and @GrigorenkoPV for reviewing this.

@bors r+ rollup

@bors
Copy link
Collaborator

bors commented Oct 3, 2025

📌 Commit d834935 has been approved by tgross35

It is now in the queue for this repository.

@bors bors added S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Oct 3, 2025
Zalathar added a commit to Zalathar/rust that referenced this pull request Oct 4, 2025
…ocs, r=tgross35

Fix atan2 inaccuracy in documentation

Fixes rust-lang#136275
bors added a commit that referenced this pull request Oct 4, 2025
Rollup of 14 pull requests

Successful merges:

 - #142670 (Document fully-qualified syntax in `as`' keyword doc)
 - #144908 (Fix doctest output json)
 - #145685 (add CloneFromCell and Cell::get_cloned)
 - #146330 (Bump unicode_data and printables to version 17.0.0)
 - #146451 (Fix atan2 inaccuracy in documentation)
 - #146479 (add mem::conjure_zst)
 - #147190 (std: `sys::net` cleanups)
 - #147245 (only replace the intended comma in pattern suggestions)
 - #147251 (Do not assert that a change in global cache only happens when concurrent)
 - #147269 (Add regression test for 123953)
 - #147277 (Extract common logic for iterating over features)
 - #147280 (Return to needs-llvm-components being info-only)
 - #147292 (Respect `-Z` unstable options in `rustdoc --test`)
 - #147300 (Add xtensa arch to object file creation)

r? `@ghost`
`@rustbot` modify labels: rollup
Zalathar added a commit to Zalathar/rust that referenced this pull request Oct 4, 2025
…ocs, r=tgross35

Fix atan2 inaccuracy in documentation

Fixes rust-lang#136275
Zalathar added a commit to Zalathar/rust that referenced this pull request Oct 4, 2025
…ocs, r=tgross35

Fix atan2 inaccuracy in documentation

Fixes rust-lang#136275
Zalathar added a commit to Zalathar/rust that referenced this pull request Oct 4, 2025
…ocs, r=tgross35

Fix atan2 inaccuracy in documentation

Fixes rust-lang#136275
Zalathar added a commit to Zalathar/rust that referenced this pull request Oct 4, 2025
…ocs, r=tgross35

Fix atan2 inaccuracy in documentation

Fixes rust-lang#136275
bors added a commit that referenced this pull request Oct 4, 2025
Rollup of 14 pull requests

Successful merges:

 - #142670 (Document fully-qualified syntax in `as`' keyword doc)
 - #145685 (add CloneFromCell and Cell::get_cloned)
 - #146330 (Bump unicode_data and printables to version 17.0.0)
 - #146451 (Fix atan2 inaccuracy in documentation)
 - #146479 (add mem::conjure_zst)
 - #146874 (compiler: Hint at multiple crate versions if trait impl is for wrong ADT )
 - #147117 (interpret `#[used]` as `#[used(compiler)]` on illumos)
 - #147190 (std: `sys::net` cleanups)
 - #147251 (Do not assert that a change in global cache only happens when concurrent)
 - #147280 (Return to needs-llvm-components being info-only)
 - #147288 (compiletest: Make `DirectiveLine` responsible for name/value splitting)
 - #147309 (Add documentation about unwinding to wasm targets)
 - #147315 (bless autodiff batching test)
 - #147323 (Fix top level ui tests check in tidy)

r? `@ghost`
`@rustbot` modify labels: rollup
matthiaskrgr added a commit to matthiaskrgr/rust that referenced this pull request Oct 4, 2025
…ocs, r=tgross35

Fix atan2 inaccuracy in documentation

Fixes rust-lang#136275
bors added a commit that referenced this pull request Oct 4, 2025
Rollup of 11 pull requests

Successful merges:

 - #142670 (Document fully-qualified syntax in `as`' keyword doc)
 - #145685 (add CloneFromCell and Cell::get_cloned)
 - #146330 (Bump unicode_data and printables to version 17.0.0)
 - #146451 (Fix atan2 inaccuracy in documentation)
 - #146479 (add mem::conjure_zst)
 - #147117 (interpret `#[used]` as `#[used(compiler)]` on illumos)
 - #147190 (std: `sys::net` cleanups)
 - #147251 (Do not assert that a change in global cache only happens when concurrent)
 - #147280 (Return to needs-llvm-components being info-only)
 - #147288 (compiletest: Make `DirectiveLine` responsible for name/value splitting)
 - #147315 (bless autodiff batching test)

r? `@ghost`
`@rustbot` modify labels: rollup
matthiaskrgr added a commit to matthiaskrgr/rust that referenced this pull request Oct 4, 2025
…ocs, r=tgross35

Fix atan2 inaccuracy in documentation

Fixes rust-lang#136275
bors added a commit that referenced this pull request Oct 4, 2025
Rollup of 10 pull requests

Successful merges:

 - #142670 (Document fully-qualified syntax in `as`' keyword doc)
 - #145685 (add CloneFromCell and Cell::get_cloned)
 - #146330 (Bump unicode_data and printables to version 17.0.0)
 - #146451 (Fix atan2 inaccuracy in documentation)
 - #146479 (add mem::conjure_zst)
 - #147117 (interpret `#[used]` as `#[used(compiler)]` on illumos)
 - #147190 (std: `sys::net` cleanups)
 - #147251 (Do not assert that a change in global cache only happens when concurrent)
 - #147280 (Return to needs-llvm-components being info-only)
 - #147315 (bless autodiff batching test)

r? `@ghost`
`@rustbot` modify labels: rollup
@bors bors merged commit baea20b into rust-lang:master Oct 4, 2025
10 checks passed
@rustbot rustbot added this to the 1.92.0 milestone Oct 4, 2025
rust-timer added a commit that referenced this pull request Oct 4, 2025
Rollup merge of #146451 - DimitriiTrater:atan2_correctness_docs, r=tgross35

Fix atan2 inaccuracy in documentation

Fixes #136275
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. 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
5 participants