From ff2001040f06bda894fb512684e34ea12deade6e Mon Sep 17 00:00:00 2001 From: Christian Poveda Date: Fri, 2 Aug 2019 13:42:10 -0500 Subject: [PATCH] Add shim for ldexp --- src/shims/foreign_items.rs | 12 ++++++++++-- tests/run-pass/intrinsics-math.rs | 4 ++++ 2 files changed, 14 insertions(+), 2 deletions(-) diff --git a/src/shims/foreign_items.rs b/src/shims/foreign_items.rs index bcfcda2fd01c..332132947823 100644 --- a/src/shims/foreign_items.rs +++ b/src/shims/foreign_items.rs @@ -603,7 +603,15 @@ fn emulate_foreign_item( }; this.write_scalar(Scalar::from_u64(n.to_bits()), dest)?; } - + // underscore case for windows + "_ldexp" | "ldexp" => { + // FIXME: Using host floats. + let x = f64::from_bits(this.read_scalar(args[0])?.to_u64()?); + let exp = this.read_scalar(args[1])?.to_i32()?; + // FIXME: We should use cmath if there are any imprecisions. + let n = x * 2.0f64.powi(exp); + this.write_scalar(Scalar::from_u64(n.to_bits()), dest)?; + } // Some things needed for `sys::thread` initialization to go through. "signal" | "sigaction" | "sigaltstack" => { this.write_scalar(Scalar::from_int(0, dest.layout.size), dest)?; @@ -973,4 +981,4 @@ fn eval_path_scalar(&mut self, path: &[&str]) -> InterpResult<'tcx, Option f64; + } + unsafe { assert_approx_eq!(ldexp(0.65f64, 3i32), 5.2f64); } }