]> git.lizzy.rs Git - rust.git/commitdiff
Auto merge of #885 - Aaron1011:fix/f-round, r=RalfJung
authorbors <bors@rust-lang.org>
Sun, 4 Aug 2019 20:12:02 +0000 (20:12 +0000)
committerbors <bors@rust-lang.org>
Sun, 4 Aug 2019 20:12:02 +0000 (20:12 +0000)
Add misssing 'roundf32' and 'roundf64' intrinsics

src/shims/intrinsics.rs
tests/run-pass/intrinsics-math.rs

index 920dc564e1546e440ede8ac6555926fc8c9ba622..52a17a92c2edabc84bd236edd439e28575342435 100644 (file)
@@ -225,7 +225,7 @@ fn call_intrinsic(
             }
 
             "sinf32" | "fabsf32" | "cosf32" | "sqrtf32" | "expf32" | "exp2f32" | "logf32" |
-            "log10f32" | "log2f32" | "floorf32" | "ceilf32" | "truncf32" => {
+            "log10f32" | "log2f32" | "floorf32" | "ceilf32" | "truncf32" | "roundf32" => {
                 // FIXME: Using host floats.
                 let f = f32::from_bits(this.read_scalar(args[0])?.to_u32()?);
                 let f = match intrinsic_name.get() {
@@ -241,13 +241,14 @@ fn call_intrinsic(
                     "floorf32" => f.floor(),
                     "ceilf32" => f.ceil(),
                     "truncf32" => f.trunc(),
+                    "roundf32" => f.round(),
                     _ => bug!(),
                 };
                 this.write_scalar(Scalar::from_u32(f.to_bits()), dest)?;
             }
 
             "sinf64" | "fabsf64" | "cosf64" | "sqrtf64" | "expf64" | "exp2f64" | "logf64" |
-            "log10f64" | "log2f64" | "floorf64" | "ceilf64" | "truncf64" => {
+            "log10f64" | "log2f64" | "floorf64" | "ceilf64" | "truncf64" | "roundf64" => {
                 // FIXME: Using host floats.
                 let f = f64::from_bits(this.read_scalar(args[0])?.to_u64()?);
                 let f = match intrinsic_name.get() {
@@ -263,6 +264,7 @@ fn call_intrinsic(
                     "floorf64" => f.floor(),
                     "ceilf64" => f.ceil(),
                     "truncf64" => f.trunc(),
+                    "roundf64" => f.round(),
                     _ => bug!(),
                 };
                 this.write_scalar(Scalar::from_u64(f.to_bits()), dest)?;
index 9a7a70bd00925e0ac58c7d6575710acba195d750..63098f5fd3f7480f7b6c420af0b10d3502bad129 100644 (file)
@@ -85,6 +85,9 @@ pub fn main() {
     assert_approx_eq!(1.0f32.tan(), 1.557408f32);
     assert_approx_eq!(1.0f64.tan(), 1.557408f64);
 
+    assert_eq!(3.3_f32.round(), 3.0);
+    assert_eq!(3.3_f64.round(), 3.0);
+
     extern {
         fn ldexp(x: f64, n: i32) -> f64;
     }