Coverage Report

Created: 2025-08-03 06:59

/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
122k
{
50
122k
  double z,w,t,r,fn;
51
122k
  double tx[3],ty[2];
52
122k
  int32_t e0,i,j,nx,n,ix,hx;
53
122k
  u_int32_t low;
54
55
122k
  GET_HIGH_WORD(hx,x);   /* high word of x */
56
122k
  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
122k
  if (ix <= 0x400f6a7a) {   /* |x| ~<= 5pi/4 */
62
107k
      if ((ix & 0xfffff) == 0x921fb)  /* |x| ~= pi/2 or 2pi/2 */
63
0
    goto medium;   /* cancellation -- use medium case */
64
107k
      if (ix <= 0x4002d97c) { /* |x| ~<= 3pi/4 */
65
105k
    if (hx > 0) {
66
103k
        z = x - pio2_1; /* one round good to 85 bits */
67
103k
        y[0] = z - pio2_1t;
68
103k
        y[1] = (z-y[0])-pio2_1t;
69
103k
        return 1;
70
103k
    } else {
71
1.67k
        z = x + pio2_1;
72
1.67k
        y[0] = z + pio2_1t;
73
1.67k
        y[1] = (z-y[0])+pio2_1t;
74
1.67k
        return -1;
75
1.67k
    }
76
105k
      } else {
77
2.48k
    if (hx > 0) {
78
1.49k
        z = x - 2*pio2_1;
79
1.49k
        y[0] = z - 2*pio2_1t;
80
1.49k
        y[1] = (z-y[0])-2*pio2_1t;
81
1.49k
        return 2;
82
1.49k
    } else {
83
987
        z = x + 2*pio2_1;
84
987
        y[0] = z + 2*pio2_1t;
85
987
        y[1] = (z-y[0])+2*pio2_1t;
86
987
        return -2;
87
987
    }
88
2.48k
      }
89
107k
  }
90
14.4k
  if (ix <= 0x401c463b) {   /* |x| ~<= 9pi/4 */
91
3.65k
      if (ix <= 0x4015fdbc) { /* |x| ~<= 7pi/4 */
92
2.08k
    if (ix == 0x4012d97c)  /* |x| ~= 3pi/2 */
93
0
        goto medium;
94
2.08k
    if (hx > 0) {
95
1.00k
        z = x - 3*pio2_1;
96
1.00k
        y[0] = z - 3*pio2_1t;
97
1.00k
        y[1] = (z-y[0])-3*pio2_1t;
98
1.00k
        return 3;
99
1.08k
    } else {
100
1.08k
        z = x + 3*pio2_1;
101
1.08k
        y[0] = z + 3*pio2_1t;
102
1.08k
        y[1] = (z-y[0])+3*pio2_1t;
103
1.08k
        return -3;
104
1.08k
    }
105
2.08k
      } else {
106
1.57k
    if (ix == 0x401921fb)  /* |x| ~= 4pi/2 */
107
0
        goto medium;
108
1.57k
    if (hx > 0) {
109
941
        z = x - 4*pio2_1;
110
941
        y[0] = z - 4*pio2_1t;
111
941
        y[1] = (z-y[0])-4*pio2_1t;
112
941
        return 4;
113
941
    } else {
114
632
        z = x + 4*pio2_1;
115
632
        y[0] = z + 4*pio2_1t;
116
632
        y[1] = (z-y[0])+4*pio2_1t;
117
632
        return -4;
118
632
    }
119
1.57k
      }
120
3.65k
  }
121
10.7k
  if(ix<0x413921fb) { /* |x| ~< 2^20*(pi/2), medium size */
122
7.81k
medium:
123
7.81k
      fn = rnint((double_t)x*invpio2);
124
7.81k
      n  = irint(fn);
125
7.81k
      r  = x-fn*pio2_1;
126
7.81k
      w  = fn*pio2_1t;  /* 1st round good to 85 bit */
127
7.81k
      {
128
7.81k
          u_int32_t high;
129
7.81k
          j  = ix>>20;
130
7.81k
          y[0] = r-w; 
131
7.81k
    GET_HIGH_WORD(high,y[0]);
132
7.81k
          i = j-((high>>20)&0x7ff);
133
7.81k
          if(i>16) {  /* 2nd iteration needed, good to 118 */
134
951
        t  = r;
135
951
        w  = fn*pio2_2; 
136
951
        r  = t-w;
137
951
        w  = fn*pio2_2t-((t-r)-w);  
138
951
        y[0] = r-w;
139
951
        GET_HIGH_WORD(high,y[0]);
140
951
        i = j-((high>>20)&0x7ff);
141
951
        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
951
    }
149
7.81k
      }
150
7.81k
      y[1] = (r-y[0])-w;
151
7.81k
      return n;
152
7.81k
  }
153
    /* 
154
     * all other (large) arguments
155
     */
156
2.98k
  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.98k
  GET_LOW_WORD(low,x);
161
2.98k
  e0  = (ix>>20)-1046;  /* e0 = ilogb(z)-23; */
162
2.98k
  INSERT_WORDS(z, ix - ((int32_t)((u_int32_t)e0<<20)), low);
163
8.96k
  for(i=0;i<2;i++) {
164
5.97k
    tx[i] = (double)((int32_t)(z));
165
5.97k
    z     = (z-tx[i])*two24;
166
5.97k
  }
167
2.98k
  tx[2] = z;
168
2.98k
  nx = 3;
169
6.31k
  while(tx[nx-1]==zero) nx--; /* skip zero term */
170
2.98k
  n  =  __kernel_rem_pio2(tx,ty,e0,nx,1);
171
2.98k
  if(hx<0) {y[0] = -ty[0]; y[1] = -ty[1]; return -n;}
172
2.09k
  y[0] = ty[0]; y[1] = ty[1]; return n;
173
2.98k
}
Unexecuted instantiation: __ieee754_rem_pio2
s_cos.c:__ieee754_rem_pio2
Line
Count
Source
49
113k
{
50
113k
  double z,w,t,r,fn;
51
113k
  double tx[3],ty[2];
52
113k
  int32_t e0,i,j,nx,n,ix,hx;
53
113k
  u_int32_t low;
54
55
113k
  GET_HIGH_WORD(hx,x);   /* high word of x */
56
113k
  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
113k
  if (ix <= 0x400f6a7a) {   /* |x| ~<= 5pi/4 */
62
103k
      if ((ix & 0xfffff) == 0x921fb)  /* |x| ~= pi/2 or 2pi/2 */
63
0
    goto medium;   /* cancellation -- use medium case */
64
103k
      if (ix <= 0x4002d97c) { /* |x| ~<= 3pi/4 */
65
102k
    if (hx > 0) {
66
102k
        z = x - pio2_1; /* one round good to 85 bits */
67
102k
        y[0] = z - pio2_1t;
68
102k
        y[1] = (z-y[0])-pio2_1t;
69
102k
        return 1;
70
102k
    } else {
71
731
        z = x + pio2_1;
72
731
        y[0] = z + pio2_1t;
73
731
        y[1] = (z-y[0])+pio2_1t;
74
731
        return -1;
75
731
    }
76
102k
      } else {
77
909
    if (hx > 0) {
78
416
        z = x - 2*pio2_1;
79
416
        y[0] = z - 2*pio2_1t;
80
416
        y[1] = (z-y[0])-2*pio2_1t;
81
416
        return 2;
82
493
    } else {
83
493
        z = x + 2*pio2_1;
84
493
        y[0] = z + 2*pio2_1t;
85
493
        y[1] = (z-y[0])+2*pio2_1t;
86
493
        return -2;
87
493
    }
88
909
      }
89
103k
  }
90
9.29k
  if (ix <= 0x401c463b) {   /* |x| ~<= 9pi/4 */
91
1.67k
      if (ix <= 0x4015fdbc) { /* |x| ~<= 7pi/4 */
92
981
    if (ix == 0x4012d97c)  /* |x| ~= 3pi/2 */
93
0
        goto medium;
94
981
    if (hx > 0) {
95
379
        z = x - 3*pio2_1;
96
379
        y[0] = z - 3*pio2_1t;
97
379
        y[1] = (z-y[0])-3*pio2_1t;
98
379
        return 3;
99
602
    } else {
100
602
        z = x + 3*pio2_1;
101
602
        y[0] = z + 3*pio2_1t;
102
602
        y[1] = (z-y[0])+3*pio2_1t;
103
602
        return -3;
104
602
    }
105
981
      } else {
106
696
    if (ix == 0x401921fb)  /* |x| ~= 4pi/2 */
107
0
        goto medium;
108
696
    if (hx > 0) {
109
218
        z = x - 4*pio2_1;
110
218
        y[0] = z - 4*pio2_1t;
111
218
        y[1] = (z-y[0])-4*pio2_1t;
112
218
        return 4;
113
478
    } else {
114
478
        z = x + 4*pio2_1;
115
478
        y[0] = z + 4*pio2_1t;
116
478
        y[1] = (z-y[0])+4*pio2_1t;
117
478
        return -4;
118
478
    }
119
696
      }
120
1.67k
  }
121
7.61k
  if(ix<0x413921fb) { /* |x| ~< 2^20*(pi/2), medium size */
122
6.59k
medium:
123
6.59k
      fn = rnint((double_t)x*invpio2);
124
6.59k
      n  = irint(fn);
125
6.59k
      r  = x-fn*pio2_1;
126
6.59k
      w  = fn*pio2_1t;  /* 1st round good to 85 bit */
127
6.59k
      {
128
6.59k
          u_int32_t high;
129
6.59k
          j  = ix>>20;
130
6.59k
          y[0] = r-w; 
131
6.59k
    GET_HIGH_WORD(high,y[0]);
132
6.59k
          i = j-((high>>20)&0x7ff);
133
6.59k
          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.59k
      }
150
6.59k
      y[1] = (r-y[0])-w;
151
6.59k
      return n;
152
6.59k
  }
153
    /* 
154
     * all other (large) arguments
155
     */
156
1.02k
  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.02k
  GET_LOW_WORD(low,x);
161
1.02k
  e0  = (ix>>20)-1046;  /* e0 = ilogb(z)-23; */
162
1.02k
  INSERT_WORDS(z, ix - ((int32_t)((u_int32_t)e0<<20)), low);
163
3.07k
  for(i=0;i<2;i++) {
164
2.05k
    tx[i] = (double)((int32_t)(z));
165
2.05k
    z     = (z-tx[i])*two24;
166
2.05k
  }
167
1.02k
  tx[2] = z;
168
1.02k
  nx = 3;
169
1.88k
  while(tx[nx-1]==zero) nx--; /* skip zero term */
170
1.02k
  n  =  __kernel_rem_pio2(tx,ty,e0,nx,1);
171
1.02k
  if(hx<0) {y[0] = -ty[0]; y[1] = -ty[1]; return -n;}
172
884
  y[0] = ty[0]; y[1] = ty[1]; return n;
173
1.02k
}
s_sin.c:__ieee754_rem_pio2
Line
Count
Source
49
5.51k
{
50
5.51k
  double z,w,t,r,fn;
51
5.51k
  double tx[3],ty[2];
52
5.51k
  int32_t e0,i,j,nx,n,ix,hx;
53
5.51k
  u_int32_t low;
54
55
5.51k
  GET_HIGH_WORD(hx,x);   /* high word of x */
56
5.51k
  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.51k
  if (ix <= 0x400f6a7a) {   /* |x| ~<= 5pi/4 */
62
3.02k
      if ((ix & 0xfffff) == 0x921fb)  /* |x| ~= pi/2 or 2pi/2 */
63
0
    goto medium;   /* cancellation -- use medium case */
64
3.02k
      if (ix <= 0x4002d97c) { /* |x| ~<= 3pi/4 */
65
1.60k
    if (hx > 0) {
66
884
        z = x - pio2_1; /* one round good to 85 bits */
67
884
        y[0] = z - pio2_1t;
68
884
        y[1] = (z-y[0])-pio2_1t;
69
884
        return 1;
70
884
    } else {
71
717
        z = x + pio2_1;
72
717
        y[0] = z + pio2_1t;
73
717
        y[1] = (z-y[0])+pio2_1t;
74
717
        return -1;
75
717
    }
76
1.60k
      } else {
77
1.42k
    if (hx > 0) {
78
1.00k
        z = x - 2*pio2_1;
79
1.00k
        y[0] = z - 2*pio2_1t;
80
1.00k
        y[1] = (z-y[0])-2*pio2_1t;
81
1.00k
        return 2;
82
1.00k
    } else {
83
420
        z = x + 2*pio2_1;
84
420
        y[0] = z + 2*pio2_1t;
85
420
        y[1] = (z-y[0])+2*pio2_1t;
86
420
        return -2;
87
420
    }
88
1.42k
      }
89
3.02k
  }
90
2.48k
  if (ix <= 0x401c463b) {   /* |x| ~<= 9pi/4 */
91
1.51k
      if (ix <= 0x4015fdbc) { /* |x| ~<= 7pi/4 */
92
873
    if (ix == 0x4012d97c)  /* |x| ~= 3pi/2 */
93
0
        goto medium;
94
873
    if (hx > 0) {
95
473
        z = x - 3*pio2_1;
96
473
        y[0] = z - 3*pio2_1t;
97
473
        y[1] = (z-y[0])-3*pio2_1t;
98
473
        return 3;
99
473
    } else {
100
400
        z = x + 3*pio2_1;
101
400
        y[0] = z + 3*pio2_1t;
102
400
        y[1] = (z-y[0])+3*pio2_1t;
103
400
        return -3;
104
400
    }
105
873
      } else {
106
646
    if (ix == 0x401921fb)  /* |x| ~= 4pi/2 */
107
0
        goto medium;
108
646
    if (hx > 0) {
109
571
        z = x - 4*pio2_1;
110
571
        y[0] = z - 4*pio2_1t;
111
571
        y[1] = (z-y[0])-4*pio2_1t;
112
571
        return 4;
113
571
    } else {
114
75
        z = x + 4*pio2_1;
115
75
        y[0] = z + 4*pio2_1t;
116
75
        y[1] = (z-y[0])+4*pio2_1t;
117
75
        return -4;
118
75
    }
119
646
      }
120
1.51k
  }
121
970
  if(ix<0x413921fb) { /* |x| ~< 2^20*(pi/2), medium size */
122
207
medium:
123
207
      fn = rnint((double_t)x*invpio2);
124
207
      n  = irint(fn);
125
207
      r  = x-fn*pio2_1;
126
207
      w  = fn*pio2_1t;  /* 1st round good to 85 bit */
127
207
      {
128
207
          u_int32_t high;
129
207
          j  = ix>>20;
130
207
          y[0] = r-w; 
131
207
    GET_HIGH_WORD(high,y[0]);
132
207
          i = j-((high>>20)&0x7ff);
133
207
          if(i>16) {  /* 2nd iteration needed, good to 118 */
134
202
        t  = r;
135
202
        w  = fn*pio2_2; 
136
202
        r  = t-w;
137
202
        w  = fn*pio2_2t-((t-r)-w);  
138
202
        y[0] = r-w;
139
202
        GET_HIGH_WORD(high,y[0]);
140
202
        i = j-((high>>20)&0x7ff);
141
202
        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
202
    }
149
207
      }
150
207
      y[1] = (r-y[0])-w;
151
207
      return n;
152
207
  }
153
    /* 
154
     * all other (large) arguments
155
     */
156
763
  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
763
  GET_LOW_WORD(low,x);
161
763
  e0  = (ix>>20)-1046;  /* e0 = ilogb(z)-23; */
162
763
  INSERT_WORDS(z, ix - ((int32_t)((u_int32_t)e0<<20)), low);
163
2.28k
  for(i=0;i<2;i++) {
164
1.52k
    tx[i] = (double)((int32_t)(z));
165
1.52k
    z     = (z-tx[i])*two24;
166
1.52k
  }
167
763
  tx[2] = z;
168
763
  nx = 3;
169
2.21k
  while(tx[nx-1]==zero) nx--; /* skip zero term */
170
763
  n  =  __kernel_rem_pio2(tx,ty,e0,nx,1);
171
763
  if(hx<0) {y[0] = -ty[0]; y[1] = -ty[1]; return -n;}
172
741
  y[0] = ty[0]; y[1] = ty[1]; return n;
173
763
}
s_tan.c:__ieee754_rem_pio2
Line
Count
Source
49
3.50k
{
50
3.50k
  double z,w,t,r,fn;
51
3.50k
  double tx[3],ty[2];
52
3.50k
  int32_t e0,i,j,nx,n,ix,hx;
53
3.50k
  u_int32_t low;
54
55
3.50k
  GET_HIGH_WORD(hx,x);   /* high word of x */
56
3.50k
  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
3.50k
  if (ix <= 0x400f6a7a) {   /* |x| ~<= 5pi/4 */
62
828
      if ((ix & 0xfffff) == 0x921fb)  /* |x| ~= pi/2 or 2pi/2 */
63
0
    goto medium;   /* cancellation -- use medium case */
64
828
      if (ix <= 0x4002d97c) { /* |x| ~<= 3pi/4 */
65
674
    if (hx > 0) {
66
447
        z = x - pio2_1; /* one round good to 85 bits */
67
447
        y[0] = z - pio2_1t;
68
447
        y[1] = (z-y[0])-pio2_1t;
69
447
        return 1;
70
447
    } else {
71
227
        z = x + pio2_1;
72
227
        y[0] = z + pio2_1t;
73
227
        y[1] = (z-y[0])+pio2_1t;
74
227
        return -1;
75
227
    }
76
674
      } else {
77
154
    if (hx > 0) {
78
80
        z = x - 2*pio2_1;
79
80
        y[0] = z - 2*pio2_1t;
80
80
        y[1] = (z-y[0])-2*pio2_1t;
81
80
        return 2;
82
80
    } 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
154
      }
89
828
  }
90
2.67k
  if (ix <= 0x401c463b) {   /* |x| ~<= 9pi/4 */
91
462
      if (ix <= 0x4015fdbc) { /* |x| ~<= 7pi/4 */
92
231
    if (ix == 0x4012d97c)  /* |x| ~= 3pi/2 */
93
0
        goto medium;
94
231
    if (hx > 0) {
95
150
        z = x - 3*pio2_1;
96
150
        y[0] = z - 3*pio2_1t;
97
150
        y[1] = (z-y[0])-3*pio2_1t;
98
150
        return 3;
99
150
    } else {
100
81
        z = x + 3*pio2_1;
101
81
        y[0] = z + 3*pio2_1t;
102
81
        y[1] = (z-y[0])+3*pio2_1t;
103
81
        return -3;
104
81
    }
105
231
      } else {
106
231
    if (ix == 0x401921fb)  /* |x| ~= 4pi/2 */
107
0
        goto medium;
108
231
    if (hx > 0) {
109
152
        z = x - 4*pio2_1;
110
152
        y[0] = z - 4*pio2_1t;
111
152
        y[1] = (z-y[0])-4*pio2_1t;
112
152
        return 4;
113
152
    } else {
114
79
        z = x + 4*pio2_1;
115
79
        y[0] = z + 4*pio2_1t;
116
79
        y[1] = (z-y[0])+4*pio2_1t;
117
79
        return -4;
118
79
    }
119
231
      }
120
462
  }
121
2.21k
  if(ix<0x413921fb) { /* |x| ~< 2^20*(pi/2), medium size */
122
1.01k
medium:
123
1.01k
      fn = rnint((double_t)x*invpio2);
124
1.01k
      n  = irint(fn);
125
1.01k
      r  = x-fn*pio2_1;
126
1.01k
      w  = fn*pio2_1t;  /* 1st round good to 85 bit */
127
1.01k
      {
128
1.01k
          u_int32_t high;
129
1.01k
          j  = ix>>20;
130
1.01k
          y[0] = r-w; 
131
1.01k
    GET_HIGH_WORD(high,y[0]);
132
1.01k
          i = j-((high>>20)&0x7ff);
133
1.01k
          if(i>16) {  /* 2nd iteration needed, good to 118 */
134
521
        t  = r;
135
521
        w  = fn*pio2_2; 
136
521
        r  = t-w;
137
521
        w  = fn*pio2_2t-((t-r)-w);  
138
521
        y[0] = r-w;
139
521
        GET_HIGH_WORD(high,y[0]);
140
521
        i = j-((high>>20)&0x7ff);
141
521
        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
521
    }
149
1.01k
      }
150
1.01k
      y[1] = (r-y[0])-w;
151
1.01k
      return n;
152
1.01k
  }
153
    /* 
154
     * all other (large) arguments
155
     */
156
1.20k
  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.20k
  GET_LOW_WORD(low,x);
161
1.20k
  e0  = (ix>>20)-1046;  /* e0 = ilogb(z)-23; */
162
1.20k
  INSERT_WORDS(z, ix - ((int32_t)((u_int32_t)e0<<20)), low);
163
3.60k
  for(i=0;i<2;i++) {
164
2.40k
    tx[i] = (double)((int32_t)(z));
165
2.40k
    z     = (z-tx[i])*two24;
166
2.40k
  }
167
1.20k
  tx[2] = z;
168
1.20k
  nx = 3;
169
2.21k
  while(tx[nx-1]==zero) nx--; /* skip zero term */
170
1.20k
  n  =  __kernel_rem_pio2(tx,ty,e0,nx,1);
171
1.20k
  if(hx<0) {y[0] = -ty[0]; y[1] = -ty[1]; return -n;}
172
474
  y[0] = ty[0]; y[1] = ty[1]; return n;
173
1.20k
}