/rust/registry/src/index.crates.io-1949cf8c6b5b557f/libm-0.2.11/src/math/sinhf.rs
Line | Count | Source |
1 | | use super::{expm1f, k_expo2f}; |
2 | | |
3 | | /// The hyperbolic sine of `x` (f32). |
4 | | #[cfg_attr(all(test, assert_no_panic), no_panic::no_panic)] |
5 | 0 | pub fn sinhf(x: f32) -> f32 { |
6 | 0 | let mut h = 0.5f32; |
7 | 0 | let mut ix = x.to_bits(); |
8 | 0 | if (ix >> 31) != 0 { |
9 | 0 | h = -h; |
10 | 0 | } |
11 | | /* |x| */ |
12 | 0 | ix &= 0x7fffffff; |
13 | 0 | let absx = f32::from_bits(ix); |
14 | 0 | let w = ix; |
15 | | |
16 | | /* |x| < log(FLT_MAX) */ |
17 | 0 | if w < 0x42b17217 { |
18 | 0 | let t = expm1f(absx); |
19 | 0 | if w < 0x3f800000 { |
20 | 0 | if w < (0x3f800000 - (12 << 23)) { |
21 | 0 | return x; |
22 | 0 | } |
23 | 0 | return h * (2. * t - t * t / (t + 1.)); |
24 | 0 | } |
25 | 0 | return h * (t + t / (t + 1.)); |
26 | 0 | } |
27 | | |
28 | | /* |x| > logf(FLT_MAX) or nan */ |
29 | 0 | 2. * h * k_expo2f(absx) |
30 | 0 | } |