rust-lang / rust-lang/rust-clippy

`cast_precision_loss` is a bit misleading for `float`s

Open
#10,075 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
Rust
Stars
13.5k
Forks
2.2k
Avg merge
2d 10h
Merged PRs (30d)
32

Description

Description

I have this code

#[warn(clippy::cast_precision_loss)]
fn div_usize_as_f64(n: usize, d: usize) -> f64 {
	n as f64 / d as f64
}

I get the following msg

warning: casting `usize` to `f64` causes a loss of precision on targets with 64-bit wide pointers (`usize` is 64 bits wide, but `f64`'s mantissa is only 52 bits wide)

"mantissa is 52bits" is true, but the implicit bit makes the "effective mantissa" 53b instead. I suggest making the message "more correct" by saying something like "maximum f64 value is 2u64.pow(53) - 1"

Version

No response

Additional Labels

No response

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

The issue identifies Rust Clippy's cast_precision_loss lint and the warning text that is misleading for f64. Start by locating that lint and its diagnostic or UI test coverage; done means the wording accurately reflects effective f64 precision and the relevant test expectations pass.

Written by the indexing model from the issue text.

Assessment

Tech stack
rust
Domain
devtools
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
42/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.