From: Kenny Goodin Date: Wed, 5 Jun 2019 05:26:46 +0000 (-0400) Subject: Implement cbrt and hypot function calls X-Git-Url: https://git.lizzy.rs/?a=commitdiff_plain;h=535914e3dcd65fd2bb2cbb02f505ef200169a547;p=rust.git Implement cbrt and hypot function calls Test cases are added to `tests/run-pass/intrinsics-math.rs` --- diff --git a/src/fn_call.rs b/src/fn_call.rs index 3d2c523bf70..b6b35bfc005 100644 --- a/src/fn_call.rs +++ b/src/fn_call.rs @@ -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" => { diff --git a/tests/run-pass/intrinsics-math.rs b/tests/run-pass/intrinsics-math.rs index 6b3d15a5091..504ef478979 100644 --- a/tests/run-pass/intrinsics-math.rs +++ b/tests/run-pass/intrinsics-math.rs @@ -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); }