Skip to content

Commit

Permalink
Implement cbrt and hypot function calls
Browse files Browse the repository at this point in the history
Test cases are added to `tests/run-pass/intrinsics-math.rs`
  • Loading branch information
kungfukennyg committed Jun 11, 2019
1 parent 48897d0 commit 0a42d0b
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 0 deletions.
11 changes: 11 additions & 0 deletions src/fn_call.rs
Original file line number Diff line number Diff line change
Expand Up @@ -560,6 +560,17 @@ 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" => {
let f = this.read_scalar(args[0])?.to_f64()?;
let n = f.cbrt();
this.write_scalar(Scalar::from_f64(n), dest)?;
}
"_hypot" | "hypot" => {
let f1 = this.read_scalar(args[0])?.to_f64()?;
let f2 = this.read_scalar(args[1])?.to_f64()?;
let n = f1.hypot(f2);
this.write_scalar(Scalar::from_f64(n), dest)?;
}

// Some things needed for `sys::thread` initialization to go through.
"signal" | "sigaction" | "sigaltstack" => {
Expand Down
3 changes: 3 additions & 0 deletions tests/run-pass/intrinsics-math.rs
Original file line number Diff line number Diff line change
Expand Up @@ -64,4 +64,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);
}

0 comments on commit 0a42d0b

Please sign in to comment.