Coverage Report

Created: 2025-06-13 06:17

/src/moddable/xs/tools/fdlibm/e_rem_pio2.c
Line
Count
Source (jump to first uncovered line)
1
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
 * Optimized by Bruce D. Evans.
13
 */
14
15
/* __ieee754_rem_pio2(x,y)
16
 * 
17
 * return the remainder of x rem pi/2 in y[0]+y[1] 
18
 * use __kernel_rem_pio2()
19
 */
20
21
#include "math_private.h"
22
23
/*
24
 * invpio2:  53 bits of 2/pi
25
 * pio2_1:   first  33 bit of pi/2
26
 * pio2_1t:  pi/2 - pio2_1
27
 * pio2_2:   second 33 bit of pi/2
28
 * pio2_2t:  pi/2 - (pio2_1+pio2_2)
29
 * pio2_3:   third  33 bit of pi/2
30
 * pio2_3t:  pi/2 - (pio2_1+pio2_2+pio2_3)
31
 */
32
33
static const double
34
zero =  0.00000000000000000000e+00, /* 0x00000000, 0x00000000 */
35
two24 =  1.67772160000000000000e+07, /* 0x41700000, 0x00000000 */
36
invpio2 =  6.36619772367581382433e-01, /* 0x3FE45F30, 0x6DC9C883 */
37
pio2_1  =  1.57079632673412561417e+00, /* 0x3FF921FB, 0x54400000 */
38
pio2_1t =  6.07710050650619224932e-11, /* 0x3DD0B461, 0x1A626331 */
39
pio2_2  =  6.07710050630396597660e-11, /* 0x3DD0B461, 0x1A600000 */
40
pio2_2t =  2.02226624879595063154e-21, /* 0x3BA3198A, 0x2E037073 */
41
pio2_3  =  2.02226624871116645580e-21, /* 0x3BA3198A, 0x2E000000 */
42
pio2_3t =  8.47842766036889956997e-32; /* 0x397B839A, 0x252049C1 */
43
44
#ifdef INLINE_REM_PIO2
45
static inline
46
#endif
47
int
48
__ieee754_rem_pio2(double x, double *y)
49
532k
{
50
532k
  double z,w,t,r,fn;
51
532k
  double tx[3],ty[2];
52
532k
  int32_t e0,i,j,nx,n,ix,hx;
53
532k
  u_int32_t low;
54
55
532k
  GET_HIGH_WORD(hx,x);   /* high word of x */
56
532k
  ix = hx&0x7fffffff;
57
#if 0 /* Must be handled in caller. */
58
  if(ix<=0x3fe921fb)   /* |x| ~<= pi/4 , no need for reduction */
59
      {y[0] = x; y[1] = 0; return 0;}
60
#endif
61
532k
  if (ix <= 0x400f6a7a) {   /* |x| ~<= 5pi/4 */
62
262k
      if ((ix & 0xfffff) == 0x921fb)  /* |x| ~= pi/2 or 2pi/2 */
63
0
    goto medium;   /* cancellation -- use medium case */
64
262k
      if (ix <= 0x4002d97c) { /* |x| ~<= 3pi/4 */
65
257k
    if (hx > 0) {
66
254k
        z = x - pio2_1; /* one round good to 85 bits */
67
254k
        y[0] = z - pio2_1t;
68
254k
        y[1] = (z-y[0])-pio2_1t;
69
254k
        return 1;
70
254k
    } else {
71
2.11k
        z = x + pio2_1;
72
2.11k
        y[0] = z + pio2_1t;
73
2.11k
        y[1] = (z-y[0])+pio2_1t;
74
2.11k
        return -1;
75
2.11k
    }
76
257k
      } else {
77
5.31k
    if (hx > 0) {
78
2.78k
        z = x - 2*pio2_1;
79
2.78k
        y[0] = z - 2*pio2_1t;
80
2.78k
        y[1] = (z-y[0])-2*pio2_1t;
81
2.78k
        return 2;
82
2.78k
    } else {
83
2.52k
        z = x + 2*pio2_1;
84
2.52k
        y[0] = z + 2*pio2_1t;
85
2.52k
        y[1] = (z-y[0])+2*pio2_1t;
86
2.52k
        return -2;
87
2.52k
    }
88
5.31k
      }
89
262k
  }
90
270k
  if (ix <= 0x401c463b) {   /* |x| ~<= 9pi/4 */
91
7.48k
      if (ix <= 0x4015fdbc) { /* |x| ~<= 7pi/4 */
92
4.63k
    if (ix == 0x4012d97c)  /* |x| ~= 3pi/2 */
93
0
        goto medium;
94
4.63k
    if (hx > 0) {
95
2.55k
        z = x - 3*pio2_1;
96
2.55k
        y[0] = z - 3*pio2_1t;
97
2.55k
        y[1] = (z-y[0])-3*pio2_1t;
98
2.55k
        return 3;
99
2.55k
    } else {
100
2.08k
        z = x + 3*pio2_1;
101
2.08k
        y[0] = z + 3*pio2_1t;
102
2.08k
        y[1] = (z-y[0])+3*pio2_1t;
103
2.08k
        return -3;
104
2.08k
    }
105
4.63k
      } else {
106
2.84k
    if (ix == 0x401921fb)  /* |x| ~= 4pi/2 */
107
0
        goto medium;
108
2.84k
    if (hx > 0) {
109
1.88k
        z = x - 4*pio2_1;
110
1.88k
        y[0] = z - 4*pio2_1t;
111
1.88k
        y[1] = (z-y[0])-4*pio2_1t;
112
1.88k
        return 4;
113
1.88k
    } else {
114
964
        z = x + 4*pio2_1;
115
964
        y[0] = z + 4*pio2_1t;
116
964
        y[1] = (z-y[0])+4*pio2_1t;
117
964
        return -4;
118
964
    }
119
2.84k
      }
120
7.48k
  }
121
263k
  if(ix<0x413921fb) { /* |x| ~< 2^20*(pi/2), medium size */
122
133k
medium:
123
133k
      fn = rnint((double_t)x*invpio2);
124
133k
      n  = irint(fn);
125
133k
      r  = x-fn*pio2_1;
126
133k
      w  = fn*pio2_1t;  /* 1st round good to 85 bit */
127
133k
      {
128
133k
          u_int32_t high;
129
133k
          j  = ix>>20;
130
133k
          y[0] = r-w; 
131
133k
    GET_HIGH_WORD(high,y[0]);
132
133k
          i = j-((high>>20)&0x7ff);
133
133k
          if(i>16) {  /* 2nd iteration needed, good to 118 */
134
6.47k
        t  = r;
135
6.47k
        w  = fn*pio2_2; 
136
6.47k
        r  = t-w;
137
6.47k
        w  = fn*pio2_2t-((t-r)-w);  
138
6.47k
        y[0] = r-w;
139
6.47k
        GET_HIGH_WORD(high,y[0]);
140
6.47k
        i = j-((high>>20)&0x7ff);
141
6.47k
        if(i>49)  { /* 3rd iteration need, 151 bits acc */
142
0
          t  = r; /* will cover all possible cases */
143
0
          w  = fn*pio2_3; 
144
0
          r  = t-w;
145
0
          w  = fn*pio2_3t-((t-r)-w);  
146
0
          y[0] = r-w;
147
0
        }
148
6.47k
    }
149
133k
      }
150
133k
      y[1] = (r-y[0])-w;
151
133k
      return n;
152
133k
  }
153
    /* 
154
     * all other (large) arguments
155
     */
156
129k
  if(ix>=0x7ff00000) {   /* x is inf or NaN */
157
0
      y[0]=y[1]=x-x; return 0;
158
0
  }
159
    /* set z = scalbn(|x|,ilogb(x)-23) */
160
129k
  GET_LOW_WORD(low,x);
161
129k
  e0  = (ix>>20)-1046;  /* e0 = ilogb(z)-23; */
162
129k
  INSERT_WORDS(z, ix - ((int32_t)((u_int32_t)e0<<20)), low);
163
387k
  for(i=0;i<2;i++) {
164
258k
    tx[i] = (double)((int32_t)(z));
165
258k
    z     = (z-tx[i])*two24;
166
258k
  }
167
129k
  tx[2] = z;
168
129k
  nx = 3;
169
156k
  while(tx[nx-1]==zero) nx--; /* skip zero term */
170
129k
  n  =  __kernel_rem_pio2(tx,ty,e0,nx,1);
171
129k
  if(hx<0) {y[0] = -ty[0]; y[1] = -ty[1]; return -n;}
172
122k
  y[0] = ty[0]; y[1] = ty[1]; return n;
173
129k
}
Unexecuted instantiation: __ieee754_rem_pio2
s_cos.c:__ieee754_rem_pio2
Line
Count
Source
49
379k
{
50
379k
  double z,w,t,r,fn;
51
379k
  double tx[3],ty[2];
52
379k
  int32_t e0,i,j,nx,n,ix,hx;
53
379k
  u_int32_t low;
54
55
379k
  GET_HIGH_WORD(hx,x);   /* high word of x */
56
379k
  ix = hx&0x7fffffff;
57
#if 0 /* Must be handled in caller. */
58
  if(ix<=0x3fe921fb)   /* |x| ~<= pi/4 , no need for reduction */
59
      {y[0] = x; y[1] = 0; return 0;}
60
#endif
61
379k
  if (ix <= 0x400f6a7a) {   /* |x| ~<= 5pi/4 */
62
255k
      if ((ix & 0xfffff) == 0x921fb)  /* |x| ~= pi/2 or 2pi/2 */
63
0
    goto medium;   /* cancellation -- use medium case */
64
255k
      if (ix <= 0x4002d97c) { /* |x| ~<= 3pi/4 */
65
254k
    if (hx > 0) {
66
253k
        z = x - pio2_1; /* one round good to 85 bits */
67
253k
        y[0] = z - pio2_1t;
68
253k
        y[1] = (z-y[0])-pio2_1t;
69
253k
        return 1;
70
253k
    } else {
71
829
        z = x + pio2_1;
72
829
        y[0] = z + pio2_1t;
73
829
        y[1] = (z-y[0])+pio2_1t;
74
829
        return -1;
75
829
    }
76
254k
      } else {
77
1.36k
    if (hx > 0) {
78
902
        z = x - 2*pio2_1;
79
902
        y[0] = z - 2*pio2_1t;
80
902
        y[1] = (z-y[0])-2*pio2_1t;
81
902
        return 2;
82
902
    } else {
83
465
        z = x + 2*pio2_1;
84
465
        y[0] = z + 2*pio2_1t;
85
465
        y[1] = (z-y[0])+2*pio2_1t;
86
465
        return -2;
87
465
    }
88
1.36k
      }
89
255k
  }
90
124k
  if (ix <= 0x401c463b) {   /* |x| ~<= 9pi/4 */
91
2.02k
      if (ix <= 0x4015fdbc) { /* |x| ~<= 7pi/4 */
92
1.18k
    if (ix == 0x4012d97c)  /* |x| ~= 3pi/2 */
93
0
        goto medium;
94
1.18k
    if (hx > 0) {
95
620
        z = x - 3*pio2_1;
96
620
        y[0] = z - 3*pio2_1t;
97
620
        y[1] = (z-y[0])-3*pio2_1t;
98
620
        return 3;
99
620
    } else {
100
569
        z = x + 3*pio2_1;
101
569
        y[0] = z + 3*pio2_1t;
102
569
        y[1] = (z-y[0])+3*pio2_1t;
103
569
        return -3;
104
569
    }
105
1.18k
      } else {
106
840
    if (ix == 0x401921fb)  /* |x| ~= 4pi/2 */
107
0
        goto medium;
108
840
    if (hx > 0) {
109
402
        z = x - 4*pio2_1;
110
402
        y[0] = z - 4*pio2_1t;
111
402
        y[1] = (z-y[0])-4*pio2_1t;
112
402
        return 4;
113
438
    } else {
114
438
        z = x + 4*pio2_1;
115
438
        y[0] = z + 4*pio2_1t;
116
438
        y[1] = (z-y[0])+4*pio2_1t;
117
438
        return -4;
118
438
    }
119
840
      }
120
2.02k
  }
121
121k
  if(ix<0x413921fb) { /* |x| ~< 2^20*(pi/2), medium size */
122
114k
medium:
123
114k
      fn = rnint((double_t)x*invpio2);
124
114k
      n  = irint(fn);
125
114k
      r  = x-fn*pio2_1;
126
114k
      w  = fn*pio2_1t;  /* 1st round good to 85 bit */
127
114k
      {
128
114k
          u_int32_t high;
129
114k
          j  = ix>>20;
130
114k
          y[0] = r-w; 
131
114k
    GET_HIGH_WORD(high,y[0]);
132
114k
          i = j-((high>>20)&0x7ff);
133
114k
          if(i>16) {  /* 2nd iteration needed, good to 118 */
134
4.44k
        t  = r;
135
4.44k
        w  = fn*pio2_2; 
136
4.44k
        r  = t-w;
137
4.44k
        w  = fn*pio2_2t-((t-r)-w);  
138
4.44k
        y[0] = r-w;
139
4.44k
        GET_HIGH_WORD(high,y[0]);
140
4.44k
        i = j-((high>>20)&0x7ff);
141
4.44k
        if(i>49)  { /* 3rd iteration need, 151 bits acc */
142
0
          t  = r; /* will cover all possible cases */
143
0
          w  = fn*pio2_3; 
144
0
          r  = t-w;
145
0
          w  = fn*pio2_3t-((t-r)-w);  
146
0
          y[0] = r-w;
147
0
        }
148
4.44k
    }
149
114k
      }
150
114k
      y[1] = (r-y[0])-w;
151
114k
      return n;
152
114k
  }
153
    /* 
154
     * all other (large) arguments
155
     */
156
7.35k
  if(ix>=0x7ff00000) {   /* x is inf or NaN */
157
0
      y[0]=y[1]=x-x; return 0;
158
0
  }
159
    /* set z = scalbn(|x|,ilogb(x)-23) */
160
7.35k
  GET_LOW_WORD(low,x);
161
7.35k
  e0  = (ix>>20)-1046;  /* e0 = ilogb(z)-23; */
162
7.35k
  INSERT_WORDS(z, ix - ((int32_t)((u_int32_t)e0<<20)), low);
163
22.0k
  for(i=0;i<2;i++) {
164
14.7k
    tx[i] = (double)((int32_t)(z));
165
14.7k
    z     = (z-tx[i])*two24;
166
14.7k
  }
167
7.35k
  tx[2] = z;
168
7.35k
  nx = 3;
169
10.5k
  while(tx[nx-1]==zero) nx--; /* skip zero term */
170
7.35k
  n  =  __kernel_rem_pio2(tx,ty,e0,nx,1);
171
7.35k
  if(hx<0) {y[0] = -ty[0]; y[1] = -ty[1]; return -n;}
172
3.43k
  y[0] = ty[0]; y[1] = ty[1]; return n;
173
7.35k
}
s_sin.c:__ieee754_rem_pio2
Line
Count
Source
49
9.76k
{
50
9.76k
  double z,w,t,r,fn;
51
9.76k
  double tx[3],ty[2];
52
9.76k
  int32_t e0,i,j,nx,n,ix,hx;
53
9.76k
  u_int32_t low;
54
55
9.76k
  GET_HIGH_WORD(hx,x);   /* high word of x */
56
9.76k
  ix = hx&0x7fffffff;
57
#if 0 /* Must be handled in caller. */
58
  if(ix<=0x3fe921fb)   /* |x| ~<= pi/4 , no need for reduction */
59
      {y[0] = x; y[1] = 0; return 0;}
60
#endif
61
9.76k
  if (ix <= 0x400f6a7a) {   /* |x| ~<= 5pi/4 */
62
3.78k
      if ((ix & 0xfffff) == 0x921fb)  /* |x| ~= pi/2 or 2pi/2 */
63
0
    goto medium;   /* cancellation -- use medium case */
64
3.78k
      if (ix <= 0x4002d97c) { /* |x| ~<= 3pi/4 */
65
1.26k
    if (hx > 0) {
66
539
        z = x - pio2_1; /* one round good to 85 bits */
67
539
        y[0] = z - pio2_1t;
68
539
        y[1] = (z-y[0])-pio2_1t;
69
539
        return 1;
70
725
    } else {
71
725
        z = x + pio2_1;
72
725
        y[0] = z + pio2_1t;
73
725
        y[1] = (z-y[0])+pio2_1t;
74
725
        return -1;
75
725
    }
76
2.51k
      } else {
77
2.51k
    if (hx > 0) {
78
994
        z = x - 2*pio2_1;
79
994
        y[0] = z - 2*pio2_1t;
80
994
        y[1] = (z-y[0])-2*pio2_1t;
81
994
        return 2;
82
1.52k
    } else {
83
1.52k
        z = x + 2*pio2_1;
84
1.52k
        y[0] = z + 2*pio2_1t;
85
1.52k
        y[1] = (z-y[0])+2*pio2_1t;
86
1.52k
        return -2;
87
1.52k
    }
88
2.51k
      }
89
3.78k
  }
90
5.98k
  if (ix <= 0x401c463b) {   /* |x| ~<= 9pi/4 */
91
2.76k
      if (ix <= 0x4015fdbc) { /* |x| ~<= 7pi/4 */
92
1.80k
    if (ix == 0x4012d97c)  /* |x| ~= 3pi/2 */
93
0
        goto medium;
94
1.80k
    if (hx > 0) {
95
830
        z = x - 3*pio2_1;
96
830
        y[0] = z - 3*pio2_1t;
97
830
        y[1] = (z-y[0])-3*pio2_1t;
98
830
        return 3;
99
978
    } else {
100
978
        z = x + 3*pio2_1;
101
978
        y[0] = z + 3*pio2_1t;
102
978
        y[1] = (z-y[0])+3*pio2_1t;
103
978
        return -3;
104
978
    }
105
1.80k
      } else {
106
959
    if (ix == 0x401921fb)  /* |x| ~= 4pi/2 */
107
0
        goto medium;
108
959
    if (hx > 0) {
109
715
        z = x - 4*pio2_1;
110
715
        y[0] = z - 4*pio2_1t;
111
715
        y[1] = (z-y[0])-4*pio2_1t;
112
715
        return 4;
113
715
    } else {
114
244
        z = x + 4*pio2_1;
115
244
        y[0] = z + 4*pio2_1t;
116
244
        y[1] = (z-y[0])+4*pio2_1t;
117
244
        return -4;
118
244
    }
119
959
      }
120
2.76k
  }
121
3.21k
  if(ix<0x413921fb) { /* |x| ~< 2^20*(pi/2), medium size */
122
1.16k
medium:
123
1.16k
      fn = rnint((double_t)x*invpio2);
124
1.16k
      n  = irint(fn);
125
1.16k
      r  = x-fn*pio2_1;
126
1.16k
      w  = fn*pio2_1t;  /* 1st round good to 85 bit */
127
1.16k
      {
128
1.16k
          u_int32_t high;
129
1.16k
          j  = ix>>20;
130
1.16k
          y[0] = r-w; 
131
1.16k
    GET_HIGH_WORD(high,y[0]);
132
1.16k
          i = j-((high>>20)&0x7ff);
133
1.16k
          if(i>16) {  /* 2nd iteration needed, good to 118 */
134
605
        t  = r;
135
605
        w  = fn*pio2_2; 
136
605
        r  = t-w;
137
605
        w  = fn*pio2_2t-((t-r)-w);  
138
605
        y[0] = r-w;
139
605
        GET_HIGH_WORD(high,y[0]);
140
605
        i = j-((high>>20)&0x7ff);
141
605
        if(i>49)  { /* 3rd iteration need, 151 bits acc */
142
0
          t  = r; /* will cover all possible cases */
143
0
          w  = fn*pio2_3; 
144
0
          r  = t-w;
145
0
          w  = fn*pio2_3t-((t-r)-w);  
146
0
          y[0] = r-w;
147
0
        }
148
605
    }
149
1.16k
      }
150
1.16k
      y[1] = (r-y[0])-w;
151
1.16k
      return n;
152
1.16k
  }
153
    /* 
154
     * all other (large) arguments
155
     */
156
2.05k
  if(ix>=0x7ff00000) {   /* x is inf or NaN */
157
0
      y[0]=y[1]=x-x; return 0;
158
0
  }
159
    /* set z = scalbn(|x|,ilogb(x)-23) */
160
2.05k
  GET_LOW_WORD(low,x);
161
2.05k
  e0  = (ix>>20)-1046;  /* e0 = ilogb(z)-23; */
162
2.05k
  INSERT_WORDS(z, ix - ((int32_t)((u_int32_t)e0<<20)), low);
163
6.16k
  for(i=0;i<2;i++) {
164
4.10k
    tx[i] = (double)((int32_t)(z));
165
4.10k
    z     = (z-tx[i])*two24;
166
4.10k
  }
167
2.05k
  tx[2] = z;
168
2.05k
  nx = 3;
169
5.86k
  while(tx[nx-1]==zero) nx--; /* skip zero term */
170
2.05k
  n  =  __kernel_rem_pio2(tx,ty,e0,nx,1);
171
2.05k
  if(hx<0) {y[0] = -ty[0]; y[1] = -ty[1]; return -n;}
172
1.01k
  y[0] = ty[0]; y[1] = ty[1]; return n;
173
2.05k
}
s_tan.c:__ieee754_rem_pio2
Line
Count
Source
49
143k
{
50
143k
  double z,w,t,r,fn;
51
143k
  double tx[3],ty[2];
52
143k
  int32_t e0,i,j,nx,n,ix,hx;
53
143k
  u_int32_t low;
54
55
143k
  GET_HIGH_WORD(hx,x);   /* high word of x */
56
143k
  ix = hx&0x7fffffff;
57
#if 0 /* Must be handled in caller. */
58
  if(ix<=0x3fe921fb)   /* |x| ~<= pi/4 , no need for reduction */
59
      {y[0] = x; y[1] = 0; return 0;}
60
#endif
61
143k
  if (ix <= 0x400f6a7a) {   /* |x| ~<= 5pi/4 */
62
3.11k
      if ((ix & 0xfffff) == 0x921fb)  /* |x| ~= pi/2 or 2pi/2 */
63
0
    goto medium;   /* cancellation -- use medium case */
64
3.11k
      if (ix <= 0x4002d97c) { /* |x| ~<= 3pi/4 */
65
1.68k
    if (hx > 0) {
66
1.12k
        z = x - pio2_1; /* one round good to 85 bits */
67
1.12k
        y[0] = z - pio2_1t;
68
1.12k
        y[1] = (z-y[0])-pio2_1t;
69
1.12k
        return 1;
70
1.12k
    } else {
71
563
        z = x + pio2_1;
72
563
        y[0] = z + pio2_1t;
73
563
        y[1] = (z-y[0])+pio2_1t;
74
563
        return -1;
75
563
    }
76
1.68k
      } else {
77
1.42k
    if (hx > 0) {
78
889
        z = x - 2*pio2_1;
79
889
        y[0] = z - 2*pio2_1t;
80
889
        y[1] = (z-y[0])-2*pio2_1t;
81
889
        return 2;
82
889
    } else {
83
536
        z = x + 2*pio2_1;
84
536
        y[0] = z + 2*pio2_1t;
85
536
        y[1] = (z-y[0])+2*pio2_1t;
86
536
        return -2;
87
536
    }
88
1.42k
      }
89
3.11k
  }
90
140k
  if (ix <= 0x401c463b) {   /* |x| ~<= 9pi/4 */
91
2.68k
      if (ix <= 0x4015fdbc) { /* |x| ~<= 7pi/4 */
92
1.63k
    if (ix == 0x4012d97c)  /* |x| ~= 3pi/2 */
93
0
        goto medium;
94
1.63k
    if (hx > 0) {
95
1.10k
        z = x - 3*pio2_1;
96
1.10k
        y[0] = z - 3*pio2_1t;
97
1.10k
        y[1] = (z-y[0])-3*pio2_1t;
98
1.10k
        return 3;
99
1.10k
    } else {
100
538
        z = x + 3*pio2_1;
101
538
        y[0] = z + 3*pio2_1t;
102
538
        y[1] = (z-y[0])+3*pio2_1t;
103
538
        return -3;
104
538
    }
105
1.63k
      } else {
106
1.04k
    if (ix == 0x401921fb)  /* |x| ~= 4pi/2 */
107
0
        goto medium;
108
1.04k
    if (hx > 0) {
109
763
        z = x - 4*pio2_1;
110
763
        y[0] = z - 4*pio2_1t;
111
763
        y[1] = (z-y[0])-4*pio2_1t;
112
763
        return 4;
113
763
    } else {
114
282
        z = x + 4*pio2_1;
115
282
        y[0] = z + 4*pio2_1t;
116
282
        y[1] = (z-y[0])+4*pio2_1t;
117
282
        return -4;
118
282
    }
119
1.04k
      }
120
2.68k
  }
121
137k
  if(ix<0x413921fb) { /* |x| ~< 2^20*(pi/2), medium size */
122
18.1k
medium:
123
18.1k
      fn = rnint((double_t)x*invpio2);
124
18.1k
      n  = irint(fn);
125
18.1k
      r  = x-fn*pio2_1;
126
18.1k
      w  = fn*pio2_1t;  /* 1st round good to 85 bit */
127
18.1k
      {
128
18.1k
          u_int32_t high;
129
18.1k
          j  = ix>>20;
130
18.1k
          y[0] = r-w; 
131
18.1k
    GET_HIGH_WORD(high,y[0]);
132
18.1k
          i = j-((high>>20)&0x7ff);
133
18.1k
          if(i>16) {  /* 2nd iteration needed, good to 118 */
134
1.42k
        t  = r;
135
1.42k
        w  = fn*pio2_2; 
136
1.42k
        r  = t-w;
137
1.42k
        w  = fn*pio2_2t-((t-r)-w);  
138
1.42k
        y[0] = r-w;
139
1.42k
        GET_HIGH_WORD(high,y[0]);
140
1.42k
        i = j-((high>>20)&0x7ff);
141
1.42k
        if(i>49)  { /* 3rd iteration need, 151 bits acc */
142
0
          t  = r; /* will cover all possible cases */
143
0
          w  = fn*pio2_3; 
144
0
          r  = t-w;
145
0
          w  = fn*pio2_3t-((t-r)-w);  
146
0
          y[0] = r-w;
147
0
        }
148
1.42k
    }
149
18.1k
      }
150
18.1k
      y[1] = (r-y[0])-w;
151
18.1k
      return n;
152
18.1k
  }
153
    /* 
154
     * all other (large) arguments
155
     */
156
119k
  if(ix>=0x7ff00000) {   /* x is inf or NaN */
157
0
      y[0]=y[1]=x-x; return 0;
158
0
  }
159
    /* set z = scalbn(|x|,ilogb(x)-23) */
160
119k
  GET_LOW_WORD(low,x);
161
119k
  e0  = (ix>>20)-1046;  /* e0 = ilogb(z)-23; */
162
119k
  INSERT_WORDS(z, ix - ((int32_t)((u_int32_t)e0<<20)), low);
163
359k
  for(i=0;i<2;i++) {
164
239k
    tx[i] = (double)((int32_t)(z));
165
239k
    z     = (z-tx[i])*two24;
166
239k
  }
167
119k
  tx[2] = z;
168
119k
  nx = 3;
169
140k
  while(tx[nx-1]==zero) nx--; /* skip zero term */
170
119k
  n  =  __kernel_rem_pio2(tx,ty,e0,nx,1);
171
119k
  if(hx<0) {y[0] = -ty[0]; y[1] = -ty[1]; return -n;}
172
118k
  y[0] = ty[0]; y[1] = ty[1]; return n;
173
119k
}