]> git.lizzy.rs Git - rust.git/commitdiff
Implement cbrt and hypot function calls
authorKenny Goodin <kennethbgoodin@gmail.com>
Wed, 5 Jun 2019 05:26:46 +0000 (01:26 -0400)
committerKenny Goodin <kennethbgoodin@gmail.com>
Wed, 12 Jun 2019 19:44:30 +0000 (15:44 -0400)
Test cases are added to `tests/run-pass/intrinsics-math.rs`

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

index 3d2c523bf705a2cb7758f23bd0981b609574fac2..b6b35bfc005e1510cafd904a4193edc4b4e7f1f9 100644 (file)
@@ -560,6 +560,20 @@ fn emulate_foreign_item(
                 let n = this.memory().get(ptr.alloc_id)?.read_c_str(tcx, ptr)?.len();
                 this.write_scalar(Scalar::from_uint(n as u64, dest.layout.size), dest)?;
             }
+            "cbrt" => {
+                // FIXME: Using host floats.
+                let f = f64::from_bits(this.read_scalar(args[0])?.to_u64()?);
+                let n = f.cbrt();
+                this.write_scalar(Scalar::from_u64(n.to_bits()), dest)?;
+            }
+            // underscore case for windows
+            "_hypot" | "hypot" => {
+                // FIXME: Using host floats.
+                let f1 = f64::from_bits(this.read_scalar(args[0])?.to_u64()?);
+                let f2 = f64::from_bits(this.read_scalar(args[1])?.to_u64()?);
+                let n = f1.hypot(f2);
+                this.write_scalar(Scalar::from_u64(n.to_bits()), dest)?;
+            }
 
             // Some things needed for `sys::thread` initialization to go through.
             "signal" | "sigaction" | "sigaltstack" => {
index 6b3d15a5091fc80c2fab3f7b0667f57148aa254b..504ef47897953862ed0820cdf18c55895e95380a 100644 (file)
@@ -66,4 +66,7 @@ pub fn main() {
 
     assert_approx_eq!(0.1f32.trunc(), 0.0f32);
     assert_approx_eq!((-0.1f64).trunc(), 0.0f64);
+
+    assert_approx_eq!(27f64.cbrt(), 3.0f64);
+    assert_approx_eq!(3f64.hypot(4f64), 5.0f64);
 }