Skip to content

Commit d0e8850

Browse files
committed
Auto merge of #877 - christianpoveda:ldexp-shim, r=RalfJung
Add shim for ldexp Fixes #821 r? @RalfJung
2 parents a71ebf9 + c4cea03 commit d0e8850

File tree

2 files changed

+14
-1
lines changed

2 files changed

+14
-1
lines changed

src/shims/foreign_items.rs

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -602,6 +602,15 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx
602602
};
603603
this.write_scalar(Scalar::from_u64(n.to_bits()), dest)?;
604604
}
605+
// underscore case for windows
606+
"_ldexp" | "ldexp" => {
607+
// FIXME: Using host floats.
608+
let x = f64::from_bits(this.read_scalar(args[0])?.to_u64()?);
609+
let exp = this.read_scalar(args[1])?.to_i32()?;
610+
// FIXME: We should use cmath if there are any imprecisions.
611+
let n = x * 2.0f64.powi(exp);
612+
this.write_scalar(Scalar::from_u64(n.to_bits()), dest)?;
613+
}
605614

606615
// Some things needed for `sys::thread` initialization to go through.
607616
"signal" | "sigaction" | "sigaltstack" => {
@@ -974,4 +983,4 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx
974983
}
975984
return Ok(None);
976985
}
977-
}
986+
}

tests/run-pass/intrinsics-math.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,4 +85,8 @@ pub fn main() {
8585
assert_approx_eq!(1.0f32.tan(), 1.557408f32);
8686
assert_approx_eq!(1.0f64.tan(), 1.557408f64);
8787

88+
extern {
89+
fn ldexp(x: f64, n: i32) -> f64;
90+
}
91+
unsafe { assert_approx_eq!(ldexp(0.65f64, 3i32), 5.2f64); }
8892
}

0 commit comments

Comments
 (0)