]> git.proxmox.com Git - rustc.git/blob - vendor/libm/src/math/coshf.rs
New upstream version 1.53.0+dfsg1
[rustc.git] / vendor / libm / src / math / coshf.rs
1 use super::expf;
2 use super::expm1f;
3 use super::k_expo2f;
4
5 /// Hyperbolic cosine (f64)
6 ///
7 /// Computes the hyperbolic cosine of the argument x.
8 /// Is defined as `(exp(x) + exp(-x))/2`
9 /// Angles are specified in radians.
10 #[inline]
11 #[cfg_attr(all(test, assert_no_panic), no_panic::no_panic)]
12 pub fn coshf(mut x: f32) -> f32 {
13 let x1p120 = f32::from_bits(0x7b800000); // 0x1p120f === 2 ^ 120
14
15 /* |x| */
16 let mut ix = x.to_bits();
17 ix &= 0x7fffffff;
18 x = f32::from_bits(ix);
19 let w = ix;
20
21 /* |x| < log(2) */
22 if w < 0x3f317217 {
23 if w < (0x3f800000 - (12 << 23)) {
24 force_eval!(x + x1p120);
25 return 1.;
26 }
27 let t = expm1f(x);
28 return 1. + t * t / (2. * (1. + t));
29 }
30
31 /* |x| < log(FLT_MAX) */
32 if w < 0x42b17217 {
33 let t = expf(x);
34 return 0.5 * (t + 1. / t);
35 }
36
37 /* |x| > log(FLT_MAX) or nan */
38 k_expo2f(x)
39 }