/rust/registry/src/index.crates.io-1949cf8c6b5b557f/libm-0.2.11/src/math/asinf.rs
Line | Count | Source |
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 | 0 | fn r(z: f32) -> f32 { |
28 | 0 | let p = z * (P_S0 + z * (P_S1 + z * P_S2)); |
29 | 0 | let q = 1. + z * Q_S1; |
30 | 0 | p / q |
31 | 0 | } |
32 | | |
33 | | /// Arcsine (f32) |
34 | | /// |
35 | | /// Computes the inverse sine (arc sine) of the argument `x`. |
36 | | /// Arguments to asin must be in the range -1 to 1. |
37 | | /// Returns values in radians, in the range of -pi/2 to pi/2. |
38 | | #[cfg_attr(all(test, assert_no_panic), no_panic::no_panic)] |
39 | 0 | pub fn asinf(mut x: f32) -> f32 { |
40 | 0 | let x1p_120 = f64::from_bits(0x3870000000000000); // 0x1p-120 === 2 ^ (-120) |
41 | | |
42 | 0 | let hx = x.to_bits(); |
43 | 0 | let ix = hx & 0x7fffffff; |
44 | | |
45 | 0 | if ix >= 0x3f800000 { |
46 | | /* |x| >= 1 */ |
47 | 0 | if ix == 0x3f800000 { |
48 | | /* |x| == 1 */ |
49 | 0 | return ((x as f64) * PIO2 + x1p_120) as f32; /* asin(+-1) = +-pi/2 with inexact */ |
50 | 0 | } |
51 | 0 | return 0. / (x - x); /* asin(|x|>1) is NaN */ |
52 | 0 | } |
53 | | |
54 | 0 | if ix < 0x3f000000 { |
55 | | /* |x| < 0.5 */ |
56 | | /* if 0x1p-126 <= |x| < 0x1p-12, avoid raising underflow */ |
57 | 0 | if (ix < 0x39800000) && (ix >= 0x00800000) { |
58 | 0 | return x; |
59 | 0 | } |
60 | 0 | return x + x * r(x * x); |
61 | 0 | } |
62 | | |
63 | | /* 1 > |x| >= 0.5 */ |
64 | 0 | let z = (1. - fabsf(x)) * 0.5; |
65 | 0 | let s = sqrt(z as f64); |
66 | 0 | x = (PIO2 - 2. * (s + s * (r(z) as f64))) as f32; |
67 | 0 | if (hx >> 31) != 0 { -x } else { x } |
68 | 0 | } |