Skip to content

Commit 95912a0

Browse files
committed
Implement cbrt and hypot function calls
1 parent 6ab0147 commit 95912a0

File tree

2 files changed

+24
-0
lines changed

2 files changed

+24
-0
lines changed

src/fn_call.rs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -560,6 +560,17 @@ 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+
let f = this.read_scalar(args[0])?.to_f64()?;
565+
let n = f.cbrt();
566+
this.write_scalar(Scalar::from_f64(n), dest)?;
567+
}
568+
"hypot" => {
569+
let f1 = this.read_scalar(args[0])?.to_f64()?;
570+
let f2 = this.read_scalar(args[1])?.to_f64()?;
571+
let n = f1.hypot(f2);
572+
this.write_scalar(Scalar::from_f64(n), dest)?;
573+
}
563574

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

tests/run-pass/cmath.rs

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
fn cbrt(f: f64) -> f64 {
2+
f.cbrt()
3+
}
4+
5+
fn hypot(f1: f64, f2: f64) -> f64 {
6+
f1.hypot(f2)
7+
}
8+
9+
fn main() {
10+
assert_eq!(cbrt(4.3), 1.6261333316791686);
11+
12+
assert_eq!(hypot(3.0, 4.0), 5.0);
13+
}

0 commit comments

Comments
 (0)