1 /* origin: FreeBSD /usr/src/lib/msun/src/e_cosh.c */
3 * ====================================================
4 * Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved.
6 * Developed at SunSoft, a Sun Microsystems, Inc. business.
7 * Permission to use, copy, modify, and distribute this
8 * software is freely granted, provided that this notice
10 * ====================================================
14 * mathematically cosh(x) if defined to be (exp(x)+exp(-x))/2
15 * 1. Replace x by |x| (cosh(x) = cosh(-x)).
18 * 0 <= x <= ln2/2 : cosh(x) := 1 + -------------------
22 * ln2/2 <= x <= 22 : cosh(x) := -------------------
24 * 22 <= x <= lnovft : cosh(x) := exp(x)/2
25 * lnovft <= x <= ln2ovft: cosh(x) := exp(x/2)/2 * exp(x/2)
26 * ln2ovft < x : cosh(x) := inf (overflow)
29 * cosh(x) is |x| if x is +INF, -INF, or NaN.
30 * only cosh(0)=1 is exact for finite x.
37 union {double f; uint64_t i;} u = {.f = x};
42 u.i &= (uint64_t)-1/2;
46 /* |x| in [0,0.5*ln2], return 1+expm1(|x|)^2/(2*exp(|x|)) */
47 if (ix < 0x3fd62e43) {
51 return 1 + t*t/(2*(1+t));
54 /* |x| in [0.5*ln2,22], return (exp(|x|)+1/exp(|x|))/2; */
55 if (ix < 0x40360000) {
60 /* |x| in [22, log(maxdouble)] return 0.5*exp(|x|) */
64 /* |x| in [log(maxdouble), overflowthresold] */
68 /* overflow (or nan) */