/rust/registry/src/index.crates.io-6f17d22bba15001f/libm-0.2.11/src/math/acosh.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 | | /// Inverse hyperbolic cosine (f64) |
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 acosh(x: f64) -> f64 { |
12 | 0 | let u = x.to_bits(); |
13 | 0 | let e = ((u >> 52) as usize) & 0x7ff; |
14 | 0 |
|
15 | 0 | /* x < 1 domain error is handled in the called functions */ |
16 | 0 |
|
17 | 0 | if e < 0x3ff + 1 { |
18 | | /* |x| < 2, up to 2ulp error in [1,1.125] */ |
19 | 0 | return log1p(x - 1.0 + sqrt((x - 1.0) * (x - 1.0) + 2.0 * (x - 1.0))); |
20 | 0 | } |
21 | 0 | if e < 0x3ff + 26 { |
22 | | /* |x| < 0x1p26 */ |
23 | 0 | return log(2.0 * x - 1.0 / (x + sqrt(x * x - 1.0))); |
24 | 0 | } |
25 | 0 | /* |x| >= 0x1p26 or nan */ |
26 | 0 | return log(x) + LN2; |
27 | 0 | } |