Skip to content

Commit

Permalink
Add tests for {f32,f64}::round_to_even() functions
Browse files Browse the repository at this point in the history
  • Loading branch information
dsprenkels committed Feb 18, 2021
1 parent 396a286 commit 68074e0
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 0 deletions.
18 changes: 18 additions & 0 deletions library/std/src/f32/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -201,12 +201,30 @@ fn test_round() {
assert_approx_eq!(1.3f32.round(), 1.0f32);
assert_approx_eq!(1.5f32.round(), 2.0f32);
assert_approx_eq!(1.7f32.round(), 2.0f32);
assert_approx_eq!(2.5f32.round(), 3.0f32);
assert_approx_eq!(0.0f32.round(), 0.0f32);
assert_approx_eq!((-0.0f32).round(), -0.0f32);
assert_approx_eq!((-1.0f32).round(), -1.0f32);
assert_approx_eq!((-1.3f32).round(), -1.0f32);
assert_approx_eq!((-1.5f32).round(), -2.0f32);
assert_approx_eq!((-1.7f32).round(), -2.0f32);
assert_approx_eq!((-2.5f32).round(), -3.0f32);
}

#[test]
fn test_round_to_even() {
assert_approx_eq!(1.0f32.round_to_even(), 1.0f32);
assert_approx_eq!(1.3f32.round_to_even(), 1.0f32);
assert_approx_eq!(1.5f32.round_to_even(), 2.0f32);
assert_approx_eq!(1.7f32.round_to_even(), 2.0f32);
assert_approx_eq!(2.5f32.round_to_even(), 2.0f32);
assert_approx_eq!(0.0f32.round_to_even(), 0.0f32);
assert_approx_eq!((-0.0f32).round_to_even(), -0.0f32);
assert_approx_eq!((-1.0f32).round_to_even(), -1.0f32);
assert_approx_eq!((-1.3f32).round_to_even(), -1.0f32);
assert_approx_eq!((-1.5f32).round_to_even(), -2.0f32);
assert_approx_eq!((-1.7f32).round_to_even(), -2.0f32);
assert_approx_eq!((-2.5f32).round_to_even(), -2.0f32);
}

#[test]
Expand Down
18 changes: 18 additions & 0 deletions library/std/src/f64/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -203,12 +203,30 @@ fn test_round() {
assert_approx_eq!(1.3f64.round(), 1.0f64);
assert_approx_eq!(1.5f64.round(), 2.0f64);
assert_approx_eq!(1.7f64.round(), 2.0f64);
assert_approx_eq!(2.5f64.round(), 3.0f64);
assert_approx_eq!(0.0f64.round(), 0.0f64);
assert_approx_eq!((-0.0f64).round(), -0.0f64);
assert_approx_eq!((-1.0f64).round(), -1.0f64);
assert_approx_eq!((-1.3f64).round(), -1.0f64);
assert_approx_eq!((-1.5f64).round(), -2.0f64);
assert_approx_eq!((-1.7f64).round(), -2.0f64);
assert_approx_eq!((-2.5f64).round(), -3.0f64);
}

#[test]
fn test_round_to_even() {
assert_approx_eq!(1.0f64.round_to_even(), 1.0f64);
assert_approx_eq!(1.3f64.round_to_even(), 1.0f64);
assert_approx_eq!(1.5f64.round_to_even(), 2.0f64);
assert_approx_eq!(1.7f64.round_to_even(), 2.0f64);
assert_approx_eq!(2.5f64.round_to_even(), 2.0f64);
assert_approx_eq!(0.0f64.round_to_even(), 0.0f64);
assert_approx_eq!((-0.0f64).round_to_even(), -0.0f64);
assert_approx_eq!((-1.0f64).round_to_even(), -1.0f64);
assert_approx_eq!((-1.3f64).round_to_even(), -1.0f64);
assert_approx_eq!((-1.5f64).round_to_even(), -2.0f64);
assert_approx_eq!((-1.7f64).round_to_even(), -2.0f64);
assert_approx_eq!((-2.5f64).round_to_even(), -2.0f64);
}

#[test]
Expand Down
1 change: 1 addition & 0 deletions library/std/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -302,6 +302,7 @@
#![feature(ptr_internals)]
#![feature(raw)]
#![feature(ready_macro)]
#![cfg_attr(not(bootstrap), feature(round_to_even))]
#![feature(rustc_attrs)]
#![feature(rustc_private)]
#![feature(shrink_to)]
Expand Down

0 comments on commit 68074e0

Please sign in to comment.