diff --git a/library/std/src/f32/tests.rs b/library/std/src/f32/tests.rs index 0d4b865f3392a..34df2688f6882 100644 --- a/library/std/src/f32/tests.rs +++ b/library/std/src/f32/tests.rs @@ -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] diff --git a/library/std/src/f64/tests.rs b/library/std/src/f64/tests.rs index 5c163cfe90e0b..a5d62f1a6e8f6 100644 --- a/library/std/src/f64/tests.rs +++ b/library/std/src/f64/tests.rs @@ -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] diff --git a/library/std/src/lib.rs b/library/std/src/lib.rs index 16733b7ccd353..5cfd59354ceb8 100644 --- a/library/std/src/lib.rs +++ b/library/std/src/lib.rs @@ -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)]