Coverage Report

Created: 2025-07-11 06:39

/rust/registry/src/index.crates.io-6f17d22bba15001f/libm-0.2.11/src/math/asinh.rs
Line
Count
Source (jump to first uncovered line)
1
use super::{log, log1p, sqrt};
2
3
const LN2: f64 = 0.693147180559945309417232121458176568; /* 0x3fe62e42,  0xfefa39ef*/
4
5
/* asinh(x) = sign(x)*log(|x|+sqrt(x*x+1)) ~= x - x^3/6 + o(x^5) */
6
/// Inverse hyperbolic sine (f64)
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 asinh(mut x: f64) -> f64 {
12
0
    let mut u = x.to_bits();
13
0
    let e = ((u >> 52) as usize) & 0x7ff;
14
0
    let sign = (u >> 63) != 0;
15
0
16
0
    /* |x| */
17
0
    u &= (!0) >> 1;
18
0
    x = f64::from_bits(u);
19
0
20
0
    if e >= 0x3ff + 26 {
21
0
        /* |x| >= 0x1p26 or inf or nan */
22
0
        x = log(x) + LN2;
23
0
    } else if e >= 0x3ff + 1 {
24
0
        /* |x| >= 2 */
25
0
        x = log(2.0 * x + 1.0 / (sqrt(x * x + 1.0) + x));
26
0
    } else if e >= 0x3ff - 26 {
27
0
        /* |x| >= 0x1p-26, up to 1.6ulp error in [0.125,0.5] */
28
0
        x = log1p(x + x * x / (sqrt(x * x + 1.0) + 1.0));
29
0
    } else {
30
0
        /* |x| < 0x1p-26, raise inexact if x != 0 */
31
0
        let x1p120 = f64::from_bits(0x4770000000000000);
32
0
        force_eval!(x + x1p120);
33
0
    }
34
35
0
    if sign { -x } else { x }
36
0
}