123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140 |
- #include "cdefs-compat.h"
- #include <float.h>
- #include <openlibm.h>
- #include "math_private.h"
- #include "fpmath.h"
- #define BIAS (LDBL_MAX_EXP - 1)
- static const double
- zero = 0.00000000000000000000e+00,
- two24 = 1.67772160000000000000e+07;
- static const long double
- invpio2 = 6.3661977236758134307553505349005747e-01L,
- pio2_1 = 1.5707963267948966192292994253909555e+00L,
- pio2_1t = 2.0222662487959507323996846200947577e-21L,
- pio2_2 = 2.0222662487959507323994779168837751e-21L,
- pio2_2t = 2.0670321098263988236496903051604844e-43L,
- pio2_3 = 2.0670321098263988236499468110329591e-43L,
- pio2_3t = -2.5650587247459238361625433492959285e-65L;
- static inline __always_inline int
- __ieee754_rem_pio2l(long double x, long double *y)
- {
- union IEEEl2bits u,u1;
- long double z,w,t,r,fn;
- double tx[5],ty[3];
- int64_t n;
- int e0,ex,i,j,nx;
- int16_t expsign;
- u.e = x;
- expsign = u.xbits.expsign;
- ex = expsign & 0x7fff;
- if (ex < BIAS + 45 || ex == BIAS + 45 &&
- u.bits.manh < 0x921fb54442d1LL) {
-
-
- fn = x*invpio2+0x1.8p112;
- fn = fn-0x1.8p112;
- #ifdef HAVE_EFFICIENT_I64RINT
- n = i64rint(fn);
- #else
- n = fn;
- #endif
- r = x-fn*pio2_1;
- w = fn*pio2_1t;
- {
- union IEEEl2bits u2;
- int ex1;
- j = ex;
- y[0] = r-w;
- u2.e = y[0];
- ex1 = u2.xbits.expsign & 0x7fff;
- i = j-ex1;
- if(i>51) {
- t = r;
- w = fn*pio2_2;
- r = t-w;
- w = fn*pio2_2t-((t-r)-w);
- y[0] = r-w;
- u2.e = y[0];
- ex1 = u2.xbits.expsign & 0x7fff;
- i = j-ex1;
- if(i>119) {
- t = r;
- w = fn*pio2_3;
- r = t-w;
- w = fn*pio2_3t-((t-r)-w);
- y[0] = r-w;
- }
- }
- }
- y[1] = (r-y[0])-w;
- return n;
- }
-
- if(ex==0x7fff) {
- y[0]=y[1]=x-x; return 0;
- }
-
- u1.e = x;
- e0 = ex - BIAS - 23;
- u1.xbits.expsign = ex - e0;
- z = u1.e;
- for(i=0;i<4;i++) {
- tx[i] = (double)((int32_t)(z));
- z = (z-tx[i])*two24;
- }
- tx[4] = z;
- nx = 5;
- while(tx[nx-1]==zero) nx--;
- n = __kernel_rem_pio2(tx,ty,e0,nx,3);
- t = (long double)ty[2] + ty[1];
- r = t + ty[0];
- w = ty[0] - (r - t);
- if(expsign<0) {y[0] = -r; y[1] = -w; return -n;}
- y[0] = r; y[1] = w; return n;
- }
|