libm/math/
tanhf.rs
1use super::expm1f;
2
3#[cfg_attr(all(test, assert_no_panic), no_panic::no_panic)]
4pub fn tanhf(mut x: f32) -> f32 {
5 let mut ix = x.to_bits();
7 let sign = (ix >> 31) != 0;
8 ix &= 0x7fffffff;
9 x = f32::from_bits(ix);
10 let w = ix;
11
12 let tt = if w > 0x3f0c9f54 {
13 if w > 0x41200000 {
15 1. + 0. / x
17 } else {
18 let t = expm1f(2. * x);
19 1. - 2. / (t + 2.)
20 }
21 } else if w > 0x3e82c578 {
22 let t = expm1f(2. * x);
24 t / (t + 2.)
25 } else if w >= 0x00800000 {
26 let t = expm1f(-2. * x);
28 -t / (t + 2.)
29 } else {
30 force_eval!(x * x);
32 x
33 };
34 if sign {
35 -tt
36 } else {
37 tt
38 }
39}