Skip to content

Commit c7b5e30

Browse files
committed
Add float cmp const tests for arrays
1 parent 3c738b2 commit c7b5e30

File tree

2 files changed

+26
-1
lines changed

2 files changed

+26
-1
lines changed

tests/ui/float_cmp_const.rs

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,4 +46,17 @@ fn main() {
4646
v != w;
4747
v == 1.0;
4848
v != 1.0;
49+
50+
const ZERO_ARRAY: [f32; 3] = [0.0, 0.0, 0.0];
51+
const ZERO_INF_ARRAY: [f32; 3] = [0.0, ::std::f32::INFINITY, ::std::f32::NEG_INFINITY];
52+
const NON_ZERO_ARRAY: [f32; 3] = [0.0, 0.1, 0.2];
53+
const NON_ZERO_ARRAY2: [f32; 3] = [0.2, 0.1, 0.0];
54+
55+
// no errors, zero and infinity values
56+
NON_ZERO_ARRAY[0] == NON_ZERO_ARRAY2[1]; // lhs is 0.0
57+
ZERO_ARRAY == NON_ZERO_ARRAY; // lhs is all zeros
58+
ZERO_INF_ARRAY == NON_ZERO_ARRAY; // lhs is all zeros or infinities
59+
60+
// has errors
61+
NON_ZERO_ARRAY == NON_ZERO_ARRAY2;
4962
}

tests/ui/float_cmp_const.stderr

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,5 +83,17 @@ note: `f32::EPSILON` and `f64::EPSILON` are available.
8383
LL | v != ONE;
8484
| ^^^^^^^^
8585

86-
error: aborting due to 7 previous errors
86+
error: strict comparison of `f32` or `f64` constant
87+
--> $DIR/float_cmp_const.rs:61:5
88+
|
89+
LL | NON_ZERO_ARRAY == NON_ZERO_ARRAY2;
90+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
91+
|
92+
note: `std::f32::EPSILON` and `std::f64::EPSILON` are available.
93+
--> $DIR/float_cmp_const.rs:61:5
94+
|
95+
LL | NON_ZERO_ARRAY == NON_ZERO_ARRAY2;
96+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
97+
98+
error: aborting due to 8 previous errors
8799

0 commit comments

Comments
 (0)