Skip to content

Commit 644e2a7

Browse files
committed
Auto merge of #1067 - Aaron1011:feature/inverse-trig, r=RalfJung
Add acos, asin, and atan foreign functions I copied the tests from the docs pages
2 parents 0fffa97 + a328683 commit 644e2a7

File tree

2 files changed

+17
-2
lines changed

2 files changed

+17
-2
lines changed

src/shims/foreign_items.rs

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -496,14 +496,17 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx
496496
}
497497

498498
// math functions
499-
"cbrtf" | "coshf" | "sinhf" | "tanf" => {
499+
"cbrtf" | "coshf" | "sinhf" | "tanf" | "acosf" | "asinf" | "atanf" => {
500500
// FIXME: Using host floats.
501501
let f = f32::from_bits(this.read_scalar(args[0])?.to_u32()?);
502502
let f = match link_name {
503503
"cbrtf" => f.cbrt(),
504504
"coshf" => f.cosh(),
505505
"sinhf" => f.sinh(),
506506
"tanf" => f.tan(),
507+
"acosf" => f.acos(),
508+
"asinf" => f.asin(),
509+
"atanf" => f.atan(),
507510
_ => bug!(),
508511
};
509512
this.write_scalar(Scalar::from_u32(f.to_bits()), dest)?;
@@ -521,14 +524,17 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx
521524
this.write_scalar(Scalar::from_u32(n.to_bits()), dest)?;
522525
}
523526

524-
"cbrt" | "cosh" | "sinh" | "tan" => {
527+
"cbrt" | "cosh" | "sinh" | "tan" | "acos" | "asin" | "atan" => {
525528
// FIXME: Using host floats.
526529
let f = f64::from_bits(this.read_scalar(args[0])?.to_u64()?);
527530
let f = match link_name {
528531
"cbrt" => f.cbrt(),
529532
"cosh" => f.cosh(),
530533
"sinh" => f.sinh(),
531534
"tan" => f.tan(),
535+
"acos" => f.acos(),
536+
"asin" => f.asin(),
537+
"atan" => f.atan(),
532538
_ => bug!(),
533539
};
534540
this.write_scalar(Scalar::from_u64(f.to_bits()), dest)?;

tests/run-pass/intrinsics-math.rs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,15 @@ pub fn main() {
9292
assert_approx_eq!(1.0f32.tan(), 1.557408f32);
9393
assert_approx_eq!(1.0f64.tan(), 1.557408f64);
9494

95+
assert_approx_eq!(f32::consts::FRAC_PI_4.cos().acos(), f32::consts::FRAC_PI_4);
96+
assert_approx_eq!(f64::consts::FRAC_PI_4.cos().acos(), f64::consts::FRAC_PI_4);
97+
98+
assert_approx_eq!(f32::consts::FRAC_PI_4.sin().asin(), f32::consts::FRAC_PI_4);
99+
assert_approx_eq!(f64::consts::FRAC_PI_4.sin().asin(), f64::consts::FRAC_PI_4);
100+
101+
assert_approx_eq!(1.0_f32, 1.0_f32.tan().atan());
102+
assert_approx_eq!(1.0_f64, 1.0_f64.tan().atan());
103+
95104
assert_eq!(3.3_f32.round(), 3.0);
96105
assert_eq!(3.3_f64.round(), 3.0);
97106

0 commit comments

Comments
 (0)