Skip to content

Add round_to_even to floating point types #82273

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Add tests for {f32,f64}::round_to_even() functions
  • Loading branch information
dsprenkels committed Feb 18, 2021
commit ddd8edc843a6d8bc8b64d6fff20a96c78165d2d4
19 changes: 19 additions & 0 deletions library/std/src/f32/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -201,12 +201,31 @@ 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]
#[cfg(not(bootstrap))]
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
19 changes: 19 additions & 0 deletions library/std/src/f64/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -203,12 +203,31 @@ 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]
#[cfg(not(bootstrap))]
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