]> git.proxmox.com Git - rustc.git/blob - vendor/libm-0.1.4/src/math/asinf.rs
New upstream version 1.74.1+dfsg1
[rustc.git] / vendor / libm-0.1.4 / src / math / asinf.rs
1 /* origin: FreeBSD /usr/src/lib/msun/src/e_asinf.c */
2 /*
3 * Conversion to float by Ian Lance Taylor, Cygnus Support, ian@cygnus.com.
4 */
5 /*
6 * ====================================================
7 * Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved.
8 *
9 * Developed at SunPro, a Sun Microsystems, Inc. business.
10 * Permission to use, copy, modify, and distribute this
11 * software is freely granted, provided that this notice
12 * is preserved.
13 * ====================================================
14 */
15
16 use super::fabsf::fabsf;
17 use super::sqrt::sqrt;
18
19 const PIO2: f64 = 1.570796326794896558e+00;
20
21 /* coefficients for R(x^2) */
22 const P_S0: f32 = 1.6666586697e-01;
23 const P_S1: f32 = -4.2743422091e-02;
24 const P_S2: f32 = -8.6563630030e-03;
25 const Q_S1: f32 = -7.0662963390e-01;
26
27 #[inline]
28 fn r(z: f32) -> f32 {
29 let p = z * (P_S0 + z * (P_S1 + z * P_S2));
30 let q = 1. + z * Q_S1;
31 p / q
32 }
33
34 /// Arcsine (f32)
35 ///
36 /// Computes the inverse sine (arc sine) of the argument `x`.
37 /// Arguments to asin must be in the range -1 to 1.
38 /// Returns values in radians, in the range of -pi/2 to pi/2.
39 #[inline]
40 #[cfg_attr(all(test, assert_no_panic), no_panic::no_panic)]
41 pub fn asinf(mut x: f32) -> f32 {
42 let x1p_120 = f64::from_bits(0x3870000000000000); // 0x1p-120 === 2 ^ (-120)
43
44 let hx = x.to_bits();
45 let ix = hx & 0x7fffffff;
46
47 if ix >= 0x3f800000 {
48 /* |x| >= 1 */
49 if ix == 0x3f800000 {
50 /* |x| == 1 */
51 return ((x as f64) * PIO2 + x1p_120) as f32; /* asin(+-1) = +-pi/2 with inexact */
52 }
53 return 0. / (x - x); /* asin(|x|>1) is NaN */
54 }
55
56 if ix < 0x3f000000 {
57 /* |x| < 0.5 */
58 /* if 0x1p-126 <= |x| < 0x1p-12, avoid raising underflow */
59 if (ix < 0x39800000) && (ix >= 0x00800000) {
60 return x;
61 }
62 return x + x * r(x * x);
63 }
64
65 /* 1 > |x| >= 0.5 */
66 let z = (1. - fabsf(x)) * 0.5;
67 let s = sqrt(z as f64);
68 x = (PIO2 - 2. * (s + s * (r(z) as f64))) as f32;
69 if (hx >> 31) != 0 {
70 -x
71 } else {
72 x
73 }
74 }