]> git.lizzy.rs Git - rust.git/commitdiff
use apfloat for ldexp
authorRalf Jung <post@ralfj.de>
Fri, 9 Aug 2019 17:53:42 +0000 (19:53 +0200)
committerRalf Jung <post@ralfj.de>
Fri, 9 Aug 2019 17:54:01 +0000 (19:54 +0200)
src/shims/foreign_items.rs

index ba9b7ca27eb0514795cfd179bb8159fcd41e995b..d7c2b86c2c2de62185d13e0fdb02d7cb37dfaa0e 100644 (file)
@@ -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.