Coverage Report

Created: 2025-11-09 06:43

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/moddable/xs/tools/fdlibm/e_rem_pio2.c
Line
Count
Source
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
176k
{
50
176k
  double z,w,t,r,fn;
51
176k
  double tx[3],ty[2];
52
176k
  int32_t e0,i,j,nx,n,ix,hx;
53
176k
  u_int32_t low;
54
55
176k
  GET_HIGH_WORD(hx,x);   /* high word of x */
56
176k
  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
176k
  if (ix <= 0x400f6a7a) {   /* |x| ~<= 5pi/4 */
62
160k
      if ((ix & 0xfffff) == 0x921fb)  /* |x| ~= pi/2 or 2pi/2 */
63
0
    goto medium;   /* cancellation -- use medium case */
64
160k
      if (ix <= 0x4002d97c) { /* |x| ~<= 3pi/4 */
65
157k
    if (hx > 0) {
66
156k
        z = x - pio2_1; /* one round good to 85 bits */
67
156k
        y[0] = z - pio2_1t;
68
156k
        y[1] = (z-y[0])-pio2_1t;
69
156k
        return 1;
70
156k
    } else {
71
1.40k
        z = x + pio2_1;
72
1.40k
        y[0] = z + pio2_1t;
73
1.40k
        y[1] = (z-y[0])+pio2_1t;
74
1.40k
        return -1;
75
1.40k
    }
76
157k
      } else {
77
2.64k
    if (hx > 0) {
78
869
        z = x - 2*pio2_1;
79
869
        y[0] = z - 2*pio2_1t;
80
869
        y[1] = (z-y[0])-2*pio2_1t;
81
869
        return 2;
82
1.77k
    } else {
83
1.77k
        z = x + 2*pio2_1;
84
1.77k
        y[0] = z + 2*pio2_1t;
85
1.77k
        y[1] = (z-y[0])+2*pio2_1t;
86
1.77k
        return -2;
87
1.77k
    }
88
2.64k
      }
89
160k
  }
90
16.4k
  if (ix <= 0x401c463b) {   /* |x| ~<= 9pi/4 */
91
2.89k
      if (ix <= 0x4015fdbc) { /* |x| ~<= 7pi/4 */
92
1.79k
    if (ix == 0x4012d97c)  /* |x| ~= 3pi/2 */
93
0
        goto medium;
94
1.79k
    if (hx > 0) {
95
898
        z = x - 3*pio2_1;
96
898
        y[0] = z - 3*pio2_1t;
97
898
        y[1] = (z-y[0])-3*pio2_1t;
98
898
        return 3;
99
898
    } else {
100
898
        z = x + 3*pio2_1;
101
898
        y[0] = z + 3*pio2_1t;
102
898
        y[1] = (z-y[0])+3*pio2_1t;
103
898
        return -3;
104
898
    }
105
1.79k
      } else {
106
1.10k
    if (ix == 0x401921fb)  /* |x| ~= 4pi/2 */
107
0
        goto medium;
108
1.10k
    if (hx > 0) {
109
652
        z = x - 4*pio2_1;
110
652
        y[0] = z - 4*pio2_1t;
111
652
        y[1] = (z-y[0])-4*pio2_1t;
112
652
        return 4;
113
652
    } else {
114
448
        z = x + 4*pio2_1;
115
448
        y[0] = z + 4*pio2_1t;
116
448
        y[1] = (z-y[0])+4*pio2_1t;
117
448
        return -4;
118
448
    }
119
1.10k
      }
120
2.89k
  }
121
13.5k
  if(ix<0x413921fb) { /* |x| ~< 2^20*(pi/2), medium size */
122
8.91k
medium:
123
8.91k
      fn = rnint((double_t)x*invpio2);
124
8.91k
      n  = irint(fn);
125
8.91k
      r  = x-fn*pio2_1;
126
8.91k
      w  = fn*pio2_1t;  /* 1st round good to 85 bit */
127
8.91k
      {
128
8.91k
          u_int32_t high;
129
8.91k
          j  = ix>>20;
130
8.91k
          y[0] = r-w; 
131
8.91k
    GET_HIGH_WORD(high,y[0]);
132
8.91k
          i = j-((high>>20)&0x7ff);
133
8.91k
          if(i>16) {  /* 2nd iteration needed, good to 118 */
134
1.49k
        t  = r;
135
1.49k
        w  = fn*pio2_2; 
136
1.49k
        r  = t-w;
137
1.49k
        w  = fn*pio2_2t-((t-r)-w);  
138
1.49k
        y[0] = r-w;
139
1.49k
        GET_HIGH_WORD(high,y[0]);
140
1.49k
        i = j-((high>>20)&0x7ff);
141
1.49k
        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.49k
    }
149
8.91k
      }
150
8.91k
      y[1] = (r-y[0])-w;
151
8.91k
      return n;
152
8.91k
  }
153
    /* 
154
     * all other (large) arguments
155
     */
156
4.63k
  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
4.63k
  GET_LOW_WORD(low,x);
161
4.63k
  e0  = (ix>>20)-1046;  /* e0 = ilogb(z)-23; */
162
4.63k
  INSERT_WORDS(z, ix - ((int32_t)((u_int32_t)e0<<20)), low);
163
13.9k
  for(i=0;i<2;i++) {
164
9.26k
    tx[i] = (double)((int32_t)(z));
165
9.26k
    z     = (z-tx[i])*two24;
166
9.26k
  }
167
4.63k
  tx[2] = z;
168
4.63k
  nx = 3;
169
9.64k
  while(tx[nx-1]==zero) nx--; /* skip zero term */
170
4.63k
  n  =  __kernel_rem_pio2(tx,ty,e0,nx,1);
171
4.63k
  if(hx<0) {y[0] = -ty[0]; y[1] = -ty[1]; return -n;}
172
2.37k
  y[0] = ty[0]; y[1] = ty[1]; return n;
173
4.63k
}
Unexecuted instantiation: __ieee754_rem_pio2
s_cos.c:__ieee754_rem_pio2
Line
Count
Source
49
166k
{
50
166k
  double z,w,t,r,fn;
51
166k
  double tx[3],ty[2];
52
166k
  int32_t e0,i,j,nx,n,ix,hx;
53
166k
  u_int32_t low;
54
55
166k
  GET_HIGH_WORD(hx,x);   /* high word of x */
56
166k
  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
166k
  if (ix <= 0x400f6a7a) {   /* |x| ~<= 5pi/4 */
62
156k
      if ((ix & 0xfffff) == 0x921fb)  /* |x| ~= pi/2 or 2pi/2 */
63
0
    goto medium;   /* cancellation -- use medium case */
64
156k
      if (ix <= 0x4002d97c) { /* |x| ~<= 3pi/4 */
65
155k
    if (hx > 0) {
66
155k
        z = x - pio2_1; /* one round good to 85 bits */
67
155k
        y[0] = z - pio2_1t;
68
155k
        y[1] = (z-y[0])-pio2_1t;
69
155k
        return 1;
70
155k
    } else {
71
760
        z = x + pio2_1;
72
760
        y[0] = z + pio2_1t;
73
760
        y[1] = (z-y[0])+pio2_1t;
74
760
        return -1;
75
760
    }
76
155k
      } else {
77
1.13k
    if (hx > 0) {
78
640
        z = x - 2*pio2_1;
79
640
        y[0] = z - 2*pio2_1t;
80
640
        y[1] = (z-y[0])-2*pio2_1t;
81
640
        return 2;
82
640
    } else {
83
491
        z = x + 2*pio2_1;
84
491
        y[0] = z + 2*pio2_1t;
85
491
        y[1] = (z-y[0])+2*pio2_1t;
86
491
        return -2;
87
491
    }
88
1.13k
      }
89
156k
  }
90
9.71k
  if (ix <= 0x401c463b) {   /* |x| ~<= 9pi/4 */
91
2.01k
      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
652
        z = x - 3*pio2_1;
96
652
        y[0] = z - 3*pio2_1t;
97
652
        y[1] = (z-y[0])-3*pio2_1t;
98
652
        return 3;
99
652
    } else {
100
534
        z = x + 3*pio2_1;
101
534
        y[0] = z + 3*pio2_1t;
102
534
        y[1] = (z-y[0])+3*pio2_1t;
103
534
        return -3;
104
534
    }
105
1.18k
      } else {
106
831
    if (ix == 0x401921fb)  /* |x| ~= 4pi/2 */
107
0
        goto medium;
108
831
    if (hx > 0) {
109
459
        z = x - 4*pio2_1;
110
459
        y[0] = z - 4*pio2_1t;
111
459
        y[1] = (z-y[0])-4*pio2_1t;
112
459
        return 4;
113
459
    } else {
114
372
        z = x + 4*pio2_1;
115
372
        y[0] = z + 4*pio2_1t;
116
372
        y[1] = (z-y[0])+4*pio2_1t;
117
372
        return -4;
118
372
    }
119
831
      }
