about summary refs log tree commit diff
path: root/library/std/src/f64
diff options
context:
space:
mode:
authorJules Bertholet <jules.bertholet@gmail.com>2022-03-25 02:44:16 -0400
committerJules Bertholet <julesbertholet@quoi.xyz>2022-12-11 01:20:17 -0500
commitbe681fefed254c06139ab055b07cfd6f8b30bacf (patch)
treeb0d913a5c11a472075da00e42463e81ab7ba090a /library/std/src/f64
parente1c91213ff80af5b87a197b784b40bcbc8cf3add (diff)
Add `round_ties_even` to `f32` and `f64`
Diffstat (limited to 'library/std/src/f64')
-rw-r--r--library/std/src/f64/tests.rs17
1 files changed, 17 insertions, 0 deletions
diff --git a/library/std/src/f64/tests.rs b/library/std/src/f64/tests.rs
index 5b039d445ce..2f84ff910f5 100644
--- a/library/std/src/f64/tests.rs
+++ b/library/std/src/f64/tests.rs
@@ -199,6 +199,7 @@ fn test_ceil() {
 
 #[test]
 fn test_round() {
+    assert_approx_eq!(2.5f64.round(), 3.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);
@@ -211,6 +212,22 @@ fn test_round() {
     assert_approx_eq!((-1.7f64).round(), -2.0f64);
 }
 
+#[cfg(not(bootstrap))]
+#[test]
+fn test_round_ties_even() {
+    assert_approx_eq!(2.5f64.round_ties_even(), 2.0f64);
+    assert_approx_eq!(1.0f64.round_ties_even(), 1.0f64);
+    assert_approx_eq!(1.3f64.round_ties_even(), 1.0f64);
+    assert_approx_eq!(1.5f64.round_ties_even(), 2.0f64);
+    assert_approx_eq!(1.7f64.round_ties_even(), 2.0f64);
+    assert_approx_eq!(0.0f64.round_ties_even(), 0.0f64);
+    assert_approx_eq!((-0.0f64).round_ties_even(), -0.0f64);
+    assert_approx_eq!((-1.0f64).round_ties_even(), -1.0f64);
+    assert_approx_eq!((-1.3f64).round_ties_even(), -1.0f64);
+    assert_approx_eq!((-1.5f64).round_ties_even(), -2.0f64);
+    assert_approx_eq!((-1.7f64).round_ties_even(), -2.0f64);
+}
+
 #[test]
 fn test_trunc() {
     assert_approx_eq!(1.0f64.trunc(), 1.0f64);