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