Skip to content

Commit

Permalink
fix(clippy1): Updated code to test correctness clippy lint with appro…
Browse files Browse the repository at this point in the history
…x_constant lint rule

closes #888
  • Loading branch information
frvannes16 committed Dec 15, 2021
1 parent acaee79 commit f2650de
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 13 deletions.
16 changes: 11 additions & 5 deletions exercises/clippy/clippy1.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,16 @@

// I AM NOT DONE

use std::f32;

fn main() {
let x = 1.2331f64;
let y = 1.2332f64;
if y != x {
println!("Success!");
}
let pi = 3.14f32;
let radius = 5.00f32;

let area = pi * f32::powi(radius, 2);

println!(
"The area of a circle with radius {:.2} is {:.5}!",
radius, area
)
}
16 changes: 8 additions & 8 deletions info.toml
Original file line number Diff line number Diff line change
Expand Up @@ -906,15 +906,15 @@ name = "clippy1"
path = "exercises/clippy/clippy1.rs"
mode = "clippy"
hint = """
Not every floating point value can be represented exactly in binary values in
memory. Take a look at the description of
https://doc.rust-lang.org/stable/std/primitive.f32.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
usually not what you would like to do.
Rust stores the highest precision version of any long or inifinite precision
mathematical constants in the rust standard library.
https://doc.rust-lang.org/stable/std/f32/consts/index.html
We may be tempted to use our own approximations for certain mathematical constants,
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
machine epsilon value...
https://doc.rust-lang.org/stable/std/primitive.f32.html#associatedconstant.EPSILON"""
appropriate replacement constant from std::f32::consts..."""

[[exercises]]
name = "clippy2"
Expand Down

0 comments on commit f2650de

Please sign in to comment.