|
Packit |
6c4009 |
/* @(#)e_sinh.c 5.1 93/09/24 */
|
|
Packit |
6c4009 |
/*
|
|
Packit |
6c4009 |
* ====================================================
|
|
Packit |
6c4009 |
* Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved.
|
|
Packit |
6c4009 |
*
|
|
Packit |
6c4009 |
* Developed at SunPro, a Sun Microsystems, Inc. business.
|
|
Packit |
6c4009 |
* Permission to use, copy, modify, and distribute this
|
|
Packit |
6c4009 |
* software is freely granted, provided that this notice
|
|
Packit |
6c4009 |
* is preserved.
|
|
Packit |
6c4009 |
* ====================================================
|
|
Packit |
6c4009 |
*/
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
#if defined(LIBM_SCCS) && !defined(lint)
|
|
Packit |
6c4009 |
static char rcsid[] = "$NetBSD: e_sinh.c,v 1.7 1995/05/10 20:46:13 jtc Exp $";
|
|
Packit |
6c4009 |
#endif
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
/* __ieee754_sinh(x)
|
|
Packit |
6c4009 |
* Method :
|
|
Packit |
6c4009 |
* mathematically sinh(x) if defined to be (exp(x)-exp(-x))/2
|
|
Packit |
6c4009 |
* 1. Replace x by |x| (sinh(-x) = -sinh(x)).
|
|
Packit |
6c4009 |
* 2.
|
|
Packit |
6c4009 |
* E + E/(E+1)
|
|
Packit |
6c4009 |
* 0 <= x <= 22 : sinh(x) := --------------, E=expm1(x)
|
|
Packit |
6c4009 |
* 2
|
|
Packit |
6c4009 |
*
|
|
Packit |
6c4009 |
* 22 <= x <= lnovft : sinh(x) := exp(x)/2
|
|
Packit |
6c4009 |
* lnovft <= x <= ln2ovft: sinh(x) := exp(x/2)/2 * exp(x/2)
|
|
Packit |
6c4009 |
* ln2ovft < x : sinh(x) := x*shuge (overflow)
|
|
Packit |
6c4009 |
*
|
|
Packit |
6c4009 |
* Special cases:
|
|
Packit |
6c4009 |
* sinh(x) is |x| if x is +INF, -INF, or NaN.
|
|
Packit |
6c4009 |
* only sinh(0)=0 is exact for finite x.
|
|
Packit |
6c4009 |
*/
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
#include <float.h>
|
|
Packit |
6c4009 |
#include <math.h>
|
|
Packit |
6c4009 |
#include <math-narrow-eval.h>
|
|
Packit |
6c4009 |
#include <math_private.h>
|
|
Packit |
6c4009 |
#include <math-underflow.h>
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
static const double one = 1.0, shuge = 1.0e307;
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
double
|
|
Packit |
6c4009 |
__ieee754_sinh (double x)
|
|
Packit |
6c4009 |
{
|
|
Packit |
6c4009 |
double t, w, h;
|
|
Packit |
6c4009 |
int32_t ix, jx;
|
|
Packit |
6c4009 |
uint32_t lx;
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
/* High word of |x|. */
|
|
Packit |
6c4009 |
GET_HIGH_WORD (jx, x);
|
|
Packit |
6c4009 |
ix = jx & 0x7fffffff;
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
/* x is INF or NaN */
|
|
Packit |
6c4009 |
if (__glibc_unlikely (ix >= 0x7ff00000))
|
|
Packit |
6c4009 |
return x + x;
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
h = 0.5;
|
|
Packit |
6c4009 |
if (jx < 0)
|
|
Packit |
6c4009 |
h = -h;
|
|
Packit |
6c4009 |
/* |x| in [0,22], return sign(x)*0.5*(E+E/(E+1))) */
|
|
Packit |
6c4009 |
if (ix < 0x40360000) /* |x|<22 */
|
|
Packit |
6c4009 |
{
|
|
Packit |
6c4009 |
if (__glibc_unlikely (ix < 0x3e300000)) { /* |x|<2**-28 */
|
|
Packit |
6c4009 |
math_check_force_underflow (x);
|
|
Packit |
6c4009 |
if (shuge + x > one)
|
|
Packit |
6c4009 |
return x;
|
|
Packit |
6c4009 |
/* sinh(tiny) = tiny with inexact */
|
|
Packit |
6c4009 |
}
|
|
Packit |
6c4009 |
t = __expm1 (fabs (x));
|
|
Packit |
6c4009 |
if (ix < 0x3ff00000)
|
|
Packit |
6c4009 |
return h * (2.0 * t - t * t / (t + one));
|
|
Packit |
6c4009 |
return h * (t + t / (t + one));
|
|
Packit |
6c4009 |
}
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
/* |x| in [22, log(maxdouble)] return 0.5*exp(|x|) */
|
|
Packit |
6c4009 |
if (ix < 0x40862e42)
|
|
Packit |
6c4009 |
return h * __ieee754_exp (fabs (x));
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
/* |x| in [log(maxdouble), overflowthresold] */
|
|
Packit |
6c4009 |
GET_LOW_WORD (lx, x);
|
|
Packit |
6c4009 |
if (ix < 0x408633ce || ((ix == 0x408633ce) && (lx <= (uint32_t) 0x8fb9f87d)))
|
|
Packit |
6c4009 |
{
|
|
Packit |
6c4009 |
w = __ieee754_exp (0.5 * fabs (x));
|
|
Packit |
6c4009 |
t = h * w;
|
|
Packit |
6c4009 |
return t * w;
|
|
Packit |
6c4009 |
}
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
/* |x| > overflowthresold, sinh(x) overflow */
|
|
Packit |
6c4009 |
return math_narrow_eval (x * shuge);
|
|
Packit |
6c4009 |
}
|
|
Packit |
6c4009 |
strong_alias (__ieee754_sinh, __sinh_finite)
|