Change `rint` to `roundeven` in `round_ties_even` implementation
Nobody has claimed this yet.
- Dominant language
- Rust
- Stars
- 119k
- Forks
- 16.2k
- PR merge metrics
- PR metrics pending
Description
C has three reasonably similar ways to round a single float to even. I'll just copy the docs here, nearbyint:
Description
The
nearbyintfunctions round their argument to an integer value in floating-point format, using the current rounding direction and without raising the "inexact" floating-point exception.Returns
The
nearbyintfunctions return the rounded integer value.
rint:
Description
The rint functions differ from the nearbyint functions (7.12.9.3) only in that the rint functions may raise the "inexact" floating-point exception if the result differs in value from the argument
Returns
The rint functions return the rounded integer value.
And roundeven, which is available since C23:
Description
The roundeven functions round their argument to the nearest integer value in floating-point format, rounding halfway cases to even (that is, to the nearest value that is an even integer), regardless of the current rounding direction
Returns
The round functions return the rounded integer value.
We currently use rintf16, rintf32, rintf64, and rintf128 (e.g. https://doc.rust-lang.org/std/intrinsics/fn.rintf32.html) as the intrinsics to implement round_ties_even. These map to LLVM's rint and similar:
rint is not exactly what we want here because it is supposed to raise inexact. We should change to roundeven because it matches Rust's preference of ignoring rounding modes and never raising fp exceptions.
This may be blocked on platform support, e.g. https://github.com/llvm/llvm-project/issues/73588. that issue looks like it is about the vector version.
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start in compiler/rustc_codegen_llvm/src/intrinsic.rs at the rintf16, rintf32, rintf64, and rintf128 mappings used by round_ties_even. Check the linked LLVM support issue and verify that roundeven is available for the required platforms; done means the implementation uses roundeven semantics without depending on the current rounding mode or raising inexact.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- c, rust
- Domain
- compilers
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Clearly specified
- Newbie friendliness
- 42/100