120
2.01k
  }
121
7.69k
  if(ix<0x413921fb) { /* |x| ~< 2^20*(pi/2), medium size */
122
6.65k
medium:
123
6.65k
      fn = rnint((double_t)x*invpio2);
124
6.65k
      n  = irint(fn);
125
6.65k
      r  = x-fn*pio2_1;
126
6.65k
      w  = fn*pio2_1t;  /* 1st round good to 85 bit */
127
6.65k
      {
128
6.65k
          u_int32_t high;
129
6.65k
          j  = ix>>20;
130
6.65k
          y[0] = r-w; 
131
6.65k
    GET_HIGH_WORD(high,y[0]);
132
6.65k
          i = j-((high>>20)&0x7ff);
133
6.65k
          if(i>16) {  /* 2nd iteration needed, good to 118 */
134
228
        t  = r;
135
228
        w  = fn*pio2_2; 
136
228
        r  = t-w;
137
228
        w  = fn*pio2_2t-((t-r)-w);  
138
228
        y[0] = r-w;
139
228
        GET_HIGH_WORD(high,y[0]);
140
228
        i = j-((high>>20)&0x7ff);
141
228
        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
228
    }
149
6.65k
      }
150
6.65k
      y[1] = (r-y[0])-w;
151
6.65k
      return n;
152
6.65k
  }
