Skip to content

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

Open
@scottmcm

Description

@scottmcm

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

Metadata

Metadata

Assignees

Labels

C-bugCategory: Clippy is not doing the correct thingI-false-positiveIssue: The lint was triggered on code it shouldn't have

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions