Skip to content

Commit b597eab

Browse files
authored
Merge pull request #763 from kennethbgoodin/fix_cmath_functions
[WIP] Implement cbrt and hypot function calls
2 parents 6ceb716 + 535914e commit b597eab

File tree

2 files changed

+17
-0
lines changed

2 files changed

+17
-0
lines changed

src/fn_call.rs

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -560,6 +560,20 @@ pub trait EvalContextExt<'a, 'mir, 'tcx: 'a + 'mir>: crate::MiriEvalContextExt<'
560560
let n = this.memory().get(ptr.alloc_id)?.read_c_str(tcx, ptr)?.len();
561561
this.write_scalar(Scalar::from_uint(n as u64, dest.layout.size), dest)?;
562562
}
563+
"cbrt" => {
564+
// FIXME: Using host floats.
565+
let f = f64::from_bits(this.read_scalar(args[0])?.to_u64()?);
566+
let n = f.cbrt();
567+
this.write_scalar(Scalar::from_u64(n.to_bits()), dest)?;
568+
}
569+
// underscore case for windows
570+
"_hypot" | "hypot" => {
571+
// FIXME: Using host floats.
572+
let f1 = f64::from_bits(this.read_scalar(args[0])?.to_u64()?);
573+
let f2 = f64::from_bits(this.read_scalar(args[1])?.to_u64()?);
574+
let n = f1.hypot(f2);
575+
this.write_scalar(Scalar::from_u64(n.to_bits()), dest)?;
576+
}
563577

564578
// Some things needed for `sys::thread` initialization to go through.
565579
"signal" | "sigaction" | "sigaltstack" => {

tests/run-pass/intrinsics-math.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,4 +66,7 @@ pub fn main() {
6666

6767
assert_approx_eq!(0.1f32.trunc(), 0.0f32);
6868
assert_approx_eq!((-0.1f64).trunc(), 0.0f64);
69+
70+
assert_approx_eq!(27f64.cbrt(), 3.0f64);
71+
assert_approx_eq!(3f64.hypot(4f64), 5.0f64);
6972
}

0 commit comments

Comments
 (0)