/rust/registry/src/index.crates.io-6f17d22bba15001f/libm-0.2.11/src/math/coshf.rs
Line | Count | Source (jump to first uncovered line) |
1 | | use super::{expf, expm1f, k_expo2f}; |
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 coshf(mut x: f32) -> f32 { |
10 | 0 | let x1p120 = f32::from_bits(0x7b800000); // 0x1p120f === 2 ^ 120 |
11 | 0 |
|
12 | 0 | /* |x| */ |
13 | 0 | let mut ix = x.to_bits(); |
14 | 0 | ix &= 0x7fffffff; |
15 | 0 | x = f32::from_bits(ix); |
16 | 0 | let w = ix; |
17 | 0 |
|
18 | 0 | /* |x| < log(2) */ |
19 | 0 | if w < 0x3f317217 { |
20 | 0 | if w < (0x3f800000 - (12 << 23)) { |
21 | 0 | force_eval!(x + x1p120); |
22 | 0 | return 1.; |
23 | 0 | } |
24 | 0 | let t = expm1f(x); |
25 | 0 | return 1. + t * t / (2. * (1. + t)); |
26 | 0 | } |
27 | 0 |
|
28 | 0 | /* |x| < log(FLT_MAX) */ |
29 | 0 | if w < 0x42b17217 { |
30 | 0 | let t = expf(x); |
31 | 0 | return 0.5 * (t + 1. / t); |
32 | 0 | } |
33 | 0 |
|
34 | 0 | /* |x| > log(FLT_MAX) or nan */ |
35 | 0 | k_expo2f(x) |
36 | 0 | } |