From 5e3035b6cbf02d29157ab5633142cf741e7b2361 Mon Sep 17 00:00:00 2001 From: Ralf Jung Date: Fri, 9 Aug 2019 19:53:42 +0200 Subject: [PATCH] use apfloat for ldexp --- src/shims/foreign_items.rs | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/src/shims/foreign_items.rs b/src/shims/foreign_items.rs index ba9b7ca27eb..d7c2b86c2c2 100644 --- a/src/shims/foreign_items.rs +++ b/src/shims/foreign_items.rs @@ -1,3 +1,6 @@ +use std::convert::TryInto; + +use rustc_apfloat::Float; use rustc::ty::layout::{Align, LayoutOf, Size}; use rustc::hir::def_id::DefId; use rustc::mir; @@ -591,14 +594,11 @@ fn emulate_foreign_item( } // underscore case for windows "_ldexp" | "ldexp" => { - // FIXME: Using host floats. - let x = f64::from_bits(this.read_scalar(args[0])?.to_u64()?); + let x = this.read_scalar(args[0])?.to_f64()?; let exp = this.read_scalar(args[1])?.to_i32()?; - extern { - fn ldexp(x: f64, n: i32) -> f64; - } - let n = unsafe { ldexp(x, exp) }; - this.write_scalar(Scalar::from_u64(n.to_bits()), dest)?; + // For radix-2 (binary) systems, `ldexp` and `scalbn` are the same. + let res = x.scalbn(exp.try_into().unwrap()); + this.write_scalar(Scalar::from_f64(res), dest)?; } // Some things needed for `sys::thread` initialization to go through. -- 2.44.0