Skip to content

Commit 68074e0

Browse files
committed
Add tests for {f32,f64}::round_to_even() functions
1 parent 396a286 commit 68074e0

File tree

3 files changed

+37
-0
lines changed

3 files changed

+37
-0
lines changed

library/std/src/f32/tests.rs

+18
Original file line numberDiff line numberDiff line change
@@ -201,12 +201,30 @@ fn test_round() {
201201
assert_approx_eq!(1.3f32.round(), 1.0f32);
202202
assert_approx_eq!(1.5f32.round(), 2.0f32);
203203
assert_approx_eq!(1.7f32.round(), 2.0f32);
204+
assert_approx_eq!(2.5f32.round(), 3.0f32);
204205
assert_approx_eq!(0.0f32.round(), 0.0f32);
205206
assert_approx_eq!((-0.0f32).round(), -0.0f32);
206207
assert_approx_eq!((-1.0f32).round(), -1.0f32);
207208
assert_approx_eq!((-1.3f32).round(), -1.0f32);
208209
assert_approx_eq!((-1.5f32).round(), -2.0f32);
209210
assert_approx_eq!((-1.7f32).round(), -2.0f32);
211+
assert_approx_eq!((-2.5f32).round(), -3.0f32);
212+
}
213+
214+
#[test]
215+
fn test_round_to_even() {
216+
assert_approx_eq!(1.0f32.round_to_even(), 1.0f32);
217+
assert_approx_eq!(1.3f32.round_to_even(), 1.0f32);
218+
assert_approx_eq!(1.5f32.round_to_even(), 2.0f32);
219+
assert_approx_eq!(1.7f32.round_to_even(), 2.0f32);
220+
assert_approx_eq!(2.5f32.round_to_even(), 2.0f32);
221+
assert_approx_eq!(0.0f32.round_to_even(), 0.0f32);
222+
assert_approx_eq!((-0.0f32).round_to_even(), -0.0f32);
223+
assert_approx_eq!((-1.0f32).round_to_even(), -1.0f32);
224+
assert_approx_eq!((-1.3f32).round_to_even(), -1.0f32);
225+
assert_approx_eq!((-1.5f32).round_to_even(), -2.0f32);
226+
assert_approx_eq!((-1.7f32).round_to_even(), -2.0f32);
227+
assert_approx_eq!((-2.5f32).round_to_even(), -2.0f32);
210228
}
211229

212230
#[test]

library/std/src/f64/tests.rs

+18
Original file line numberDiff line numberDiff line change
@@ -203,12 +203,30 @@ fn test_round() {
203203
assert_approx_eq!(1.3f64.round(), 1.0f64);
204204
assert_approx_eq!(1.5f64.round(), 2.0f64);
205205
assert_approx_eq!(1.7f64.round(), 2.0f64);
206+
assert_approx_eq!(2.5f64.round(), 3.0f64);
206207
assert_approx_eq!(0.0f64.round(), 0.0f64);
207208
assert_approx_eq!((-0.0f64).round(), -0.0f64);
208209
assert_approx_eq!((-1.0f64).round(), -1.0f64);
209210
assert_approx_eq!((-1.3f64).round(), -1.0f64);
210211
assert_approx_eq!((-1.5f64).round(), -2.0f64);
211212
assert_approx_eq!((-1.7f64).round(), -2.0f64);
213+
assert_approx_eq!((-2.5f64).round(), -3.0f64);
214+
}
215+
216+
#[test]
217+
fn test_round_to_even() {
218+
assert_approx_eq!(1.0f64.round_to_even(), 1.0f64);
219+
assert_approx_eq!(1.3f64.round_to_even(), 1.0f64);
220+
assert_approx_eq!(1.5f64.round_to_even(), 2.0f64);
221+
assert_approx_eq!(1.7f64.round_to_even(), 2.0f64);
222+
assert_approx_eq!(2.5f64.round_to_even(), 2.0f64);
223+
assert_approx_eq!(0.0f64.round_to_even(), 0.0f64);
224+
assert_approx_eq!((-0.0f64).round_to_even(), -0.0f64);
225+
assert_approx_eq!((-1.0f64).round_to_even(), -1.0f64);
226+
assert_approx_eq!((-1.3f64).round_to_even(), -1.0f64);
227+
assert_approx_eq!((-1.5f64).round_to_even(), -2.0f64);
228+
assert_approx_eq!((-1.7f64).round_to_even(), -2.0f64);
229+
assert_approx_eq!((-2.5f64).round_to_even(), -2.0f64);
212230
}
213231

214232
#[test]

library/std/src/lib.rs

+1
Original file line numberDiff line numberDiff line change
@@ -302,6 +302,7 @@
302302
#![feature(ptr_internals)]
303303
#![feature(raw)]
304304
#![feature(ready_macro)]
305+
#![cfg_attr(not(bootstrap), feature(round_to_even))]
305306
#![feature(rustc_attrs)]
306307
#![feature(rustc_private)]
307308
#![feature(shrink_to)]

0 commit comments

Comments
 (0)