fix(clippy1): Updated code to test correctness clippy lint with approx_constant lint rule
closes #888
This commit is contained in:
parent
acaee79994
commit
f2650de369
@ -8,10 +8,16 @@
|
|||||||
|
|
||||||
// I AM NOT DONE
|
// I AM NOT DONE
|
||||||
|
|
||||||
|
use std::f32;
|
||||||
|
|
||||||
fn main() {
|
fn main() {
|
||||||
let x = 1.2331f64;
|
let pi = 3.14f32;
|
||||||
let y = 1.2332f64;
|
let radius = 5.00f32;
|
||||||
if y != x {
|
|
||||||
println!("Success!");
|
let area = pi * f32::powi(radius, 2);
|
||||||
}
|
|
||||||
|
println!(
|
||||||
|
"The area of a circle with radius {:.2} is {:.5}!",
|
||||||
|
radius, area
|
||||||
|
)
|
||||||
}
|
}
|
||||||
|
16
info.toml
16
info.toml
@ -906,15 +906,15 @@ name = "clippy1"
|
|||||||
path = "exercises/clippy/clippy1.rs"
|
path = "exercises/clippy/clippy1.rs"
|
||||||
mode = "clippy"
|
mode = "clippy"
|
||||||
hint = """
|
hint = """
|
||||||
Not every floating point value can be represented exactly in binary values in
|
Rust stores the highest precision version of any long or inifinite precision
|
||||||
memory. Take a look at the description of
|
mathematical constants in the rust standard library.
|
||||||
https://doc.rust-lang.org/stable/std/primitive.f32.html
|
https://doc.rust-lang.org/stable/std/f32/consts/index.html
|
||||||
When using the binary compare operators with floating points you won't compare
|
|
||||||
the floating point values but the binary representation in memory. This is
|
We may be tempted to use our own approximations for certain mathematical constants,
|
||||||
usually not what you would like to do.
|
but clippy recognizes those imprecise mathematical constants as a source of
|
||||||
|
potential error.
|
||||||
See the suggestions of the clippy warning in compile output and use the
|
See the suggestions of the clippy warning in compile output and use the
|
||||||
machine epsilon value...
|
appropriate replacement constant from std::f32::consts..."""
|
||||||
https://doc.rust-lang.org/stable/std/primitive.f32.html#associatedconstant.EPSILON"""
|
|
||||||
|
|
||||||
[[exercises]]
|
[[exercises]]
|
||||||
name = "clippy2"
|
name = "clippy2"
|
||||||
|
Loading…
Reference in New Issue
Block a user