Implement cbrt and hypot function calls
Test cases are added to `tests/run-pass/intrinsics-math.rs`
This commit is contained in:
parent
6ceb716227
commit
535914e3dc
@ -560,6 +560,20 @@ pub trait EvalContextExt<'a, 'mir, 'tcx: 'a + 'mir>: crate::MiriEvalContextExt<'
|
||||
let n = this.memory().get(ptr.alloc_id)?.read_c_str(tcx, ptr)?.len();
|
||||
this.write_scalar(Scalar::from_uint(n as u64, dest.layout.size), dest)?;
|
||||
}
|
||||
"cbrt" => {
|
||||
// FIXME: Using host floats.
|
||||
let f = f64::from_bits(this.read_scalar(args[0])?.to_u64()?);
|
||||
let n = f.cbrt();
|
||||
this.write_scalar(Scalar::from_u64(n.to_bits()), dest)?;
|
||||
}
|
||||
// underscore case for windows
|
||||
"_hypot" | "hypot" => {
|
||||
// FIXME: Using host floats.
|
||||
let f1 = f64::from_bits(this.read_scalar(args[0])?.to_u64()?);
|
||||
let f2 = f64::from_bits(this.read_scalar(args[1])?.to_u64()?);
|
||||
let n = f1.hypot(f2);
|
||||
this.write_scalar(Scalar::from_u64(n.to_bits()), dest)?;
|
||||
}
|
||||
|
||||
// Some things needed for `sys::thread` initialization to go through.
|
||||
"signal" | "sigaction" | "sigaltstack" => {
|
||||
|
@ -66,4 +66,7 @@ pub fn main() {
|
||||
|
||||
assert_approx_eq!(0.1f32.trunc(), 0.0f32);
|
||||
assert_approx_eq!((-0.1f64).trunc(), 0.0f64);
|
||||
|
||||
assert_approx_eq!(27f64.cbrt(), 3.0f64);
|
||||
assert_approx_eq!(3f64.hypot(4f64), 5.0f64);
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user