From 917655e7117a29aef38412f3d4eadaae159bebce Mon Sep 17 00:00:00 2001 From: Raymond Toy <toy.raymond@gmail.com> Date: Sat, 2 Aug 2014 14:46:44 -0700 Subject: [PATCH] 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. --- src/lisp/e_cosh.c | 6 ++++-- src/lisp/e_sinh.c | 6 ++++-- src/lisp/fdlibm.h | 9 ++++++--- src/lisp/s_tanh.c | 12 +++++++----- 4 files changed, 21 insertions(+), 12 deletions(-) diff --git a/src/lisp/e_cosh.c b/src/lisp/e_cosh.c index 204017d84..f33ec02e8 100644 --- a/src/lisp/e_cosh.c +++ b/src/lisp/e_cosh.c @@ -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); diff --git a/src/lisp/e_sinh.c b/src/lisp/e_sinh.c index 8af8a11eb..16671a9f9 100644 --- a/src/lisp/e_sinh.c +++ b/src/lisp/e_sinh.c @@ -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)); } diff --git a/src/lisp/fdlibm.h b/src/lisp/fdlibm.h index 180137baf..325d7d42f 100644 --- a/src/lisp/fdlibm.h +++ b/src/lisp/fdlibm.h @@ -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 diff --git a/src/lisp/s_tanh.c b/src/lisp/s_tanh.c index 7d77c2eac..6b770043d 100644 --- a/src/lisp/s_tanh.c +++ b/src/lisp/s_tanh.c @@ -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 */ -- GitLab