Skip to content

Commit 5e3035b

Browse files
committed
use apfloat for ldexp
1 parent c1cb249 commit 5e3035b

File tree

1 file changed

+7
-7
lines changed

1 file changed

+7
-7
lines changed

src/shims/foreign_items.rs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
use std::convert::TryInto;
2+
3+
use rustc_apfloat::Float;
14
use rustc::ty::layout::{Align, LayoutOf, Size};
25
use rustc::hir::def_id::DefId;
36
use rustc::mir;
@@ -591,14 +594,11 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx
591594
}
592595
// underscore case for windows
593596
"_ldexp" | "ldexp" => {
594-
// FIXME: Using host floats.
595-
let x = f64::from_bits(this.read_scalar(args[0])?.to_u64()?);
597+
let x = this.read_scalar(args[0])?.to_f64()?;
596598
let exp = this.read_scalar(args[1])?.to_i32()?;
597-
extern {
598-
fn ldexp(x: f64, n: i32) -> f64;
599-
}
600-
let n = unsafe { ldexp(x, exp) };
601-
this.write_scalar(Scalar::from_u64(n.to_bits()), dest)?;
599+
// For radix-2 (binary) systems, `ldexp` and `scalbn` are the same.
600+
let res = x.scalbn(exp.try_into().unwrap());
601+
this.write_scalar(Scalar::from_f64(res), dest)?;
602602
}
603603

604604
// Some things needed for `sys::thread` initialization to go through.

0 commit comments

Comments
 (0)