Coverage Report

Created: 2025-07-18 06:22

/rust/registry/src/index.crates.io-6f17d22bba15001f/libm-0.2.11/src/math/asinhf.rs
Line
Count
Source (jump to first uncovered line)
1
use super::{log1pf, logf, sqrtf};
2
3
const LN2: f32 = 0.693147180559945309417232121458176568;
4
5
/* asinh(x) = sign(x)*log(|x|+sqrt(x*x+1)) ~= x - x^3/6 + o(x^5) */
6
/// Inverse hyperbolic sine (f32)
7
///
8
/// Calculates the inverse hyperbolic sine of `x`.
9
/// Is defined as `sgn(x)*log(|x|+sqrt(x*x+1))`.
10
#[cfg_attr(all(test, assert_no_panic), no_panic::no_panic)]
11
0
pub fn asinhf(mut x: f32) -> f32 {
12
0
    let u = x.to_bits();
13
0
    let i = u & 0x7fffffff;
14
0
    let sign = (u >> 31) != 0;
15
0
16
0
    /* |x| */
17
0
    x = f32::from_bits(i);
18
0
19
0
    if i >= 0x3f800000 + (12 << 23) {
20
0
        /* |x| >= 0x1p12 or inf or nan */
21
0
        x = logf(x) + LN2;
22
0
    } else if i >= 0x3f800000 + (1 << 23) {
23
0
        /* |x| >= 2 */
24
0
        x = logf(2.0 * x + 1.0 / (sqrtf(x * x + 1.0) + x));
25
0
    } else if i >= 0x3f800000 - (12 << 23) {
26
0
        /* |x| >= 0x1p-12, up to 1.6ulp error in [0.125,0.5] */
27
0
        x = log1pf(x + x * x / (sqrtf(x * x + 1.0) + 1.0));
28
0
    } else {
29
0
        /* |x| < 0x1p-12, raise inexact if x!=0 */
30
0
        let x1p120 = f32::from_bits(0x7b800000);
31
0
        force_eval!(x + x1p120);
32
0
    }
33
34
0
    if sign { -x } else { x }
35
0
}