-
Notifications
You must be signed in to change notification settings - Fork 1.8k
Closed
Labels
A-lintArea: New lintsArea: New lintsL-correctnessLint: Belongs in the correctness lint groupLint: Belongs in the correctness lint group
Description
Would adding a lint to detect whole number floating-point literals that are lossy when represented as floats be something useful. Here are a few examples:
// f32 example
let _: f32 = 16_777_219.0; // represented as 16_777_220.0
let _: f32 = -16_777_219.0; // represented as -16_777_220.0
// f64 example
let _: f64 = 9_007_199_254_740_993.0; // represented as 9_007_199_254_740_992.0
let _: f64 = -9_007_199_254_740_993.0; // represented as -9_007_199_254_740_992.0
For f32
maybe we could suggest upcasting to an f64
. Not sure what we could suggest for f64
but we could at the least warn that the literal would be lossy. Would love to know your thoughts and if it is worth adding this to clippy then I can start working on it but if not feel free to close it.
Metadata
Metadata
Assignees
Labels
A-lintArea: New lintsArea: New lintsL-correctnessLint: Belongs in the correctness lint groupLint: Belongs in the correctness lint group