Out of range float casts miscompilation
Open
Nobody has claimed this yet.
bug
- Dominant language
- C++
- Stars
- 2.9k
- Forks
- 230
- Avg merge
- 19h 55m
- Merged PRs (30d)
- 67
Description
I tried this code:
pub fn foo() -> f32 {
0xffff_ffff_ffff_ffff_ffff_ffff_ffff_ffffu128 as f32
}
I expected to see this happen: Saturating to f32::INFINITY
Instead, this happened: 9223372000000000000.0 is returned
Another case is
pub fn foo() -> f32 {
1<an absolutely huge amount of zeros>u128 as f32
}
which should give an out of range error, but returns 0.0.
Meta
- What version of Rust GCC were you using, git sha if possible: The current version at godbolt.
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 by reproducing both Rust snippets with the current gccrs version or the Godbolt setup referenced in the issue, and compare their results with the expected saturating conversion behavior. Trace the compiler handling of out-of-range u128-to-f32 casts; done means both examples produce the specified results and regression coverage is added where the relevant tests are found.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- rust
- Domain
- compilers
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100