]> git.lizzy.rs Git - rust.git/blob - src/docs/imprecise_flops.txt
[Arithmetic] Consider literals
[rust.git] / src / docs / imprecise_flops.txt
1 ### What it does
2 Looks for floating-point expressions that
3 can be expressed using built-in methods to improve accuracy
4 at the cost of performance.
5
6 ### Why is this bad?
7 Negatively impacts accuracy.
8
9 ### Example
10 ```
11 let a = 3f32;
12 let _ = a.powf(1.0 / 3.0);
13 let _ = (1.0 + a).ln();
14 let _ = a.exp() - 1.0;
15 ```
16
17 Use instead:
18 ```
19 let a = 3f32;
20 let _ = a.cbrt();
21 let _ = a.ln_1p();
22 let _ = a.exp_m1();
23 ```