Coverage Report

Created: 2025-07-11 06:39

/rust/registry/src/index.crates.io-6f17d22bba15001f/libm-0.2.11/src/math/cosh.rs
Line
Count
Source (jump to first uncovered line)
1
use super::{exp, expm1, k_expo2};
2
3
/// Hyperbolic cosine (f64)
4
///
5
/// Computes the hyperbolic cosine of the argument x.
6
/// Is defined as `(exp(x) + exp(-x))/2`
7
/// Angles are specified in radians.
8
#[cfg_attr(all(test, assert_no_panic), no_panic::no_panic)]
9
0
pub fn cosh(mut x: f64) -> f64 {
10
0
    /* |x| */
11
0
    let mut ix = x.to_bits();
12
0
    ix &= 0x7fffffffffffffff;
13
0
    x = f64::from_bits(ix);
14
0
    let w = ix >> 32;
15
0
16
0
    /* |x| < log(2) */
17
0
    if w < 0x3fe62e42 {
18
0
        if w < 0x3ff00000 - (26 << 20) {
19
0
            let x1p120 = f64::from_bits(0x4770000000000000);
20
0
            force_eval!(x + x1p120);
21
0
            return 1.;
22
0
        }
23
0
        let t = expm1(x); // exponential minus 1
24
0
        return 1. + t * t / (2. * (1. + t));
25
0
    }
26
0
27
0
    /* |x| < log(DBL_MAX) */
28
0
    if w < 0x40862e42 {
29
0
        let t = exp(x);
30
0
        /* note: if x>log(0x1p26) then the 1/t is not needed */
31
0
        return 0.5 * (t + 1. / t);
32
0
    }
33
0
34
0
    /* |x| > log(DBL_MAX) or nan */
35
0
    k_expo2(x)
36
0
}