`<{f16,f32,f64,f128} as Rem>::rem` documented definition is misleading w.r.t. intermediate rounding
Nobody has claimed this yet.
- Dominant language
- Rust
- Stars
- 119k
- Forks
- 16.1k
- PR merge metrics
- PR metrics pending
Description
Our documentation for impl Rem for {f16, f32, f64, f128} says:
The remainder has the same sign as the dividend and is computed as:
x - (x / y).trunc() * y.
But that's not true. E.g.:
fn main() {
let (x, y) = (11f64, 1.1f64);
assert_eq!(x - (x / y).trunc() * y, x % y);
//~^ PANIC
// assertion `left == right` failed
// left: 0.0
// right: 1.0999999999999992
}
This mismatch creates a hazard when trying to correctly encode algorithms that rely on this semantic.
This tripped me up, e.g., when authoring:
cc #133485 #107904
cc @cuviper @Noratrieb @tczajka @Neutron3529 @BartMassey
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 with the linked Rem implementation documentation and the displayed formula, then reproduce the Rust example with f64 values to observe the intermediate-rounding mismatch. Revise the documentation so it does not describe % as exactly that real-number formula, and verify that the updated wording accurately matches the demonstrated behavior.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- rust
- Domain
- documentation
- Issue type
- Documentation
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 48/100