The Android Open Source Project | 1dc9e47 | 2009-03-03 19:28:35 -0800 | [diff] [blame] | 1 | |
The Android Open Source Project | 1dc9e47 | 2009-03-03 19:28:35 -0800 | [diff] [blame] | 2 | /* |
| 3 | * ==================================================== |
| 4 | * Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved. |
| 5 | * |
| 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 |
| 9 | * is preserved. |
| 10 | * ==================================================== |
| 11 | */ |
| 12 | |
Elliott Hughes | 4088e3a | 2023-08-03 13:33:56 -0700 | [diff] [blame] | 13 | /* sinh(x) |
The Android Open Source Project | 1dc9e47 | 2009-03-03 19:28:35 -0800 | [diff] [blame] | 14 | * Method : |
| 15 | * mathematically sinh(x) if defined to be (exp(x)-exp(-x))/2 |
| 16 | * 1. Replace x by |x| (sinh(-x) = -sinh(x)). |
| 17 | * 2. |
| 18 | * E + E/(E+1) |
| 19 | * 0 <= x <= 22 : sinh(x) := --------------, E=expm1(x) |
| 20 | * 2 |
| 21 | * |
| 22 | * 22 <= x <= lnovft : sinh(x) := exp(x)/2 |
| 23 | * lnovft <= x <= ln2ovft: sinh(x) := exp(x/2)/2 * exp(x/2) |
| 24 | * ln2ovft < x : sinh(x) := x*shuge (overflow) |
| 25 | * |
| 26 | * Special cases: |
| 27 | * sinh(x) is |x| if x is +INF, -INF, or NaN. |
| 28 | * only sinh(0)=0 is exact for finite x. |
| 29 | */ |
| 30 | |
Elliott Hughes | 460ad74 | 2014-09-12 14:00:02 -0700 | [diff] [blame] | 31 | #include <float.h> |
| 32 | |
The Android Open Source Project | 1dc9e47 | 2009-03-03 19:28:35 -0800 | [diff] [blame] | 33 | #include "math.h" |
| 34 | #include "math_private.h" |
| 35 | |
| 36 | static const double one = 1.0, shuge = 1.0e307; |
| 37 | |
| 38 | double |
Elliott Hughes | 4088e3a | 2023-08-03 13:33:56 -0700 | [diff] [blame] | 39 | sinh(double x) |
The Android Open Source Project | 1dc9e47 | 2009-03-03 19:28:35 -0800 | [diff] [blame] | 40 | { |
Elliott Hughes | a0ee078 | 2013-01-30 19:06:37 -0800 | [diff] [blame] | 41 | double t,h; |
The Android Open Source Project | 1dc9e47 | 2009-03-03 19:28:35 -0800 | [diff] [blame] | 42 | int32_t ix,jx; |
The Android Open Source Project | 1dc9e47 | 2009-03-03 19:28:35 -0800 | [diff] [blame] | 43 | |
| 44 | /* High word of |x|. */ |
| 45 | GET_HIGH_WORD(jx,x); |
| 46 | ix = jx&0x7fffffff; |
| 47 | |
| 48 | /* x is INF or NaN */ |
| 49 | if(ix>=0x7ff00000) return x+x; |
| 50 | |
| 51 | h = 0.5; |
| 52 | if (jx<0) h = -h; |
| 53 | /* |x| in [0,22], return sign(x)*0.5*(E+E/(E+1))) */ |
| 54 | if (ix < 0x40360000) { /* |x|<22 */ |
| 55 | if (ix<0x3e300000) /* |x|<2**-28 */ |
| 56 | if(shuge+x>one) return x;/* sinh(tiny) = tiny with inexact */ |
| 57 | t = expm1(fabs(x)); |
| 58 | if(ix<0x3ff00000) return h*(2.0*t-t*t/(t+one)); |
| 59 | return h*(t+t/(t+one)); |
| 60 | } |
| 61 | |
| 62 | /* |x| in [22, log(maxdouble)] return 0.5*exp(|x|) */ |
Elliott Hughes | 4088e3a | 2023-08-03 13:33:56 -0700 | [diff] [blame] | 63 | if (ix < 0x40862E42) return h*exp(fabs(x)); |
The Android Open Source Project | 1dc9e47 | 2009-03-03 19:28:35 -0800 | [diff] [blame] | 64 | |
| 65 | /* |x| in [log(maxdouble), overflowthresold] */ |
Elliott Hughes | a0ee078 | 2013-01-30 19:06:37 -0800 | [diff] [blame] | 66 | if (ix<=0x408633CE) |
| 67 | return h*2.0*__ldexp_exp(fabs(x), -1); |
The Android Open Source Project | 1dc9e47 | 2009-03-03 19:28:35 -0800 | [diff] [blame] | 68 | |
| 69 | /* |x| > overflowthresold, sinh(x) overflow */ |
| 70 | return x*shuge; |
| 71 | } |
Elliott Hughes | 460ad74 | 2014-09-12 14:00:02 -0700 | [diff] [blame] | 72 | |
| 73 | #if (LDBL_MANT_DIG == 53) |
| 74 | __weak_reference(sinh, sinhl); |
| 75 | #endif |