blob: 5312a8b29c67a5a9841d3a3897f375e501baabee (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
|
#![feature(const_fn_floating_point_arithmetic)]
#![warn(clippy::suboptimal_flops)]
/// Allow suboptimal ops in constant context
pub const fn in_const_context(num: f64) -> f64 {
if num >= 0.0 { num } else { -num }
}
struct A {
a: f64,
b: f64,
}
fn fake_abs1(num: f64) -> f64 {
num.abs()
}
fn fake_abs2(num: f64) -> f64 {
num.abs()
}
fn fake_abs3(a: A) -> f64 {
a.a.abs()
}
fn fake_abs4(num: f64) -> f64 {
num.abs()
}
fn fake_abs5(a: A) -> f64 {
a.a.abs()
}
fn fake_nabs1(num: f64) -> f64 {
-num.abs()
}
fn fake_nabs2(num: f64) -> f64 {
-num.abs()
}
fn fake_nabs3(a: A) -> A {
A {
a: -a.a.abs(),
b: a.b,
}
}
fn not_fake_abs1(num: f64) -> f64 {
if num > 0.0 { num } else { -num - 1f64 }
}
fn not_fake_abs2(num: f64) -> f64 {
if num > 0.0 { num + 1.0 } else { -(num + 1.0) }
}
fn not_fake_abs3(num1: f64, num2: f64) -> f64 {
if num1 > 0.0 { num2 } else { -num2 }
}
fn not_fake_abs4(a: A) -> f64 {
if a.a > 0.0 { a.b } else { -a.b }
}
fn not_fake_abs5(a: A) -> f64 {
if a.a > 0.0 { a.a } else { -a.b }
}
fn main() {
fake_abs1(5.0);
fake_abs2(5.0);
fake_abs3(A { a: 5.0, b: 5.0 });
fake_abs4(5.0);
fake_abs5(A { a: 5.0, b: 5.0 });
fake_nabs1(5.0);
fake_nabs2(5.0);
fake_nabs3(A { a: 5.0, b: 5.0 });
not_fake_abs1(5.0);
not_fake_abs2(5.0);
not_fake_abs3(5.0, 5.0);
not_fake_abs4(A { a: 5.0, b: 5.0 });
not_fake_abs5(A { a: 5.0, b: 5.0 });
}
|