Commit 917655e7 authored by Raymond Toy's avatar Raymond Toy
Browse files

Use unions to access the high and low parts of a double and update

routine names.

 * fdlibm.h:
  * Correct the names for sin, cos, and tan; they have fdlibm_ prefix.
  * Declare fdlibm_expm1 and __ieee754_exp.
 * e_cosh.c:
  * Use unions
  * Call fdlibm_expm1 instead of expm1.
 * e_sinh.c:
  * Use unions
  * Call fdlibm_expm1 instead of expm1.
 * s_tanh.c:
  * Use unions
  * Call fdlibm_expm1 instead of expm1.
parent f399fc8d
......@@ -50,9 +50,11 @@ static double one = 1.0, half=0.5, huge = 1.0e300;
double t,w;
int ix;
unsigned lx;
union { int i[2]; double d; } ux;
/* High word of |x|. */
ix = __HI(x);
ux.d = x;
ix = ux.i[HIWORD];
ix &= 0x7fffffff;
/* x is INF or NaN */
......@@ -60,7 +62,7 @@ static double one = 1.0, half=0.5, huge = 1.0e300;
/* |x| in [0,0.5*ln2], return 1+expm1(|x|)^2/(2*exp(|x|)) */
if(ix<0x3fd62e43) {
t = expm1(fabs(x));
t = fdlibm_expm1(fabs(x));
w = one+t;
if (ix<0x3c800000) return w; /* cosh(tiny) = 1 */
return one+(t*t)/(w+w);
......
......@@ -47,9 +47,11 @@ static double one = 1.0, shuge = 1.0e307;
double t,w,h;
int ix,jx;
unsigned lx;
union { int i[2]; double d; } ux;
/* High word of |x|. */
jx = __HI(x);
ux.d = x;
jx = ux.i[HIWORD];
ix = jx&0x7fffffff;
/* x is INF or NaN */
......@@ -61,7 +63,7 @@ static double one = 1.0, shuge = 1.0e307;
if (ix < 0x40360000) { /* |x|<22 */
if (ix<0x3e300000) /* |x|<2**-28 */
if(shuge+x>one) return x;/* sinh(tiny) = tiny with inexact */
t = expm1(fabs(x));
t = fdlibm_expm1(fabs(x));
if(ix<0x3ff00000) return h*(2.0*t-t*t/(t+one));
return h*(t+t/(t+one));
}
......
......@@ -48,8 +48,11 @@ extern int __kernel_rem_pio2(double*,double*,int,int,int,const int*);
extern double __kernel_sin(double x, double y, int iy);
extern double __kernel_cos(double x, double y);
extern double __kernel_tan(double x, double y, int iy);
extern double sin(double x);
extern double cos(double x);
extern double tan(double x);
extern double fdlibm_sin(double x);
extern double fdlibm_cos(double x);
extern double fdlibm_tan(double x);
extern double fdlibm_expm1(double x);
extern double __ieee754_exp(double x);
#endif
......@@ -44,17 +44,19 @@ static double one=1.0, two=2.0, tiny = 1.0e-300;
#endif
#ifdef __STDC__
double tanh(double x)
double fdlibm_tanh(double x)
#else
double tanh(x)
double fdlibm_tanh(x)
double x;
#endif
{
double t,z;
int jx,ix;
union { int i[2]; double d; } ux;
/* High word of |x|. */
jx = __HI(x);
ux.d = x;
jx = ux.i[HIWORD];
ix = jx&0x7fffffff;
/* x is INF or NaN */
......@@ -68,10 +70,10 @@ static double one=1.0, two=2.0, tiny = 1.0e-300;
if (ix<0x3c800000) /* |x|<2**-55 */
return x*(one+x); /* tanh(small) = small */
if (ix>=0x3ff00000) { /* |x|>=1 */
t = expm1(two*fabs(x));
t = fdlibm_expm1(two*fabs(x));
z = one - two/(t+two);
} else {
t = expm1(-two*fabs(x));
t = fdlibm_expm1(-two*fabs(x));
z= -t/(t+two);
}
/* |x| > 22, return +-1 */
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment