]> git.lizzy.rs Git - rust.git/blob - src/docs/approx_constant.txt
Auto merge of #9421 - xphoniex:fix-#9420, r=giraffate
[rust.git] / src / docs / approx_constant.txt
1 ### What it does
2 Checks for floating point literals that approximate
3 constants which are defined in
4 [`std::f32::consts`](https://doc.rust-lang.org/stable/std/f32/consts/#constants)
5 or
6 [`std::f64::consts`](https://doc.rust-lang.org/stable/std/f64/consts/#constants),
7 respectively, suggesting to use the predefined constant.
8
9 ### Why is this bad?
10 Usually, the definition in the standard library is more
11 precise than what people come up with. If you find that your definition is
12 actually more precise, please [file a Rust
13 issue](https://github.com/rust-lang/rust/issues).
14
15 ### Example
16 ```
17 let x = 3.14;
18 let y = 1_f64 / x;
19 ```
20 Use instead:
21 ```
22 let x = std::f32::consts::PI;
23 let y = std::f64::consts::FRAC_1_PI;
24 ```