Coverage Report

Created: 2026-03-16 06:17

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
406k
{
50
406k
  double z,w,t,r,fn;
51
406k
  double tx[3],ty[2];
52
406k
  int32_t e0,i,j,nx,n,ix,hx;
53
406k
  u_int32_t low;
54
55
406k
  GET_HIGH_WORD(hx,x);   /* high word of x */
56
406k
  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
406k
  if (ix <= 0x400f6a7a) {   /* |x| ~<= 5pi/4 */
62
217k
      if ((ix & 0xfffff) == 0x921fb)  /* |x| ~= pi/2 or 2pi/2 */
63
0
    goto medium;   /* cancellation -- use medium case */
64
217k
      if (ix <= 0x4002d97c) { /* |x| ~<= 3pi/4 */
65
209k
    if (hx > 0) {
66
202k
        z = x - pio2_1; /* one round good to 85 bits */
67
202k
        y[0] = z - pio2_1t;
68
202k
        y[1] = (z-y[0])-pio2_1t;
69
202k
        return 1;
70
202k
    } else {
71
6.22k
        z = x + pio2_1;
72
6.22k
        y[0] = z + pio2_1t;
73
6.22k
        y[1] = (z-y[0])+pio2_1t;
74
6.22k
        return -1;
75
6.22k
    }
76
209k
      } else {
77
8.46k
    if (hx > 0) {
78
2.08k
        z = x - 2*pio2_1;
79
2.08k
        y[0] = z - 2*pio2_1t;
80
2.08k
        y[1] = (z-y[0])-2*pio2_1t;
81
2.08k
        return 2;
82
6.38k
    } else {
83
6.38k
        z = x + 2*pio2_1;
84
6.38k
        y[0] = z + 2*pio2_1t;
85
6.38k
        y[1] = (z-y[0])+2*pio2_1t;
86
6.38k
        return -2;
87
6.38k
    }
88
8.46k
      }
89
217k
  }
90
189k
  if (ix <= 0x401c463b) {   /* |x| ~<= 9pi/4 */
91
19.6k
      if (ix <= 0x4015fdbc) { /* |x| ~<= 7pi/4 */
92
13.1k
    if (ix == 0x4012d97c)  /* |x| ~= 3pi/2 */
93
0
        goto medium;
94
13.1k
    if (hx > 0) {
95
8.24k
        z = x - 3*pio2_1;
96
8.24k
        y[0] = z - 3*pio2_1t;
97
8.24k
        y[1] = (z-y[0])-3*pio2_1t;
98
8.24k
        return 3;
99
8.24k
    } else {
100
4.92k
        z = x + 3*pio2_1;
101
4.92k
        y[0] = z + 3*pio2_1t;
102
4.92k
        y[1] = (z-y[0])+3*pio2_1t;
103
4.92k
        return -3;
104
4.92k
    }
105
13.1k
      } else {
106
6.45k
    if (ix == 0x401921fb)  /* |x| ~= 4pi/2 */
107
0
        goto medium;
108
6.45k
    if (hx > 0) {
109
822
        z = x - 4*pio2_1;
110
822
        y[0] = z - 4*pio2_1t;
111
822
        y[1] = (z-y[0])-4*pio2_1t;
112
822
        return 4;
113
5.63k
    } else {
114
5.63k
        z = x + 4*pio2_1;
115
5.63k
        y[0] = z + 4*pio2_1t;
116
5.63k
        y[1] = (z-y[0])+4*pio2_1t;
117
5.63k
        return -4;
118
5.63k
    }
119
6.45k
      }
120
19.6k
  }
121
169k
  if(ix<0x413921fb) { /* |x| ~< 2^20*(pi/2), medium size */
122
87.9k
medium:
123
87.9k
      fn = rnint((double_t)x*invpio2);
124
87.9k
      n  = irint(fn);
125
87.9k
      r  = x-fn*pio2_1;
126
87.9k
      w  = fn*pio2_1t;  /* 1st round good to 85 bit */
127
87.9k
      {
128
87.9k
          u_int32_t high;
129
87.9k
          j  = ix>>20;
130
87.9k
          y[0] = r-w; 
131
87.9k
    GET_HIGH_WORD(high,y[0]);
132
87.9k
          i = j-((high>>20)&0x7ff);
133
87.9k
          if(i>16) {  /* 2nd iteration needed, good to 118 */
134
8.17k
        t  = r;
135
8.17k
        w  = fn*pio2_2; 
136
8.17k
        r  = t-w;
137
8.17k
        w  = fn*pio2_2t-((t-r)-w);  
138
8.17k
        y[0] = r-w;
139
8.17k
        GET_HIGH_WORD(high,y[0]);
140
8.17k
        i = j-((high>>20)&0x7ff);
141
8.17k
        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
8.17k
    }
149
87.9k
      }
150
87.9k
      y[1] = (r-y[0])-w;
151
87.9k
      return n;
152
87.9k
  }
153
    /* 
154
     * all other (large) arguments
155
     */
156
81.7k
  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
81.7k
  GET_LOW_WORD(low,x);
161
81.7k
  e0  = (ix>>20)-1046;  /* e0 = ilogb(z)-23; */
162
81.7k
  INSERT_WORDS(z, ix - ((int32_t)((u_int32_t)e0<<20)), low);
163
245k
  for(i=0;i<2;i++) {
164
163k
    tx[i] = (double)((int32_t)(z));
165
163k
    z     = (z-tx[i])*two24;
166
163k
  }
167
81.7k
  tx[2] = z;
168
81.7k
  nx = 3;
169
92.3k
  while(tx[nx-1]==zero) nx--; /* skip zero term */
170
81.7k
  n  =  __kernel_rem_pio2(tx,ty,e0,nx,1);
171
81.7k
  if(hx<0) {y[0] = -ty[0]; y[1] = -ty[1]; return -n;}
172
27.3k
  y[0] = ty[0]; y[1] = ty[1]; return n;
173
81.7k
}
Unexecuted instantiation: __ieee754_rem_pio2
s_cos.c:__ieee754_rem_pio2
Line
Count
Source
49
388k
{
50
388k
  double z,w,t,r,fn;
51
388k
  double tx[3],ty[2];
52
388k
  int32_t e0,i,j,nx,n,ix,hx;
53
388k
  u_int32_t low;
54
55
388k
  GET_HIGH_WORD(hx,x);   /* high word of x */
56
388k
  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
388k
  if (ix <= 0x400f6a7a) {   /* |x| ~<= 5pi/4 */
62
212k
      if ((ix & 0xfffff) == 0x921fb)  /* |x| ~= pi/2 or 2pi/2 */
63
0
    goto medium;   /* cancellation -- use medium case */
64
212k
      if (ix <= 0x4002d97c) { /* |x| ~<= 3pi/4 */
65
206k
    if (hx > 0) {
66
201k
        z = x - pio2_1; /* one round good to 85 bits */
67
201k
        y[0] = z - pio2_1t;
68
201k
        y[1] = (z-y[0])-pio2_1t;
69
201k
        return 1;
70
201k
    } else {
71
5.29k
        z = x + pio2_1;
72
5.29k
        y[0] = z + pio2_1t;
73
5.29k
        y[1] = (z-y[0])+pio2_1t;
74
5.29k
        return -1;
75
5.29k
    }
76
206k
      } else {
77
5.70k
    if (hx > 0) {
78
630
        z = x - 2*pio2_1;
79
630
        y[0] = z - 2*pio2_1t;
80
630
        y[1] = (z-y[0])-2*pio2_1t;
81
630
        return 2;
82
5.07k
    } else {
83
5.07k
        z = x + 2*pio2_1;
84
5.07k
        y[0] = z + 2*pio2_1t;
85
5.07k
        y[1] = (z-y[0])+2*pio2_1t;
86
5.07k
        return -2;
87
5.07k
    }
88
5.70k
      }
89
212k
  }
90
175k
  if (ix <= 0x401c463b) {   /* |x| ~<= 9pi/4 */
91
16.0k
      if (ix <= 0x4015fdbc) { /* |x| ~<= 7pi/4 */
92
10.6k
    if (ix == 0x4012d97c)  /* |x| ~= 3pi/2 */
93
0
        goto medium;
94
10.6k
    if (hx > 0) {
95
7.91k
        z = x - 3*pio2_1;
96
7.91k
        y[0] = z - 3*pio2_1t;
97
7.91k
        y[1] = (z-y[0])-3*pio2_1t;
98
7.91k
        return 3;
99
7.91k
    } else {
100
2.75k
        z = x + 3*pio2_1;
101
2.75k
        y[0] = z + 3*pio2_1t;
102
2.75k
        y[1] = (z-y[0])+3*pio2_1t;
103
2.75k
        return -3;
104
2.75k
    }
105
10.6k
      } else {
106
5.33k
    if (ix == 0x401921fb)  /* |x| ~= 4pi/2 */
107
0
        goto medium;
108
5.33k
    if (hx > 0) {
109
376
        z = x - 4*pio2_1;
110
376
        y[0] = z - 4*pio2_1t;
111
376
        y[1] = (z-y[0])-4*pio2_1t;
112
376
        return 4;
113
4.96k
    } else {
114
4.96k
        z = x + 4*pio2_1;
115
4.96k
        y[0] = z + 4*pio2_1t;
116
4.96k
        y[1] = (z-y[0])+4*pio2_1t;
117
4.96k
        return -4;
118
4.96k
    }
119
5.33k
      }
120
16.0k
  }
121
159k
  if(ix<0x413921fb) { /* |x| ~< 2^20*(pi/2), medium size */
122
85.7k
medium:
123
85.7k
      fn = rnint((double_t)x*invpio2);
124
85.7k
      n  = irint(fn);
125
85.7k
      r  = x-fn*pio2_1;
126
85.7k
      w  = fn*pio2_1t;  /* 1st round good to 85 bit */
127
85.7k
      {
128
85.7k
          u_int32_t high;
129
85.7k
          j  = ix>>20;
130
85.7k
          y[0] = r-w; 
131
85.7k
    GET_HIGH_WORD(high,y[0]);
132
85.7k
          i = j-((high>>20)&0x7ff);
133
85.7k
          if(i>16) {  /* 2nd iteration needed, good to 118 */
134
7.51k
        t  = r;
135
7.51k
        w  = fn*pio2_2; 
136
7.51k
        r  = t-w;
137
7.51k
        w  = fn*pio2_2t-((t-r)-w);  
138
7.51k
        y[0] = r-w;
139
7.51k
        GET_HIGH_WORD(high,y[0]);
140
7.51k
        i = j-((high>>20)&0x7ff);
141
7.51k
        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
7.51k
    }
149
85.7k
      }
150
85.7k
      y[1] = (r-y[0])-w;
151
85.7k
      return n;
152
85.7k
  }
153
    /* 
154
     * all other (large) arguments
155
     */
156
74.1k
  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
74.1k
  GET_LOW_WORD(low,x);
161
74.1k
  e0  = (ix>>20)-1046;  /* e0 = ilogb(z)-23; */
162
74.1k
  INSERT_WORDS(z, ix - ((int32_t)((u_int32_t)e0<<20)), low);
163
222k
  for(i=0;i<2;i++) {
164
148k
    tx[i] = (double)((int32_t)(z));
165
148k
    z     = (z-tx[i])*two24;
166
148k
  }
167
74.1k
  tx[2] = z;
168
74.1k
  nx = 3;
169
76.0k
  while(tx[nx-1]==zero) nx--; /* skip zero term */
170
74.1k
  n  =  __kernel_rem_pio2(tx,ty,e0,nx,1);
171
74.1k
  if(hx<0) {y[0] = -ty[0]; y[1] = -ty[1]; return -n;}
172
23.1k
  y[0] = ty[0]; y[1] = ty[1]; return n;
173
74.1k
}
s_sin.c:__ieee754_rem_pio2
Line
Count
Source
49
10.6k
{
50
10.6k
  double z,w,t,r,fn;
51
10.6k
  double tx[3],ty[2];
52
10.6k
  int32_t e0,i,j,nx,n,ix,hx;
53
10.6k
  u_int32_t low;
54
55
10.6k
  GET_HIGH_WORD(hx,x);   /* high word of x */
56
10.6k
  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
10.6k
  if (ix <= 0x400f6a7a) {   /* |x| ~<= 5pi/4 */
62
3.99k
      if ((ix & 0xfffff) == 0x921fb)  /* |x| ~= pi/2 or 2pi/2 */
63
0
    goto medium;   /* cancellation -- use medium case */
64
3.99k
      if (ix <= 0x4002d97c) { /* |x| ~<= 3pi/4 */
65
1.47k
    if (hx > 0) {
66
823
        z = x - pio2_1; /* one round good to 85 bits */
67
823
        y[0] = z - pio2_1t;
68
823
        y[1] = (z-y[0])-pio2_1t;
69
823
        return 1;
70
823
    } else {
71
651
        z = x + pio2_1;
72
651
        y[0] = z + pio2_1t;
73
651
        y[1] = (z-y[0])+pio2_1t;
74
651
        return -1;
75
651
    }
76
2.51k
      } else {
77
2.51k
    if (hx > 0) {
78
1.35k
        z = x - 2*pio2_1;
79
1.35k
        y[0] = z - 2*pio2_1t;
80
1.35k
        y[1] = (z-y[0])-2*pio2_1t;
81
1.35k
        return 2;
82
1.35k
    } else {
83
1.16k
        z = x + 2*pio2_1;
84
1.16k
        y[0] = z + 2*pio2_1t;
85
1.16k
        y[1] = (z-y[0])+2*pio2_1t;
86
1.16k
        return -2;
87
1.16k
    }
88
2.51k
      }
89
3.99k
  }
90
6.63k
  if (ix <= 0x401c463b) {   /* |x| ~<= 9pi/4 */
91
2.76k
      if (ix <= 0x4015fdbc) { /* |x| ~<= 7pi/4 */
92
1.98k
    if (ix == 0x4012d97c)  /* |x| ~= 3pi/2 */
93
0
        goto medium;
94
1.98k
    if (hx > 0) {
95
134
        z = x - 3*pio2_1;
96
134
        y[0] = z - 3*pio2_1t;
97
134
        y[1] = (z-y[0])-3*pio2_1t;
98
134
        return 3;
99
1.84k
    } else {
100
1.84k
        z = x + 3*pio2_1;
101
1.84k
        y[0] = z + 3*pio2_1t;
102
1.84k
        y[1] = (z-y[0])+3*pio2_1t;
103
1.84k
        return -3;
104
1.84k
    }
105
1.98k
      } else {
106
789
    if (ix == 0x401921fb)  /* |x| ~= 4pi/2 */
107
0
        goto medium;
108
789
    if (hx > 0) {
109
251
        z = x - 4*pio2_1;
110
251
        y[0] = z - 4*pio2_1t;
111
251
        y[1] = (z-y[0])-4*pio2_1t;
112
251
        return 4;
113
538
    } else {
114
538
        z = x + 4*pio2_1;
115
538
        y[0] = z + 4*pio2_1t;
116
538
        y[1] = (z-y[0])+4*pio2_1t;
117
538
        return -4;
118
538
    }
119
789
      }
120
2.76k
  }
121
3.86k
  if(ix<0x413921fb) { /* |x| ~< 2^20*(pi/2), medium size */
122
1.17k
medium:
123
1.17k
      fn = rnint((double_t)x*invpio2);
124
1.17k
      n  = irint(fn);
125
1.17k
      r  = x-fn*pio2_1;
126
1.17k
      w  = fn*pio2_1t;  /* 1st round good to 85 bit */
127
1.17k
      {
128
1.17k
          u_int32_t high;
129
1.17k
          j  = ix>>20;
130
1.17k
          y[0] = r-w; 
131
1.17k
    GET_HIGH_WORD(high,y[0]);
132
1.17k
          i = j-((high>>20)&0x7ff);
133
1.17k
          if(i>16) {  /* 2nd iteration needed, good to 118 */
134
288
        t  = r;
135
288
        w  = fn*pio2_2; 
136
288
        r  = t-w;
137
288
        w  = fn*pio2_2t-((t-r)-w);  
138
288
        y[0] = r-w;
139
288
        GET_HIGH_WORD(high,y[0]);
140
288
        i = j-((high>>20)&0x7ff);
141
288
        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
288
    }
149
1.17k
      }
150
1.17k
      y[1] = (r-y[0])-w;
151
1.17k
      return n;
152
1.17k
  }
153
    /* 
154
     * all other (large) arguments
155
     */
156
2.68k
  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.68k
  GET_LOW_WORD(low,x);
161
2.68k
  e0  = (ix>>20)-1046;  /* e0 = ilogb(z)-23; */
162
2.68k
  INSERT_WORDS(z, ix - ((int32_t)((u_int32_t)e0<<20)), low);
163
8.06k
  for(i=0;i<2;i++) {
164
5.37k
    tx[i] = (double)((int32_t)(z));
165
5.37k
    z     = (z-tx[i])*two24;
166
5.37k
  }
167
2.68k
  tx[2] = z;
168
2.68k
  nx = 3;
169
7.47k
  while(tx[nx-1]==zero) nx--; /* skip zero term */
170
2.68k
  n  =  __kernel_rem_pio2(tx,ty,e0,nx,1);
171
2.68k
  if(hx<0) {y[0] = -ty[0]; y[1] = -ty[1]; return -n;}
172
1.08k
  y[0] = ty[0]; y[1] = ty[1]; return n;
173
2.68k
}
s_tan.c:__ieee754_rem_pio2
Line
Count
Source
49
7.86k
{
50
7.86k
  double z,w,t,r,fn;
51
7.86k
  double tx[3],ty[2];
52
7.86k
  int32_t e0,i,j,nx,n,ix,hx;
53
7.86k
  u_int32_t low;
54
55
7.86k
  GET_HIGH_WORD(hx,x);   /* high word of x */
56
7.86k
  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
7.86k
  if (ix <= 0x400f6a7a) {   /* |x| ~<= 5pi/4 */
62
1.06k
      if ((ix & 0xfffff) == 0x921fb)  /* |x| ~= pi/2 or 2pi/2 */
63
0
    goto medium;   /* cancellation -- use medium case */
64
1.06k
      if (ix <= 0x4002d97c) { /* |x| ~<= 3pi/4 */
65
818
    if (hx > 0) {
66
541
        z = x - pio2_1; /* one round good to 85 bits */
67
541
        y[0] = z - pio2_1t;
68
541
        y[1] = (z-y[0])-pio2_1t;
69
541
        return 1;
70
541
    } else {
71
277
        z = x + pio2_1;
72
277
        y[0] = z + pio2_1t;
73
277
        y[1] = (z-y[0])+pio2_1t;
74
277
        return -1;
75
277
    }
76
818
      } else {
77
242
    if (hx > 0) {
78
103
        z = x - 2*pio2_1;
79
103
        y[0] = z - 2*pio2_1t;
80
103
        y[1] = (z-y[0])-2*pio2_1t;
81
103
        return 2;
82
139
    } else {
83
139
        z = x + 2*pio2_1;
84
139
        y[0] = z + 2*pio2_1t;
85
139
        y[1] = (z-y[0])+2*pio2_1t;
86
139
        return -2;
87
139
    }
88
242
      }
89
1.06k
  }
90
6.80k
  if (ix <= 0x401c463b) {   /* |x| ~<= 9pi/4 */
91
850
      if (ix <= 0x4015fdbc) { /* |x| ~<= 7pi/4 */
92
523
    if (ix == 0x4012d97c)  /* |x| ~= 3pi/2 */
93
0
        goto medium;
94
523
    if (hx > 0) {
95
199
        z = x - 3*pio2_1;
96
199
        y[0] = z - 3*pio2_1t;
97
199
        y[1] = (z-y[0])-3*pio2_1t;
98
199
        return 3;
99
324
    } else {
100
324
        z = x + 3*pio2_1;
101
324
        y[0] = z + 3*pio2_1t;
102
324
        y[1] = (z-y[0])+3*pio2_1t;
103
324
        return -3;
104
324
    }
105
523
      } else {
106
327
    if (ix == 0x401921fb)  /* |x| ~= 4pi/2 */
107
0
        goto medium;
108
327
    if (hx > 0) {
109
195
        z = x - 4*pio2_1;
110
195
        y[0] = z - 4*pio2_1t;
111
195
        y[1] = (z-y[0])-4*pio2_1t;
112
195
        return 4;
113
195
    } else {
114
132
        z = x + 4*pio2_1;
115
132
        y[0] = z + 4*pio2_1t;
116
132
        y[1] = (z-y[0])+4*pio2_1t;
117
132
        return -4;
118
132
    }
119
327
      }
120
850
  }
121
5.95k
  if(ix<0x413921fb) { /* |x| ~< 2^20*(pi/2), medium size */
122
992
medium:
123
992
      fn = rnint((double_t)x*invpio2);
124
992
      n  = irint(fn);
125
992
      r  = x-fn*pio2_1;
126
992
      w  = fn*pio2_1t;  /* 1st round good to 85 bit */
127
992
      {
128
992
          u_int32_t high;
129
992
          j  = ix>>20;
130
992
          y[0] = r-w; 
131
992
    GET_HIGH_WORD(high,y[0]);
132
992
          i = j-((high>>20)&0x7ff);
133
992
          if(i>16) {  /* 2nd iteration needed, good to 118 */
134
374
        t  = r;
135
374
        w  = fn*pio2_2; 
136
374
        r  = t-w;
137
374
        w  = fn*pio2_2t-((t-r)-w);  
138
374
        y[0] = r-w;
139
374
        GET_HIGH_WORD(high,y[0]);
140
374
        i = j-((high>>20)&0x7ff);
141
374
        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
374
    }
149
992
      }
150
992
      y[1] = (r-y[0])-w;
151
992
      return n;
152
992
  }
153
    /* 
154
     * all other (large) arguments
155
     */
156
4.96k
  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.96k
  GET_LOW_WORD(low,x);
161
4.96k
  e0  = (ix>>20)-1046;  /* e0 = ilogb(z)-23; */
162
4.96k
  INSERT_WORDS(z, ix - ((int32_t)((u_int32_t)e0<<20)), low);
163
14.8k
  for(i=0;i<2;i++) {
164
9.92k
    tx[i] = (double)((int32_t)(z));
165
9.92k
    z     = (z-tx[i])*two24;
166
9.92k
  }
167
4.96k
  tx[2] = z;
168
4.96k
  nx = 3;
169
8.75k
  while(tx[nx-1]==zero) nx--; /* skip zero term */
170
4.96k
  n  =  __kernel_rem_pio2(tx,ty,e0,nx,1);
171
4.96k
  if(hx<0) {y[0] = -ty[0]; y[1] = -ty[1]; return -n;}
172
3.19k
  y[0] = ty[0]; y[1] = ty[1]; return n;
173
4.96k
}