Coverage Report

Created: 2025-08-26 06:41

/rust/registry/src/index.crates.io-6f17d22bba15001f/libm-0.2.11/src/math/acoshf.rs
Line
Count
Source (jump to first uncovered line)
1
use super::{log1pf, logf, sqrtf};
2
3
const LN2: f32 = 0.693147180559945309417232121458176568;
4
5
/// Inverse hyperbolic cosine (f32)
6
///
7
/// Calculates the inverse hyperbolic cosine of `x`.
8
/// Is defined as `log(x + sqrt(x*x-1))`.
9
/// `x` must be a number greater than or equal to 1.
10
#[cfg_attr(all(test, assert_no_panic), no_panic::no_panic)]
11
0
pub fn acoshf(x: f32) -> f32 {
12
0
    let u = x.to_bits();
13
0
    let a = u & 0x7fffffff;
14
0
15
0
    if a < 0x3f800000 + (1 << 23) {
16
        /* |x| < 2, invalid if x < 1 or nan */
17
        /* up to 2ulp error in [1,1.125] */
18
0
        return log1pf(x - 1.0 + sqrtf((x - 1.0) * (x - 1.0) + 2.0 * (x - 1.0)));
19
0
    }
20
0
    if a < 0x3f800000 + (12 << 23) {
21
        /* |x| < 0x1p12 */
22
0
        return logf(2.0 * x - 1.0 / (x + sqrtf(x * x - 1.0)));
23
0
    }
24
0
    /* x >= 0x1p12 */
25
0
    return logf(x) + LN2;
26
0
}