rust-lang / rust-lang/rust-clippy
false positive of lossy_float_literal for bigger powers of 2
Nobody has claimed this yet.
- Dominant language
- Rust
- Stars
- 13.5k
- Forks
- 2.2k
- Avg merge
- 2d 10h
- Merged PRs (30d)
- 32
Description
Powers of 2 which exceed the size of the mantissa seem to yield a lossy_float_literal warning even though those are perfectly representable.
I tried this code:
fn main() {
let x64 = 4_294_967_296_f64;
let x32 = 4_294_967_296_f32;
println!("x64 {:016x}", x64.to_bits());
println!("x32 {:08x}", x32.to_bits());
println!("x32 as x64 {:016x}", (x32 as f64).to_bits());
}
I expected to see this happen:
No clippy warnings.
Instead, this happened:
4_294_967_296_f32 get reported as not being covered by f32. The output shows that this value could successfully be converted into the expected bit-pattern.
x64 41f0000000000000
x32 4f800000
x32 as x64 41f0000000000000
Meta
cargo clippy -V: clippy 0.1.54 (e82b650 2021-06-20)rustc -Vv:rustc 1.55.0-nightly (e82b65026 2021-06-20) binary: rustc commit-hash: e82b65026dcadf0998e3abf9dabc677f63160de7 commit-date: 2021-06-20 host: x86_64-unknown-linux-gnu release: 1.55.0-nightly LLVM version: 12.0.1
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 the reported Rust example and locating the lossy_float_literal lint. Check how the lint evaluates the larger powers-of-two literals, then verify that the shown f32 value no longer produces a warning while the existing warning behavior remains covered.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- rust
- Domain
- tooling
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 40/100