Skip to content

Commit ff20010

Browse files
committed
Add shim for ldexp
1 parent 079b53e commit ff20010

File tree

2 files changed

+14
-2
lines changed

2 files changed

+14
-2
lines changed

src/shims/foreign_items.rs

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -603,7 +603,15 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx
603603
};
604604
this.write_scalar(Scalar::from_u64(n.to_bits()), dest)?;
605605
}
606-
606+
// underscore case for windows
607+
"_ldexp" | "ldexp" => {
608+
// FIXME: Using host floats.
609+
let x = f64::from_bits(this.read_scalar(args[0])?.to_u64()?);
610+
let exp = this.read_scalar(args[1])?.to_i32()?;
611+
// FIXME: We should use cmath if there are any imprecisions.
612+
let n = x * 2.0f64.powi(exp);
613+
this.write_scalar(Scalar::from_u64(n.to_bits()), dest)?;
614+
}
607615
// Some things needed for `sys::thread` initialization to go through.
608616
"signal" | "sigaction" | "sigaltstack" => {
609617
this.write_scalar(Scalar::from_int(0, dest.layout.size), dest)?;
@@ -973,4 +981,4 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx
973981
}
974982
return Ok(None);
975983
}
976-
}
984+
}

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)