Skip to content
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

document rounding behavior of rint/nearbyint for ties #119656

Merged
merged 1 commit into from
Jan 7, 2024

Conversation

RalfJung
Copy link
Member

@RalfJung RalfJung commented Jan 6, 2024

It's not possible to change the rounding mode in Rust, so these intrinsics will always behave like roundeven.

@rustbot
Copy link
Collaborator

rustbot commented Jan 6, 2024

r? @Mark-Simulacrum

(rustbot has picked a reviewer for you, use r? to override)

@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 Jan 6, 2024
@RalfJung
Copy link
Member Author

RalfJung commented Jan 6, 2024

I opened llvm/llvm-project#77191 to clarify the docs on the LLVM side.

/// Returns the nearest integer to an `f32`. Changing the rounding mode is not possible in Rust,
/// so this rounds half-way cases to the number with an even least significant digit.
///
/// May raise an inexact floating-point exception if the argument is not an integer.
Copy link
Member

Choose a reason for hiding this comment

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

This exception isn't mentioned in the round_ties_even docs -- is this something we should be guarding against somehow? Is raising an exception UB, or does that just (guaranteed) abort the program? Feels... unhelpful to have a rounding function only allow exactly integer inputs.

Copy link
Member Author

Choose a reason for hiding this comment

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

This is an FP exception. All it does is set a bit in some register that Rust code is not allowed to read.

One can set up the FP environment to turn these exceptions into traps, but Rust doesn't permit that.

Copy link
Member

Choose a reason for hiding this comment

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

Sounds good, thanks.

@Mark-Simulacrum
Copy link
Member

@bors r+

@bors
Copy link
Contributor

bors commented Jan 6, 2024

📌 Commit 96acaff has been approved by Mark-Simulacrum

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 Jan 6, 2024
matthiaskrgr added a commit to matthiaskrgr/rust that referenced this pull request Jan 6, 2024
…crum

document rounding behavior of rint/nearbyint for ties

It's not possible to change the rounding mode in Rust, so these intrinsics will always behave like `roundeven`.
bors added a commit to rust-lang-ci/rust that referenced this pull request Jan 6, 2024
…iaskrgr

Rollup of 3 pull requests

Successful merges:

 - rust-lang#119654 (bump bootstrap dependencies)
 - rust-lang#119656 (document rounding behavior of rint/nearbyint for ties)
 - rust-lang#119657 (Fix typo in docs for slice::split_once, slice::rsplit_once)

r? `@ghost`
`@rustbot` modify labels: rollup
bors added a commit to rust-lang-ci/rust that referenced this pull request Jan 7, 2024
…mpiler-errors

Rollup of 6 pull requests

Successful merges:

 - rust-lang#119252 (rustc_mir_transform: Enforce `rustc::potential_query_instability` lint)
 - rust-lang#119548 (Use the current target instead of iterating over all targets)
 - rust-lang#119656 (document rounding behavior of rint/nearbyint for ties)
 - rust-lang#119657 (Fix typo in docs for slice::split_once, slice::rsplit_once)
 - rust-lang#119666 (Populate `yield` and `resume` types in MIR body while body is being initialized)
 - rust-lang#119679 (Ask for rustc version in diagnostic reports, remind users to update their toolchain)

r? `@ghost`
`@rustbot` modify labels: rollup
bors added a commit to rust-lang-ci/rust that referenced this pull request Jan 7, 2024
…mpiler-errors

Rollup of 6 pull requests

Successful merges:

 - rust-lang#119252 (rustc_mir_transform: Enforce `rustc::potential_query_instability` lint)
 - rust-lang#119548 (Use the current target instead of iterating over all targets)
 - rust-lang#119656 (document rounding behavior of rint/nearbyint for ties)
 - rust-lang#119657 (Fix typo in docs for slice::split_once, slice::rsplit_once)
 - rust-lang#119666 (Populate `yield` and `resume` types in MIR body while body is being initialized)
 - rust-lang#119679 (Ask for rustc version in diagnostic reports, remind users to update their toolchain)

r? `@ghost`
`@rustbot` modify labels: rollup
@bors bors merged commit e63a32e into rust-lang:master Jan 7, 2024
11 checks passed
@rustbot rustbot added this to the 1.77.0 milestone Jan 7, 2024
rust-timer added a commit to rust-lang-ci/rust that referenced this pull request Jan 7, 2024
Rollup merge of rust-lang#119656 - RalfJung:round-docs, r=Mark-Simulacrum

document rounding behavior of rint/nearbyint for ties

It's not possible to change the rounding mode in Rust, so these intrinsics will always behave like `roundeven`.
@RalfJung RalfJung deleted the round-docs branch January 7, 2024 16:27
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.

4 participants