Coverage Report

Created: 2026-08-13 06:36

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
244k
{
50
244k
  double z,w,t,r,fn;
51
244k
  double tx[3],ty[2];
52
244k
  int32_t e0,i,j,nx,n,ix,hx;
53
244k
  u_int32_t low;
54
55
244k
  GET_HIGH_WORD(hx,x);   /* high word of x */
56
244k
  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
244k
  if (ix <= 0x400f6a7a) {   /* |x| ~<= 5pi/4 */
62
144k
      if ((ix & 0xfffff) == 0x921fb)  /* |x| ~= pi/2 or 2pi/2 */
63
0
    goto medium;   /* cancellation -- use medium case */
64
144k
      if (ix <= 0x4002d97c) { /* |x| ~<= 3pi/4 */
65
138k
    if (hx > 0) {
66
135k
        z = x - pio2_1; /* one round good to 85 bits */
67
135k
        y[0] = z - pio2_1t;
68
135k
        y[1] = (z-y[0])-pio2_1t;
69
135k
        return 1;
70
135k
    } else {
71
2.67k
        z = x + pio2_1;
72
2.67k
        y[0] = z + pio2_1t;
73
2.67k
        y[1] = (z-y[0])+pio2_1t;
74
2.67k
        return -1;
75
2.67k
    }
76
138k
      } else {
77
5.70k
    if (hx > 0) {
78
2.30k
        z = x - 2*pio2_1;
79
2.30k
        y[0] = z - 2*pio2_1t;
80
2.30k
        y[1] = (z-y[0])-2*pio2_1t;
81
2.30k
        return 2;
82
3.39k
    } else {
83
3.39k
        z = x + 2*pio2_1;
84
3.39k
        y[0] = z + 2*pio2_1t;
85
3.39k
        y[1] = (z-y[0])+2*pio2_1t;
86
3.39k
        return -2;
87
3.39k
    }
88
5.70k
      }
89
144k
  }
90
100k
  if (ix <= 0x401c463b) {   /* |x| ~<= 9pi/4 */
91
7.73k
      if (ix <= 0x4015fdbc) { /* |x| ~<= 7pi/4 */
92
4.47k
    if (ix == 0x4012d97c)  /* |x| ~= 3pi/2 */
93
0
        goto medium;
94
4.47k
    if (hx > 0) {
95
2.38k
        z = x - 3*pio2_1;
96
2.38k
        y[0] = z - 3*pio2_1t;
97
2.38k
        y[1] = (z-y[0])-3*pio2_1t;
98
2.38k
        return 3;
99
2.38k
    } else {
100
2.09k
        z = x + 3*pio2_1;
101
2.09k
        y[0] = z + 3*pio2_1t;
102
2.09k
        y[1] = (z-y[0])+3*pio2_1t;
103
2.09k
        return -3;
104
2.09k
    }
105
4.47k
      } else {
106
3.26k
    if (ix == 0x401921fb)  /* |x| ~= 4pi/2 */
107
0
        goto medium;
108
3.26k
    if (hx > 0) {
109
1.51k
        z = x - 4*pio2_1;
110
1.51k
        y[0] = z - 4*pio2_1t;
111
1.51k
        y[1] = (z-y[0])-4*pio2_1t;
112
1.51k
        return 4;
113
1.74k
    } else {
114
1.74k
        z = x + 4*pio2_1;
115
1.74k
        y[0] = z + 4*pio2_1t;
116
1.74k
        y[1] = (z-y[0])+4*pio2_1t;
117
1.74k
        return -4;
118
1.74k
    }
119
3.26k
      }
120
7.73k
  }
121
92.4k
  if(ix<0x413921fb) { /* |x| ~< 2^20*(pi/2), medium size */
122
82.3k
medium:
123
82.3k
      fn = rnint((double_t)x*invpio2);
124
82.3k
      n  = irint(fn);
125
82.3k
      r  = x-fn*pio2_1;
126
82.3k
      w  = fn*pio2_1t;  /* 1st round good to 85 bit */
127
82.3k
      {
128
82.3k
          u_int32_t high;
129
82.3k
          j  = ix>>20;
130
82.3k
          y[0] = r-w; 
131
82.3k
    GET_HIGH_WORD(high,y[0]);
132
82.3k
          i = j-((high>>20)&0x7ff);
133
82.3k
          if(i>16) {  /* 2nd iteration needed, good to 118 */
134
2.52k
        t  = r;
135
2.52k
        w  = fn*pio2_2; 
136
2.52k
        r  = t-w;
137
2.52k
        w  = fn*pio2_2t-((t-r)-w);  
138
2.52k
        y[0] = r-w;
139
2.52k
        GET_HIGH_WORD(high,y[0]);
140
2.52k
        i = j-((high>>20)&0x7ff);
141
2.52k
        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
2.52k
    }
149
82.3k
      }
150
82.3k
      y[1] = (r-y[0])-w;
151
82.3k
      return n;
152
82.3k
  }
153
    /* 
154
     * all other (large) arguments
155
     */
156
10.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
10.1k
  GET_LOW_WORD(low,x);
161
10.1k
  e0  = (ix>>20)-1046;  /* e0 = ilogb(z)-23; */
162
10.1k
  INSERT_WORDS(z, ix - ((int32_t)((u_int32_t)e0<<20)), low);
163
30.3k
  for(i=0;i<2;i++) {
164
20.2k
    tx[i] = (double)((int32_t)(z));
165
20.2k
    z     = (z-tx[i])*two24;
166
20.2k
  }
167
10.1k
  tx[2] = z;
168
10.1k
  nx = 3;
169
18.6k
  while(tx[nx-1]==zero) nx--; /* skip zero term */
170
10.1k
  n  =  __kernel_rem_pio2(tx,ty,e0,nx,1);
171
10.1k
  if(hx<0) {y[0] = -ty[0]; y[1] = -ty[1]; return -n;}
172
2.94k
  y[0] = ty[0]; y[1] = ty[1]; return n;
173
10.1k
}
Unexecuted instantiation: __ieee754_rem_pio2
s_cos.c:__ieee754_rem_pio2
Line
Count
Source
49
192k
{
50
192k
  double z,w,t,r,fn;
51
192k
  double tx[3],ty[2];
52
192k
  int32_t e0,i,j,nx,n,ix,hx;
53
192k
  u_int32_t low;
54
55
192k
  GET_HIGH_WORD(hx,x);   /* high word of x */
56
192k
  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
192k
  if (ix <= 0x400f6a7a) {   /* |x| ~<= 5pi/4 */
62
134k
      if ((ix & 0xfffff) == 0x921fb)  /* |x| ~= pi/2 or 2pi/2 */
63
0
    goto medium;   /* cancellation -- use medium case */
64
134k
      if (ix <= 0x4002d97c) { /* |x| ~<= 3pi/4 */
65
133k
    if (hx > 0) {
66
132k
        z = x - pio2_1; /* one round good to 85 bits */
67
132k
        y[0] = z - pio2_1t;
68
132k
        y[1] = (z-y[0])-pio2_1t;
69
132k
        return 1;
70
132k
    } else {
71
1.17k
        z = x + pio2_1;
72
1.17k
        y[0] = z + pio2_1t;
73
1.17k
        y[1] = (z-y[0])+pio2_1t;
74
1.17k
        return -1;
75
1.17k
    }
76
133k
      } else {
77
1.48k
    if (hx > 0) {
78
481
        z = x - 2*pio2_1;
79
481
        y[0] = z - 2*pio2_1t;
80
481
        y[1] = (z-y[0])-2*pio2_1t;
81
481
        return 2;
82
1.00k
    } else {
83
1.00k
        z = x + 2*pio2_1;
84
1.00k
        y[0] = z + 2*pio2_1t;
85
1.00k
        y[1] = (z-y[0])+2*pio2_1t;
86
1.00k
        return -2;
87
1.00k
    }
88
1.48k
      }
89
134k
  }
90
57.6k
  if (ix <= 0x401c463b) {   /* |x| ~<= 9pi/4 */
91
2.24k
      if (ix <= 0x4015fdbc) { /* |x| ~<= 7pi/4 */
92
1.04k
    if (ix == 0x4012d97c)  /* |x| ~= 3pi/2 */
93
0
        goto medium;
94
1.04k
    if (hx > 0) {
95
413
        z = x - 3*pio2_1;
96
413
        y[0] = z - 3*pio2_1t;
97
413
        y[1] = (z-y[0])-3*pio2_1t;
98
413
        return 3;
99
634
    } else {
100
634
        z = x + 3*pio2_1;
101
634
        y[0] = z + 3*pio2_1t;
102
634
        y[1] = (z-y[0])+3*pio2_1t;
103
634
        return -3;
104
634
    }
105
1.19k
      } else {
106
1.19k
    if (ix == 0x401921fb)  /* |x| ~= 4pi/2 */
107
0
        goto medium;
108
1.19k
    if (hx > 0) {
109
288
        z = x - 4*pio2_1;
110
288
        y[0] = z - 4*pio2_1t;
111
288
        y[1] = (z-y[0])-4*pio2_1t;
112
288
        return 4;
113
911
    } else {
114
911
        z = x + 4*pio2_1;
115
911
        y[0] = z + 4*pio2_1t;
116
911
        y[1] = (z-y[0])+4*pio2_1t;
117
911
        return -4;
118
911
    }
119
1.19k
      }
120
2.24k
  }
121
55.3k
  if(ix<0x413921fb) { /* |x| ~< 2^20*(pi/2), medium size */
122
54.5k
medium:
123
54.5k
      fn = rnint((double_t)x*invpio2);
124
54.5k
      n  = irint(fn);
125
54.5k
      r  = x-fn*pio2_1;
126
54.5k
      w  = fn*pio2_1t;  /* 1st round good to 85 bit */
127
54.5k
      {
128
54.5k
          u_int32_t high;
129
54.5k
          j  = ix>>20;
130
54.5k
          y[0] = r-w; 
131
54.5k
    GET_HIGH_WORD(high,y[0]);
132
54.5k
          i = j-((high>>20)&0x7ff);
133
54.5k
          if(i>16) {  /* 2nd iteration needed, good to 118 */
134
271
        t  = r;
135
271
        w  = fn*pio2_2; 
136
271
        r  = t-w;
137
271
        w  = fn*pio2_2t-((t-r)-w);  
138
271
        y[0] = r-w;
139
271
        GET_HIGH_WORD(high,y[0]);
140
271
        i = j-((high>>20)&0x7ff);
141
271
        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
271
    }
149
54.5k
      }
150
54.5k
      y[1] = (r-y[0])-w;
151
54.5k
      return n;
152
54.5k
  }
153
    /* 
154
     * all other (large) arguments
155
     */
156
875
  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
875
  GET_LOW_WORD(low,x);
161
875
  e0  = (ix>>20)-1046;  /* e0 = ilogb(z)-23; */
162
875
  INSERT_WORDS(z, ix - ((int32_t)((u_int32_t)e0<<20)), low);
163
2.62k
  for(i=0;i<2;i++) {
164
1.75k
    tx[i] = (double)((int32_t)(z));
165
1.75k
    z     = (z-tx[i])*two24;
166
1.75k
  }
167
875
  tx[2] = z;
168
875
  nx = 3;
169
1.49k
  while(tx[nx-1]==zero) nx--; /* skip zero term */
170
875
  n  =  __kernel_rem_pio2(tx,ty,e0,nx,1);
171
875
  if(hx<0) {y[0] = -ty[0]; y[1] = -ty[1]; return -n;}
172
384
  y[0] = ty[0]; y[1] = ty[1]; return n;
173
875
}
s_sin.c:__ieee754_rem_pio2
Line
Count
Source
49
18.5k
{
50
18.5k
  double z,w,t,r,fn;
51
18.5k
  double tx[3],ty[2];
52
18.5k
  int32_t e0,i,j,nx,n,ix,hx;
53
18.5k
  u_int32_t low;
54
55
18.5k
  GET_HIGH_WORD(hx,x);   /* high word of x */
56
18.5k
  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
18.5k
  if (ix <= 0x400f6a7a) {   /* |x| ~<= 5pi/4 */
62
8.10k
      if ((ix & 0xfffff) == 0x921fb)  /* |x| ~= pi/2 or 2pi/2 */
63
0
    goto medium;   /* cancellation -- use medium case */
64
8.10k
      if (ix <= 0x4002d97c) { /* |x| ~<= 3pi/4 */
65
4.29k
    if (hx > 0) {
66
3.06k
        z = x - pio2_1; /* one round good to 85 bits */
67
3.06k
        y[0] = z - pio2_1t;
68
3.06k
        y[1] = (z-y[0])-pio2_1t;
69
3.06k
        return 1;
70
3.06k
    } else {
71
1.22k
        z = x + pio2_1;
72
1.22k
        y[0] = z + pio2_1t;
73
1.22k
        y[1] = (z-y[0])+pio2_1t;
74
1.22k
        return -1;
75
1.22k
    }
76
4.29k
      } else {
77
3.81k
    if (hx > 0) {
78
1.60k
        z = x - 2*pio2_1;
79
1.60k
        y[0] = z - 2*pio2_1t;
80
1.60k
        y[1] = (z-y[0])-2*pio2_1t;
81
1.60k
        return 2;
82
2.21k
    } else {
83
2.21k
        z = x + 2*pio2_1;
84
2.21k
        y[0] = z + 2*pio2_1t;
85
2.21k
        y[1] = (z-y[0])+2*pio2_1t;
86
2.21k
        return -2;
87
2.21k
    }
88
3.81k
      }
89
8.10k
  }
90
10.4k
  if (ix <= 0x401c463b) {   /* |x| ~<= 9pi/4 */
91
4.49k
      if (ix <= 0x4015fdbc) { /* |x| ~<= 7pi/4 */
92
2.92k
    if (ix == 0x4012d97c)  /* |x| ~= 3pi/2 */
93
0
        goto medium;
94
2.92k
    if (hx > 0) {
95
1.58k
        z = x - 3*pio2_1;
96
1.58k
        y[0] = z - 3*pio2_1t;
97
1.58k
        y[1] = (z-y[0])-3*pio2_1t;
98
1.58k
        return 3;
99
1.58k
    } else {
100
1.33k
        z = x + 3*pio2_1;
101
1.33k
        y[0] = z + 3*pio2_1t;
102
1.33k
        y[1] = (z-y[0])+3*pio2_1t;
103
1.33k
        return -3;
104
1.33k
    }
105
2.92k
      } else {
106
1.57k
    if (ix == 0x401921fb)  /* |x| ~= 4pi/2 */
107
0
        goto medium;
108
1.57k
    if (hx > 0) {
109
863
        z = x - 4*pio2_1;
110
863
        y[0] = z - 4*pio2_1t;
111
863
        y[1] = (z-y[0])-4*pio2_1t;
112
863
        return 4;
113
863
    } else {
114
709
        z = x + 4*pio2_1;
115
709
        y[0] = z + 4*pio2_1t;
116
709
        y[1] = (z-y[0])+4*pio2_1t;
117
709
        return -4;
118
709
    }
119
1.57k
      }
120
4.49k
  }
121
5.92k
  if(ix<0x413921fb) { /* |x| ~< 2^20*(pi/2), medium size */
122
3.08k
medium:
123
3.08k
      fn = rnint((double_t)x*invpio2);
124
3.08k
      n  = irint(fn);
125
3.08k
      r  = x-fn*pio2_1;
126
3.08k
      w  = fn*pio2_1t;  /* 1st round good to 85 bit */
127
3.08k
      {
128
3.08k
          u_int32_t high;
129
3.08k
          j  = ix>>20;
130
3.08k
          y[0] = r-w; 
131
3.08k
    GET_HIGH_WORD(high,y[0]);
132
3.08k
          i = j-((high>>20)&0x7ff);
133
3.08k
          if(i>16) {  /* 2nd iteration needed, good to 118 */
134
214
        t  = r;
135
214
        w  = fn*pio2_2; 
136
214
        r  = t-w;
137
214
        w  = fn*pio2_2t-((t-r)-w);  
138
214
        y[0] = r-w;
139
214
        GET_HIGH_WORD(high,y[0]);
140
214
        i = j-((high>>20)&0x7ff);
141
214
        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
214
    }
149
3.08k
      }
150
3.08k
      y[1] = (r-y[0])-w;
151
3.08k
      return n;
152
3.08k
  }
153
    /* 
154
     * all other (large) arguments
155
     */
156
2.83k
  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.83k
  GET_LOW_WORD(low,x);
161
2.83k
  e0  = (ix>>20)-1046;  /* e0 = ilogb(z)-23; */
162
2.83k
  INSERT_WORDS(z, ix - ((int32_t)((u_int32_t)e0<<20)), low);
163
8.51k
  for(i=0;i<2;i++) {
164
5.67k
    tx[i] = (double)((int32_t)(z));
165
5.67k
    z     = (z-tx[i])*two24;
166
5.67k
  }
167
2.83k
  tx[2] = z;
168
2.83k
  nx = 3;
169
7.92k
  while(tx[nx-1]==zero) nx--; /* skip zero term */
170
2.83k
  n  =  __kernel_rem_pio2(tx,ty,e0,nx,1);
171
2.83k
  if(hx<0) {y[0] = -ty[0]; y[1] = -ty[1]; return -n;}
172
1.13k
  y[0] = ty[0]; y[1] = ty[1]; return n;
173
2.83k
}
s_tan.c:__ieee754_rem_pio2
Line
Count
Source
49
33.4k
{
50
33.4k
  double z,w,t,r,fn;
51
33.4k
  double tx[3],ty[2];
52
33.4k
  int32_t e0,i,j,nx,n,ix,hx;
53
33.4k
  u_int32_t low;
54
55
33.4k
  GET_HIGH_WORD(hx,x);   /* high word of x */
56
33.4k
  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
33.4k
  if (ix <= 0x400f6a7a) {   /* |x| ~<= 5pi/4 */
62
1.29k
      if ((ix & 0xfffff) == 0x921fb)  /* |x| ~= pi/2 or 2pi/2 */
63
0
    goto medium;   /* cancellation -- use medium case */
64
1.29k
      if (ix <= 0x4002d97c) { /* |x| ~<= 3pi/4 */
65
895
    if (hx > 0) {
66
622
        z = x - pio2_1; /* one round good to 85 bits */
67
622
        y[0] = z - pio2_1t;
68
622
        y[1] = (z-y[0])-pio2_1t;
69
622
        return 1;
70
622
    } else {
71
273
        z = x + pio2_1;
72
273
        y[0] = z + pio2_1t;
73
273
        y[1] = (z-y[0])+pio2_1t;
74
273
        return -1;
75
273
    }
76
895
      } else {
77
398
    if (hx > 0) {
78
222
        z = x - 2*pio2_1;
79
222
        y[0] = z - 2*pio2_1t;
80
222
        y[1] = (z-y[0])-2*pio2_1t;
81
222
        return 2;
82
222
    } else {
83
176
        z = x + 2*pio2_1;
84
176
        y[0] = z + 2*pio2_1t;
85
176
        y[1] = (z-y[0])+2*pio2_1t;
86
176
        return -2;
87
176
    }
88
398
      }
89
1.29k
  }
90
32.1k
  if (ix <= 0x401c463b) {   /* |x| ~<= 9pi/4 */
91
1.00k
      if (ix <= 0x4015fdbc) { /* |x| ~<= 7pi/4 */
92
510
    if (ix == 0x4012d97c)  /* |x| ~= 3pi/2 */
93
0
        goto medium;
94
510
    if (hx > 0) {
95
386
        z = x - 3*pio2_1;
96
386
        y[0] = z - 3*pio2_1t;
97
386
        y[1] = (z-y[0])-3*pio2_1t;
98
386
        return 3;
99
386
    } else {
100
124
        z = x + 3*pio2_1;
101
124
        y[0] = z + 3*pio2_1t;
102
124
        y[1] = (z-y[0])+3*pio2_1t;
103
124
        return -3;
104
124
    }
105
510
      } else {
106
490
    if (ix == 0x401921fb)  /* |x| ~= 4pi/2 */
107
0
        goto medium;
108
490
    if (hx > 0) {
109
364
        z = x - 4*pio2_1;
110
364
        y[0] = z - 4*pio2_1t;
111
364
        y[1] = (z-y[0])-4*pio2_1t;
112
364
        return 4;
113
364
    } else {
114
126
        z = x + 4*pio2_1;
115
126
        y[0] = z + 4*pio2_1t;
116
126
        y[1] = (z-y[0])+4*pio2_1t;
117
126
        return -4;
118
126
    }
119
490
      }
120
1.00k
  }
121
31.1k
  if(ix<0x413921fb) { /* |x| ~< 2^20*(pi/2), medium size */
122
24.7k
medium:
123
24.7k
      fn = rnint((double_t)x*invpio2);
124
24.7k
      n  = irint(fn);
125
24.7k
      r  = x-fn*pio2_1;
126
24.7k
      w  = fn*pio2_1t;  /* 1st round good to 85 bit */
127
24.7k
      {
128
24.7k
          u_int32_t high;
129
24.7k
          j  = ix>>20;
130
24.7k
          y[0] = r-w; 
131
24.7k
    GET_HIGH_WORD(high,y[0]);
132
24.7k
          i = j-((high>>20)&0x7ff);
133
24.7k
          if(i>16) {  /* 2nd iteration needed, good to 118 */
134
2.04k
        t  = r;
135
2.04k
        w  = fn*pio2_2; 
136
2.04k
        r  = t-w;
137
2.04k
        w  = fn*pio2_2t-((t-r)-w);  
138
2.04k
        y[0] = r-w;
139
2.04k
        GET_HIGH_WORD(high,y[0]);
140
2.04k
        i = j-((high>>20)&0x7ff);
141
2.04k
        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
2.04k
    }
149
24.7k
      }
150
24.7k
      y[1] = (r-y[0])-w;
151
24.7k
      return n;
152
24.7k
  }
153
    /* 
154
     * all other (large) arguments
155
     */
156
6.39k
  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
6.39k
  GET_LOW_WORD(low,x);
161
6.39k
  e0  = (ix>>20)-1046;  /* e0 = ilogb(z)-23; */
162
6.39k
  INSERT_WORDS(z, ix - ((int32_t)((u_int32_t)e0<<20)), low);
163
19.1k
  for(i=0;i<2;i++) {
164
12.7k
    tx[i] = (double)((int32_t)(z));
165
12.7k
    z     = (z-tx[i])*two24;
166
12.7k
  }
167
6.39k
  tx[2] = z;
168
6.39k
  nx = 3;
169
9.27k
  while(tx[nx-1]==zero) nx--; /* skip zero term */
170
6.39k
  n  =  __kernel_rem_pio2(tx,ty,e0,nx,1);
171
6.39k
  if(hx<0) {y[0] = -ty[0]; y[1] = -ty[1]; return -n;}
172
1.42k
  y[0] = ty[0]; y[1] = ty[1]; return n;
173
6.39k
}