1 | /* e_coshf.c -- float version of e_cosh.c. |
2 | * Conversion to float by Ian Lance Taylor, Cygnus Support, ian@cygnus.com. |
3 | * Optimizations by Ulrich Drepper <drepper@gmail.com>, 2011 |
4 | */ |
5 | |
6 | /* |
7 | * ==================================================== |
8 | * Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved. |
9 | * |
10 | * Developed at SunPro, a Sun Microsystems, Inc. business. |
11 | * Permission to use, copy, modify, and distribute this |
12 | * software is freely granted, provided that this notice |
13 | * is preserved. |
14 | * ==================================================== |
15 | */ |
16 | |
17 | #include <math.h> |
18 | #include <math-narrow-eval.h> |
19 | #include <math_private.h> |
20 | |
21 | static const float huge = 1.0e30; |
22 | static const float one = 1.0, half=0.5; |
23 | |
24 | float |
25 | __ieee754_coshf (float x) |
26 | { |
27 | float t,w; |
28 | int32_t ix; |
29 | |
30 | GET_FLOAT_WORD(ix,x); |
31 | ix &= 0x7fffffff; |
32 | |
33 | /* |x| in [0,22] */ |
34 | if (ix < 0x41b00000) { |
35 | /* |x| in [0,0.5*ln2], return 1+expm1(|x|)^2/(2*exp(|x|)) */ |
36 | if(ix<0x3eb17218) { |
37 | if (ix<0x24000000) return one; /* cosh(tiny) = 1 */ |
38 | t = __expm1f(fabsf(x)); |
39 | w = one+t; |
40 | return one+(t*t)/(w+w); |
41 | } |
42 | |
43 | /* |x| in [0.5*ln2,22], return (exp(|x|)+1/exp(|x|)/2; */ |
44 | t = __ieee754_expf(fabsf(x)); |
45 | return half*t+half/t; |
46 | } |
47 | |
48 | /* |x| in [22, log(maxdouble)] return half*exp(|x|) */ |
49 | if (ix < 0x42b17180) return half*__ieee754_expf(fabsf(x)); |
50 | |
51 | /* |x| in [log(maxdouble), overflowthresold] */ |
52 | if (ix<=0x42b2d4fc) { |
53 | w = __ieee754_expf(half*fabsf(x)); |
54 | t = half*w; |
55 | return t*w; |
56 | } |
57 | |
58 | /* x is INF or NaN */ |
59 | if(ix>=0x7f800000) return x*x; |
60 | |
61 | /* |x| > overflowthresold, cosh(x) overflow */ |
62 | return math_narrow_eval (huge*huge); |
63 | } |
64 | strong_alias (__ieee754_coshf, __coshf_finite) |
65 | |