Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

excessive_precision should not lint when it's so excessive as to be clearly intentional #13855

Open
scottmcm opened this issue Dec 20, 2024 · 0 comments
Labels
C-bug Category: Clippy is not doing the correct thing I-false-positive Issue: The lint was triggered on code it shouldn't have

Comments

@scottmcm
Copy link
Member

scottmcm commented Dec 20, 2024

Summary

Like how rust defines constants with clearly more precision than needed,

https://github.com/rust-lang/rust/blob/5dfe648b45659db8dd0a673a806bba3df84aa3af/library/core/src/num/f32.rs#L348-L358

For mathematical constants (that aren't already in fNN::consts) it's nice to just paste in the full value with way more precision that you could ever need, like

let γ = 0.5772156649015328606065120900824024310421;

That's 40 decimal sigfigs, aka about 132 binary sigfigs, which is well more than is needed for any built-in float type (even f128 is only ≈33 decimal sigfigs).

And changing that to

let γ = 0.577_215_7;

as clippy suggests obfuscates more than it helps, plus it makes it harder if you change from f32 to f64 in the future.

For constants that have just slightly too much precision, especially things that look like integers, this lint makes sense.

But when the coder is clearly not thinking that it'll be exactly representable -- I'll toss that 40 sigfig threshold as a first stab at how clippy could know that -- then telling them that there's excess precision is not valuable, and clippy should let it go.

(Other things you could consider here are things like suppressing it for consts defined with a type and a particularly-precise literal, or something.)

Lint Name

excessive_precision

Reproducer

No response

Version


Additional Labels

No response

@scottmcm scottmcm added C-bug Category: Clippy is not doing the correct thing I-false-positive Issue: The lint was triggered on code it shouldn't have labels Dec 20, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
C-bug Category: Clippy is not doing the correct thing I-false-positive Issue: The lint was triggered on code it shouldn't have
Projects
None yet
Development

No branches or pull requests

1 participant