153
    /* 
154
     * all other (large) arguments
155
     */
156
1.04k
  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
1.04k
  GET_LOW_WORD(low,x);
161
1.04k
  e0  = (ix>>20)-1046;  /* e0 = ilogb(z)-23; */
162
1.04k
  INSERT_WORDS(z, ix - ((int32_t)((u_int32_t)e0<<20)), low);
163
3.12k
  for(i=0;i<2;i++) {
164
2.08k
    tx[i] = (double)((int32_t)(z));
165
2.08k
    z     = (z-tx[i])*two24;
166
2.08k
  }
167
1.04k
  tx[2] = z;
168
1.04k
  nx = 3;
169
1.97k
  while(tx[nx-1]==zero) nx--; /* skip zero term */
170
1.04k
  n  =  __kernel_rem_pio2(tx,ty,e0,nx,1);
171
1.04k
  if(hx<0) {y[0] = -ty[0]; y[1] = -ty[1]; return -n;}
172
885
  y[0] = ty[0]; y[1] = ty[1]; return n;
173
1.04k
}
s_sin.c:__ieee754_rem_pio2
Line
Count
Source
49
5.26k
{
50
5.26k
  double z,w,t,r,fn;
51
5.26k
  double tx[3],ty[2];
52
5.26k
  int32_t e0,i,j,nx,n,ix,hx;
53
5.26k
  u_int32_t low;
54
55
5.26k
  GET_HIGH_WORD(hx,x);   /* high word of x */
56
5.26k
  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
5.26k
  if (ix <= 0x400f6a7a) {   /* |x| ~<= 5pi/4 */
62
2.25k
      if ((ix & 0xfffff) == 0x921fb)  /* |x| ~= pi/2 or 2pi/2 */
63
0
    goto medium;   /* cancellation -- use medium case */
64
2.25k
      if (ix <= 0x4002d97c) { /* |x| ~<= 3pi/4 */
65
846
    if (hx > 0) {
66
425
        z = x - pio2_1; /* one round good to 85 bits */
67
425
        y[0] = z - pio2_1t;
68
425
        y[1] = (z-y[0])-pio2_1t;
69
425
        return 1;
70
425
    } else {
71
421
        z = x + pio2_1;
72
421
        y[0] = z + pio2_1t;
73
421
        y[1] = (z-y[0])+pio2_1t;
74
421
        return -1;
75
421
    }
76
1.41k
      } else {
77
1.41k
    if (hx > 0) {
78
205
        z = x - 2*pio2_1;
79
205
        y[0] = z - 2*pio2_1t;
80
205
        y[1] = (z-y[0])-2*pio2_1t;
81
205
        return 2;
82
1.20k
    } else {
83
1.20k
        z = x + 2*pio2_1;
84
1.20k
        y[0] = z + 2*pio2_1t;
85
1.20k
        y[1] = (z-y[0])+2*pio2_1t;
86
1.20k
        return -2;
87
1.20k
    }
88
1.41k
      }
89
2.25k
  }
90
3.00k
  if (ix <= 0x401c463b) {   /* |x| ~<= 9pi/4 */
91
636
      if (ix <= 0x4015fdbc) { /* |x| ~<= 7pi/4 */
92
482
    if (ix == 0x4012d97c)  /* |x| ~= 3pi/2 */
93
0
        goto medium;
94
482
    if (hx > 0) {
95
197
        z = x - 3*pio2_1;
96
197
        y[0] = z - 3*pio2_1t;
97
197
        y[1] = (z-y[0])-3*pio2_1t;
98
197
        return 3;
99
285
    } else {
100
285
        z = x + 3*pio2_1;
101
285
        y[0] = z + 3*pio2_1t;
102
285
        y[1] = (z-y[0])+3*pio2_1t;
103
285
        return -3;
104
285
    }
105
482
      } else {
106
154
    if (ix == 0x401921fb)  /* |x| ~= 4pi/2 */
107
0
        goto medium;
108
154
    if (hx > 0) {
109
146
        z = x - 4*pio2_1;
110
146
        y[0] = z - 4*pio2_1t;
111
146
        y[1] = (z-y[0])-4*pio2_1t;
112
146
        return 4;
113
146
    } else {
114
8
        z = x + 4*pio2_1;
115
8
        y[0] = z + 4*pio2_1t;
116
8
        y[1] = (z-y[0])+4*pio2_1t;
117
8
        return -4;
118
8
    }
119
154
      }
120
636
  }
121
2.36k
  if(ix<0x413921fb) { /* |x| ~< 2^20*(pi/2), medium size */
122
1.62k
medium:
123
1.62k
      fn = rnint((double_t)x*invpio2);
124
1.62k
      n  = irint(fn);
125
1.62k
      r  = x-fn*pio2_1;
126
1.62k
      w  = fn*pio2_1t;  /* 1st round good to 85 bit */
127
1.62k
      {
128
1.62k
          u_int32_t high;
129
1.62k
          j  = ix>>20;
130
1.62k
          y[0] = r-w; 
131
1.62k
    GET_HIGH_WORD(high,y[0]);
132
1.62k
          i = j-((high>>20)&0x7ff);
133
1.62k
          if(i>16) {  /* 2nd iteration needed, good to 118 */
134
986
        t  = r;
135
986
        w  = fn*pio2_2; 
136
986
        r  = t-w;
137
986
        w  = fn*pio2_2t-((t-r)-w);  
138
986
        y[0] = r-w;
139
986
        GET_HIGH_WORD(high,y[0]);
140
986
        i = j-((high>>20)&0x7ff);
141
986
        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
986
    }
149
1.62k
      }
150
1.62k
      y[1] = (r-y[0])-w;
151
1.62k
      return n;
152
1.62k
  }
153
    /* 
154
     * all other (large) arguments
155
     */
156
741
  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
741
  GET_LOW_WORD(low,x);
161
741
  e0  = (ix>>20)-1046;  /* e0 = ilogb(z)-23; */
162
741
  INSERT_WORDS(z, ix - ((int32_t)((u_int32_t)e0<<20)), low);
163
2.22k
  for(i=0;i<2;i++) {
164
1.48k
    tx[i] = (double)((int32_t)(z));
165
1.48k
    z     = (z-tx[i])*two24;
166
1.48k
  }
167
741
  tx[2] = z;
168
741
  nx = 3;
169
2.07k
  while(tx[nx-1]==zero) nx--; /* skip zero term */
170
741
  n  =  __kernel_rem_pio2(tx,ty,e0,nx,1);
171
741
  if(hx<0) {y[0] = -ty[0]; y[1] = -ty[1]; return -n;}
172
665
  y[0] = ty[0]; y[1] = ty[1]; return n;
173
741
}
s_tan.c:__ieee754_rem_pio2
Line
Count
Source
49
5.08k
{
50
5.08k
  double z,w,t,r,fn;
51
5.08k
  double tx[3],ty[2];
52
5.08k
  int32_t e0,i,j,nx,n,ix,hx;
53
5.08k
  u_int32_t low;
54
55
5.08k
  GET_HIGH_WORD(hx,x);   /* high word of x */
56
5.08k
  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
5.08k
  if (ix <= 0x400f6a7a) {   /* |x| ~<= 5pi/4 */
62
1.36k
      if ((ix & 0xfffff) == 0x921fb)  /* |x| ~= pi/2 or 2pi/2 */
63
0
    goto medium;   /* cancellation -- use medium case */
64
1.36k
      if (ix <= 0x4002d97c) { /* |x| ~<= 3pi/4 */
65
1.26k
    if (hx > 0) {
66
1.04k
        z = x - pio2_1; /* one round good to 85 bits */
67
1.04k
        y[0] = z - pio2_1t;
68
1.04k
        y[1] = (z-y[0])-pio2_1t;
69
1.04k
        return 1;
70
1.04k
    } else {
71
225
        z = x + pio2_1;
72
225
        y[0] = z + pio2_1t;
73
225
        y[1] = (z-y[0])+pio2_1t;
74
225
        return -1;
75
225
    }
76
1.26k
      } else {
77
98
    if (hx > 0) {
78
24
        z = x - 2*pio2_1;
79
24
        y[0] = z - 2*pio2_1t;
80
24
        y[1] = (z-y[0])-2*pio2_1t;
81
24
        return 2;
82
74
    } else {
83
74
        z = x + 2*pio2_1;
84
74
        y[0] = z + 2*pio2_1t;
85
74
        y[1] = (z-y[0])+2*pio2_1t;
86
74
        return -2;
87
74
    }
88
98
      }
89
1.36k
  }
90
3.72k
  if (ix <= 0x401c463b) {   /* |x| ~<= 9pi/4 */
91
243
      if (ix <= 0x4015fdbc) { /* |x| ~<= 7pi/4 */
92
128
    if (ix == 0x4012d97c)  /* |x| ~= 3pi/2 */
93
0
        goto medium;
94
128
    if (hx > 0) {
95
49
        z = x - 3*pio2_1;
96
49
        y[0] = z - 3*pio2_1t;
97
49
        y[1] = (z-y[0])-3*pio2_1t;
98
49
        return 3;
99
79
    } else {
100
79
        z = x + 3*pio2_1;
101
79
        y[0] = z + 3*pio2_1t;
102
79
        y[1] = (z-y[0])+3*pio2_1t;
103
79
        return -3;
104
79
    }
105
128
      } else {
106
115
    if (ix == 0x401921fb)  /* |x| ~= 4pi/2 */
107
0
        goto medium;
108
115
    if (hx > 0) {
109
47
        z = x - 4*pio2_1;
110
47
        y[0] = z - 4*pio2_1t;
111
47
        y[1] = (z-y[0])-4*pio2_1t;
112
47
        return 4;
113
68
    } else {
114
68
        z = x + 4*pio2_1;
115
68
        y[0] = z + 4*pio2_1t;
116
68
        y[1] = (z-y[0])+4*pio2_1t;
117
68
        return -4;
118
68
    }
119
115
      }
120
243
  }
121
3.48k
  if(ix<0x413921fb) { /* |x| ~< 2^20*(pi/2), medium size */
122
628
medium:
123
628
      fn = rnint((double_t)x*invpio2);
124
628
      n  = irint(fn);
125
628
      r  = x-fn*pio2_1;
126
628
      w  = fn*pio2_1t;  /* 1st round good to 85 bit */
127
628
      {
128
628
          u_int32_t high;
129
628
          j  = ix>>20;
130
628
          y[0] = r-w; 
131
628
    GET_HIGH_WORD(high,y[0]);
132
628
          i = j-((high>>20)&0x7ff);
133
628
          if(i>16) {  /* 2nd iteration needed, good to 118 */
134
282
        t  = r;
135
282
        w  = fn*pio2_2; 
136
282
        r  = t-w;
137
282
        w  = fn*pio2_2t-((t-r)-w);  
138
282
        y[0] = r-w;
139
282
        GET_HIGH_WORD(high,y[0]);
140
282
        i = j-((high>>20)&0x7ff);
141
282
        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
282
    }
149
628
      }
150
628
      y[1] = (r-y[0])-w;
151
628
      return n;
152
628
  }
153
    /* 
154
     * all other (large) arguments
155
     */
156
2.85k
  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.85k
  GET_LOW_WORD(low,x);
161
2.85k
  e0  = (ix>>20)-1046;  /* e0 = ilogb(z)-23; */
162
2.85k
  INSERT_WORDS(z, ix - ((int32_t)((u_int32_t)e0<<20)), low);
163
8.55k
  for(i=0;i<2;i++) {
164
5.70k
    tx[i] = (double)((int32_t)(z));
165
5.70k
    z     = (z-tx[i])*two24;
166
5.70k
  }
167
2.85k
  tx[2] = z;
168
2.85k
  nx = 3;
169
5.59k
  while(tx[nx-1]==zero) nx--; /* skip zero term */
170
2.85k
  n  =  __kernel_rem_pio2(tx,ty,e0,nx,1);
171
2.85k
  if(hx<0) {y[0] = -ty[0]; y[1] = -ty[1]; return -n;}
172
823
  y[0] = ty[0]; y[1] = ty[1]; return n;
173
2.85k
}