libm/math/
acosf.rs
1use super::sqrtf::sqrtf;
17
18const PIO2_HI: f32 = 1.5707962513e+00; const PIO2_LO: f32 = 7.5497894159e-08; const P_S0: f32 = 1.6666586697e-01;
21const P_S1: f32 = -4.2743422091e-02;
22const P_S2: f32 = -8.6563630030e-03;
23const Q_S1: f32 = -7.0662963390e-01;
24
25fn r(z: f32) -> f32 {
26 let p = z * (P_S0 + z * (P_S1 + z * P_S2));
27 let q = 1. + z * Q_S1;
28 p / q
29}
30
31#[cfg_attr(all(test, assert_no_panic), no_panic::no_panic)]
37pub fn acosf(x: f32) -> f32 {
38 let x1p_120 = f32::from_bits(0x03800000); let z: f32;
41 let w: f32;
42 let s: f32;
43
44 let mut hx = x.to_bits();
45 let ix = hx & 0x7fffffff;
46 if ix >= 0x3f800000 {
48 if ix == 0x3f800000 {
49 if (hx >> 31) != 0 {
50 return 2. * PIO2_HI + x1p_120;
51 }
52 return 0.;
53 }
54 return 0. / (x - x);
55 }
56 if ix < 0x3f000000 {
58 if ix <= 0x32800000 {
59 return PIO2_HI + x1p_120;
61 }
62 return PIO2_HI - (x - (PIO2_LO - x * r(x * x)));
63 }
64 if (hx >> 31) != 0 {
66 z = (1. + x) * 0.5;
67 s = sqrtf(z);
68 w = r(z) * s - PIO2_LO;
69 return 2. * (PIO2_HI - (s + w));
70 }
71 z = (1. - x) * 0.5;
73 s = sqrtf(z);
74 hx = s.to_bits();
75 let df = f32::from_bits(hx & 0xfffff000);
76 let c = (z - df * df) / (s + df);
77 w = r(z) * s + c;
78 2. * (df + w)
79}