Skip to content

Commit

Permalink
Add tests for float in array comparison
Browse files Browse the repository at this point in the history
  • Loading branch information
briankabiro authored and marcin-serwin committed Apr 9, 2020
1 parent d440935 commit 0d00eaf
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 1 deletion.
7 changes: 7 additions & 0 deletions tests/ui/float_cmp.rs
Expand Up @@ -77,6 +77,13 @@ fn main() {

assert_eq!(a, b); // no errors

let a1: [f32; 1] = [0.0];
let a2: [f32; 1] = [1.1];

assert_eq!(a1[0], a2[0]);

assert_eq!(&a1[0], &a2[0]);

// no errors - comparing signums is ok
let x32 = 3.21f32;
1.23f32.signum() == x32.signum();
Expand Down
28 changes: 27 additions & 1 deletion tests/ui/float_cmp.stderr
Expand Up @@ -35,5 +35,31 @@ note: `f32::EPSILON` and `f64::EPSILON` are available.
LL | twice(x) != twice(ONE as f64);
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

error: aborting due to 3 previous errors
error: strict comparison of f32 or f64
--> $DIR/float_cmp.rs:83:5
|
LL | assert_eq!(a1[0], a2[0]);
| ^^^^^^^^^^^^^^^^^^^^^^^^^
|
note: std::f32::EPSILON and std::f64::EPSILON are available.
--> $DIR/float_cmp.rs:83:5
|
LL | assert_eq!(a1[0], a2[0]);
| ^^^^^^^^^^^^^^^^^^^^^^^^^
= note: this error originates in a macro outside of the current crate (in Nightly builds, run with -Z external-macro-backtrace for more info)

error: strict comparison of f32 or f64
--> $DIR/float_cmp.rs:85:5
|
LL | assert_eq!(&a1[0], &a2[0]);
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
note: std::f32::EPSILON and std::f64::EPSILON are available.
--> $DIR/float_cmp.rs:85:5
|
LL | assert_eq!(&a1[0], &a2[0]);
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^
= note: this error originates in a macro outside of the current crate (in Nightly builds, run with -Z external-macro-backtrace for more info)

error: aborting due to 5 previous errors

0 comments on commit 0d00eaf

Please sign in to comment.