1 use super::{expm1, expo2};
2 
3 // sinh(x) = (exp(x) - 1/exp(x))/2
4 //         = (exp(x)-1 + (exp(x)-1)/exp(x))/2
5 //         = x + x^3/6 + o(x^5)
6 //
7 #[cfg_attr(all(test, assert_no_panic), no_panic::no_panic)]
sinh(x: f64) -> f648 pub fn sinh(x: f64) -> f64 {
9     // union {double f; uint64_t i;} u = {.f = x};
10     // uint32_t w;
11     // double t, h, absx;
12 
13     let mut uf: f64 = x;
14     let mut ui: u64 = f64::to_bits(uf);
15     let w: u32;
16     let t: f64;
17     let mut h: f64;
18     let absx: f64;
19 
20     h = 0.5;
21     if ui >> 63 != 0 {
22         h = -h;
23     }
24     /* |x| */
25     ui &= !1 / 2;
26     uf = f64::from_bits(ui);
27     absx = uf;
28     w = (ui >> 32) as u32;
29 
30     /* |x| < log(DBL_MAX) */
31     if w < 0x40862e42 {
32         t = expm1(absx);
33         if w < 0x3ff00000 {
34             if w < 0x3ff00000 - (26 << 20) {
35                 /* note: inexact and underflow are raised by expm1 */
36                 /* note: this branch avoids spurious underflow */
37                 return x;
38             }
39             return h * (2.0 * t - t * t / (t + 1.0));
40         }
41         /* note: |x|>log(0x1p26)+eps could be just h*exp(x) */
42         return h * (t + t / (t + 1.0));
43     }
44 
45     /* |x| > log(DBL_MAX) or nan */
46     /* note: the result is stored to handle overflow */
47     t = 2.0 * h * expo2(absx);
48     t
49 }
50