intervals 0.3.56

Sign up to get free protection for your applications and to get access to all the features.
Files changed (131) hide show
  1. data/VERSION.txt +1 -0
  2. data/ext/crlibm/AUTHORS +2 -0
  3. data/ext/crlibm/COPYING +504 -0
  4. data/ext/crlibm/ChangeLog +80 -0
  5. data/ext/crlibm/INSTALL +182 -0
  6. data/ext/crlibm/Makefile.am +84 -0
  7. data/ext/crlibm/Makefile.in +530 -0
  8. data/ext/crlibm/NEWS +0 -0
  9. data/ext/crlibm/README +31 -0
  10. data/ext/crlibm/TODO +47 -0
  11. data/ext/crlibm/VERSION +1 -0
  12. data/ext/crlibm/aclocal.m4 +989 -0
  13. data/ext/crlibm/atan-itanium.c +846 -0
  14. data/ext/crlibm/atan-pentium.c +261 -0
  15. data/ext/crlibm/atan_accurate.c +244 -0
  16. data/ext/crlibm/atan_accurate.h +191 -0
  17. data/ext/crlibm/atan_fast.c +324 -0
  18. data/ext/crlibm/atan_fast.h +678 -0
  19. data/ext/crlibm/config.guess +1461 -0
  20. data/ext/crlibm/config.sub +1566 -0
  21. data/ext/crlibm/configure +7517 -0
  22. data/ext/crlibm/configure.ac +364 -0
  23. data/ext/crlibm/crlibm.h +125 -0
  24. data/ext/crlibm/crlibm_config.h +149 -0
  25. data/ext/crlibm/crlibm_config.h.in +148 -0
  26. data/ext/crlibm/crlibm_private.c +293 -0
  27. data/ext/crlibm/crlibm_private.h +658 -0
  28. data/ext/crlibm/csh_fast.c +631 -0
  29. data/ext/crlibm/csh_fast.h +771 -0
  30. data/ext/crlibm/double-extended.h +496 -0
  31. data/ext/crlibm/exp-td.c +962 -0
  32. data/ext/crlibm/exp-td.h +685 -0
  33. data/ext/crlibm/exp_accurate.c +197 -0
  34. data/ext/crlibm/exp_accurate.h +85 -0
  35. data/ext/crlibm/gappa/log-de-E0-logir0.gappa +106 -0
  36. data/ext/crlibm/gappa/log-de-E0.gappa +79 -0
  37. data/ext/crlibm/gappa/log-de.gappa +81 -0
  38. data/ext/crlibm/gappa/log-td-E0-logir0.gappa +126 -0
  39. data/ext/crlibm/gappa/log-td-E0.gappa +143 -0
  40. data/ext/crlibm/gappa/log-td-accurate-E0-logir0.gappa +230 -0
  41. data/ext/crlibm/gappa/log-td-accurate-E0.gappa +213 -0
  42. data/ext/crlibm/gappa/log-td-accurate.gappa +217 -0
  43. data/ext/crlibm/gappa/log-td.gappa +156 -0
  44. data/ext/crlibm/gappa/trigoSinCosCase3.gappa +204 -0
  45. data/ext/crlibm/gappa/trigoTanCase2.gappa +73 -0
  46. data/ext/crlibm/install-sh +269 -0
  47. data/ext/crlibm/log-de.c +431 -0
  48. data/ext/crlibm/log-de.h +732 -0
  49. data/ext/crlibm/log-td.c +852 -0
  50. data/ext/crlibm/log-td.h +819 -0
  51. data/ext/crlibm/log10-td.c +906 -0
  52. data/ext/crlibm/log10-td.h +823 -0
  53. data/ext/crlibm/log2-td.c +935 -0
  54. data/ext/crlibm/log2-td.h +821 -0
  55. data/ext/crlibm/maple/atan.mpl +359 -0
  56. data/ext/crlibm/maple/common-procedures.mpl +997 -0
  57. data/ext/crlibm/maple/csh.mpl +446 -0
  58. data/ext/crlibm/maple/double-extended.mpl +151 -0
  59. data/ext/crlibm/maple/exp-td.mpl +195 -0
  60. data/ext/crlibm/maple/log-de.mpl +243 -0
  61. data/ext/crlibm/maple/log-td.mpl +316 -0
  62. data/ext/crlibm/maple/log10-td.mpl +345 -0
  63. data/ext/crlibm/maple/log2-td.mpl +334 -0
  64. data/ext/crlibm/maple/trigo.mpl +728 -0
  65. data/ext/crlibm/maple/triple-double.mpl +58 -0
  66. data/ext/crlibm/missing +198 -0
  67. data/ext/crlibm/mkinstalldirs +40 -0
  68. data/ext/crlibm/rem_pio2_accurate.c +219 -0
  69. data/ext/crlibm/rem_pio2_accurate.h +53 -0
  70. data/ext/crlibm/scs_lib/AUTHORS +3 -0
  71. data/ext/crlibm/scs_lib/COPYING +504 -0
  72. data/ext/crlibm/scs_lib/ChangeLog +16 -0
  73. data/ext/crlibm/scs_lib/INSTALL +215 -0
  74. data/ext/crlibm/scs_lib/Makefile.am +18 -0
  75. data/ext/crlibm/scs_lib/Makefile.in +328 -0
  76. data/ext/crlibm/scs_lib/NEWS +0 -0
  77. data/ext/crlibm/scs_lib/README +9 -0
  78. data/ext/crlibm/scs_lib/TODO +4 -0
  79. data/ext/crlibm/scs_lib/addition_scs.c +623 -0
  80. data/ext/crlibm/scs_lib/config.guess +1461 -0
  81. data/ext/crlibm/scs_lib/config.sub +1566 -0
  82. data/ext/crlibm/scs_lib/configure +6226 -0
  83. data/ext/crlibm/scs_lib/division_scs.c +110 -0
  84. data/ext/crlibm/scs_lib/double2scs.c +174 -0
  85. data/ext/crlibm/scs_lib/install-sh +269 -0
  86. data/ext/crlibm/scs_lib/missing +198 -0
  87. data/ext/crlibm/scs_lib/mkinstalldirs +40 -0
  88. data/ext/crlibm/scs_lib/multiplication_scs.c +456 -0
  89. data/ext/crlibm/scs_lib/poly_fct.c +112 -0
  90. data/ext/crlibm/scs_lib/print_scs.c +73 -0
  91. data/ext/crlibm/scs_lib/rand_scs.c +63 -0
  92. data/ext/crlibm/scs_lib/scs.h +353 -0
  93. data/ext/crlibm/scs_lib/scs2double.c +391 -0
  94. data/ext/crlibm/scs_lib/scs2mpf.c +58 -0
  95. data/ext/crlibm/scs_lib/scs2mpfr.c +61 -0
  96. data/ext/crlibm/scs_lib/scs_private.c +23 -0
  97. data/ext/crlibm/scs_lib/scs_private.h +133 -0
  98. data/ext/crlibm/scs_lib/tests/tbx_timing.h +102 -0
  99. data/ext/crlibm/scs_lib/wrapper_scs.h +486 -0
  100. data/ext/crlibm/scs_lib/zero_scs.c +52 -0
  101. data/ext/crlibm/stamp-h.in +1 -0
  102. data/ext/crlibm/tests/Makefile.am +43 -0
  103. data/ext/crlibm/tests/Makefile.in +396 -0
  104. data/ext/crlibm/tests/blind_test.c +148 -0
  105. data/ext/crlibm/tests/generate_test_vectors.c +258 -0
  106. data/ext/crlibm/tests/soak_test.c +334 -0
  107. data/ext/crlibm/tests/test_common.c +627 -0
  108. data/ext/crlibm/tests/test_common.h +28 -0
  109. data/ext/crlibm/tests/test_perf.c +570 -0
  110. data/ext/crlibm/tests/test_val.c +249 -0
  111. data/ext/crlibm/trigo_accurate.c +500 -0
  112. data/ext/crlibm/trigo_accurate.h +331 -0
  113. data/ext/crlibm/trigo_fast.c +1219 -0
  114. data/ext/crlibm/trigo_fast.h +639 -0
  115. data/ext/crlibm/triple-double.h +878 -0
  116. data/ext/extconf.rb +31 -0
  117. data/ext/fpu.c +107 -0
  118. data/ext/jamis-mod.rb +591 -0
  119. data/lib/fpu.rb +287 -0
  120. data/lib/interval.rb +1170 -0
  121. data/lib/intervals.rb +212 -0
  122. data/lib/struct_float.rb +133 -0
  123. data/test/data_atan.txt +360 -0
  124. data/test/data_cos.txt +346 -0
  125. data/test/data_cosh.txt +3322 -0
  126. data/test/data_exp.txt +3322 -0
  127. data/test/data_log.txt +141 -0
  128. data/test/data_sin.txt +140 -0
  129. data/test/data_sinh.txt +3322 -0
  130. data/test/data_tan.txt +342 -0
  131. metadata +186 -0
@@ -0,0 +1,261 @@
1
+ /*
2
+ *this function computes atan correctly rounded to the nearest,
3
+ using experimental techniques based on double-extended arithmetic
4
+
5
+ THIS IS EXPERIMENTAL SOFTWARE
6
+
7
+ In particular it changes rounding modes all the time without warning
8
+ nor restoring.
9
+
10
+ *
11
+ * Author : Nicolas Gast, Florent de Dinechin
12
+ * nicolas.gast@ens.fr
13
+ *
14
+
15
+ To have it replace the crlibm atan, do:
16
+ gcc -DHAVE_CONFIG_H -I. -fPIC -O2 -c atan-pentium.c; mv atan-pentium.o atan_fast.o; make
17
+
18
+ */
19
+
20
+
21
+ #include <stdio.h>
22
+ #include <stdlib.h>
23
+ #include <crlibm.h>
24
+ #include <crlibm_private.h>
25
+ #include "double-extended.h"
26
+
27
+ #define debug 1 /*Warning : turning debugging on seems to change the final result */
28
+ #define DEBUG 0
29
+ #define NICOLASTEST 0
30
+
31
+ #ifdef HAVE_FENV_H
32
+ #include <fenv.h>
33
+ #endif
34
+
35
+
36
+ /* The following seems perfectly harmless */
37
+
38
+ #ifdef FENV_H
39
+ #pragma STDC FENV_ACCESS ON
40
+ #endif
41
+
42
+ #include "atan-pentium.h"
43
+ #include <fpu_control.h>
44
+
45
+
46
+
47
+ /* Dummy functions to compile OK */
48
+ extern double atan_rd(double x) {return 0;}
49
+ extern double atan_ru(double x) {return 0;}
50
+ extern double atan_rz(double x) {return 0;}
51
+
52
+
53
+ extern double atan_rn(double x) {
54
+ db_number x_db;
55
+ unsigned int hx;
56
+ double sign;
57
+ double u;
58
+ double comp;
59
+ double atanhi, atanlo, atanlo_u;
60
+
61
+ long double Xred;
62
+ long double Xred2;
63
+ long double q;
64
+ long double atan;
65
+ long double eps;
66
+ int i;
67
+
68
+ if(x>=0)
69
+ sign = 1;
70
+ else
71
+ {sign = -1;
72
+ x=-x;}
73
+
74
+ x_db.d = x;
75
+ hx = x_db.i[HI] & 0x7FFFFFFF;
76
+
77
+ /* Filter cases */
78
+ if ( hx >= 0x43500000) /* x >= 2^54 */
79
+ {
80
+ if ( (x_db.i[LO] == 0) && (hx & 0x000fffff) == 0x00080000)
81
+ return x+x; /* NaN */
82
+ else
83
+ return sign*HALFPI.d; /* atan(x) = Pi/2 */
84
+ }
85
+ else
86
+ if ( hx < 0x3E400000 )
87
+ {return sign*x;} /* x<2^-27 then atan(x) =~ x */
88
+
89
+ DOUBLE_EXTENDED_MODE;
90
+
91
+
92
+ if (x > MIN_REDUCTION_NEEDED) /* test if reduction is necessary : */
93
+ {
94
+ /* 1) Argument reduction : */
95
+
96
+ /* compute i so that a[i] < x < a[i+1] */
97
+ if (x>arctan_table[61][A])
98
+ i=61;
99
+ else {
100
+ i=31;
101
+ if (x < arctan_table[i][A]) i-= 16;
102
+ else i+=16;
103
+ if (x < arctan_table[i][A]) i-= 8;
104
+ else i+= 8;
105
+ if (x < arctan_table[i][A]) i-= 4;
106
+ else i+= 4;
107
+ if (x < arctan_table[i][A]) i-= 2;
108
+ else i+= 2;
109
+ if (x < arctan_table[i][A]) i-= 1;
110
+ else i+= 1;
111
+ if (x < arctan_table[i][A]) i-= 1;
112
+ }
113
+ Xred = (x - arctan_table[i][B] )/(1.0L + x * arctan_table[i][B] );
114
+
115
+ Xred2 = Xred*Xred;
116
+ /* Polynomial evaluation */
117
+ q = Xred2*(coef_poly[0][0]+Xred2*
118
+ (coef_poly[1][0]+Xred2*
119
+ (coef_poly[2][0]+Xred2*
120
+ (coef_poly[3][0]))));
121
+
122
+ /* reconstruction : atan(x) = atan(b[i]) + atan(x) */
123
+ atan = arctan_table[i][ATAN_BHI] + (Xred + q*Xred);
124
+
125
+
126
+ atanhi = (double) atan;
127
+ atanlo = atan-atanhi;
128
+
129
+
130
+ }
131
+ else
132
+
133
+ // no reduction needed
134
+ {
135
+
136
+ Xred2 = x*x;
137
+
138
+ /* Polynomial evaluation */
139
+ q = Xred2*(coef_poly[0][0]+Xred2*
140
+ (coef_poly[1][0]+Xred2*
141
+ (coef_poly[2][0]+Xred2*
142
+ (coef_poly[3][0]))));
143
+
144
+ atan = q*x + x;
145
+
146
+ }
147
+
148
+ TEST_AND_RETURN_RN2(atan, sign*atan, 0x7fe);
149
+ /* or :
150
+ TEST_AND_RETURN_RN_ZIV(sign*atan, 1.003);
151
+ */
152
+ {
153
+
154
+ /*Second step, double-double */
155
+ long double tmphi, tmplo;
156
+ long double x0hi, x0lo;
157
+ long double xmBihi, xmBilo;
158
+ long double Xredhi, Xredlo;
159
+ long double Xred2;
160
+ long double qhi,qlo; /* q = polynomial */
161
+ long double q;
162
+ long double Xred2hi,Xred2lo;
163
+ long double atanhi,atanlo;
164
+ int j;
165
+
166
+ #if EVAL_PERF
167
+ crlibm_second_step_taken++;
168
+ #endif
169
+
170
+ if (x > MIN_REDUCTION_NEEDED) /* test if reduction is necessary : */
171
+ {
172
+ /* 1) Argument reduction : */
173
+
174
+ if (i==61)
175
+ {
176
+ Add12_ext( xmBihi , xmBilo , x , -arctan_table[61][B]);
177
+ }
178
+ else
179
+ {
180
+ xmBihi = x-arctan_table[i][B];
181
+ xmBilo = 0.0;
182
+ }
183
+
184
+ Mul12_ext(&tmphi,&tmplo, x, arctan_table[i][B]);
185
+
186
+ if (x > 1)
187
+ Add22_ext(&x0hi,&x0lo,tmphi,tmplo, 1.0,0.0);
188
+ else {Add22_ext( &x0hi , &x0lo , 1.0,0.0,tmphi,tmplo);}
189
+
190
+ Div22_ext( Xredhi, Xredlo, xmBihi , xmBilo , x0hi,x0lo);
191
+
192
+ Xred2 = Xredhi*Xredhi;
193
+ Mul22_ext( &Xred2hi,&Xred2lo,Xredhi,Xredlo,Xredhi, Xredlo);
194
+
195
+ /*poly eval */
196
+
197
+ q = (coef_poly[4][0]+Xred2*
198
+ (coef_poly[5][0]+Xred2*
199
+ (coef_poly[6][0]+Xred2*
200
+ (coef_poly[7][0]+
201
+ (Xred2*coef_poly[8][0])))));
202
+
203
+ Mul12_ext( &qhi, &qlo, q, Xred2);
204
+
205
+ for(j=3;j>=0;j--)
206
+ {
207
+ Add22_ext(&qhi,&qlo, coef_poly[j][0], coef_poly[j][1], qhi,qlo);
208
+ Mul22_ext(&qhi,&qlo, qhi,qlo, Xred2hi,Xred2lo);
209
+ }
210
+
211
+ Mul22_ext(&qhi,&qlo, Xredhi,Xredlo, qhi,qlo);
212
+ Add22_ext(&qhi,&qlo, Xredhi,Xredlo, qhi,qlo);
213
+
214
+ /* reconstruction : atan(x) = atan(b[i]) + atan(x) */
215
+ Add22_ext(&atanhi,&atanlo, arctan_table[i][ATAN_BHI], arctan_table[i][ATAN_BLO], qhi,qlo);
216
+ }
217
+ else
218
+
219
+ // no reduction needed
220
+ {
221
+ /* Polynomial evaluation */
222
+ Mul12_ext( &Xred2hi,&Xred2lo,x,x);
223
+
224
+ /*poly eval */
225
+ q = Xred2hi*(coef_poly[5][0]+Xred2hi*
226
+ (coef_poly[6][0]+Xred2hi*
227
+ (coef_poly[7][0]+Xred2hi*
228
+ (coef_poly[8][0]))));
229
+
230
+ Add12_ext(qhi,qlo, coef_poly[4][0],q);
231
+ #if debug
232
+ printf(" xred2 = %1.50Le + %1.50Le\n", Xred2hi, Xred2lo);
233
+ printf(" qhi+qlo0= %1.50Le + %1.50Le\n",qhi, qlo);
234
+ #endif
235
+ Mul22_ext(&qhi,&qlo, qhi,qlo, Xred2hi,Xred2lo);
236
+
237
+ for(j=3;j>=0;j--)
238
+ {
239
+ Add22_ext(&qhi,&qlo, coef_poly[j][0], coef_poly[j][1], qhi,qlo);
240
+ Mul22_ext(&qhi,&qlo, qhi,qlo, Xred2hi,Xred2lo);
241
+ }
242
+
243
+ Mul22_ext (&qhi,&qlo, x,0, qhi,qlo);
244
+
245
+ #if debug
246
+ printf(" qhi+qlo = %1.50Le + %1.50Le\n",qhi, qlo);
247
+ #endif
248
+
249
+ /* The sequence in the TOMS paper */
250
+ Add12_ext (atanhi,atanlo,x,qhi);
251
+ atanlo += qlo;
252
+ }
253
+ #if debug
254
+ printf(" %1.50Le + %1.50Le\n",atanhi, atanlo);
255
+ printf(" %1.50Le\n",atanhi + atanlo);
256
+ #endif
257
+
258
+ BACK_TO_DOUBLE_MODE;
259
+ return sign*((double) (atanhi+atanlo));
260
+ }
261
+ }
@@ -0,0 +1,244 @@
1
+ /*
2
+ * Correctly rounded arctangent
3
+ *
4
+ * Author : Nicolas Gast (Ecole Normale Superieure), Florent de Dinechin
5
+ *
6
+ * This file is part of the crlibm library developed by the Arenaire
7
+ * project at Ecole Normale Superieure de Lyon
8
+ *
9
+ * This program is free software; you can redistribute it and/or modify
10
+ * it under the terms of the GNU Lesser General Public License as published by
11
+ * the Free Software Foundation; either version 2 of the License, or
12
+ * (at your option) any later version.
13
+ *
14
+ * This program is distributed in the hope that it will be useful,
15
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
16
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17
+ * GNU General Public License for more details.
18
+ *
19
+ * You should have received a copy of the GNU Lesser General Public License
20
+ * along with this program; if not, write to the Free Software
21
+ * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
22
+ */
23
+ #include <stdio.h>
24
+ #include <stdlib.h>
25
+ #include "crlibm_private.h"
26
+ #include "atan_accurate.h"
27
+ #include "atan_fast.h"
28
+
29
+
30
+ /*
31
+ * WHAT WE CAN DO :
32
+ *
33
+ * 1) Range reduction
34
+ *
35
+ * x > 0 because atan(-x) = - atan(x)
36
+ *
37
+ * we have built 50 intervals I(i), associated to a b(i) so that :
38
+ *
39
+ * For every x :
40
+ *
41
+ * we find the interval I(i) , as atan(x) = atan(b(i)) + atan( (x - b(i)) / (1 + x * b(i)) )
42
+ *
43
+ * so that X = (x - b(i)) / (1 + x * b(i)) be in interval [ -2^(-6) , 2^(-6) ]
44
+ * There is no cancellation because :
45
+ * for every x in [ -2^(-6) , 2^(-6) ],
46
+ *
47
+ * atan(x) <= 0.01562372862 in binary 0.000001111111111
48
+ * AND for the smallest b(i) atan(b(i)) = 0.04687118592 in binary 0.00001011111111
49
+ *
50
+ *
51
+ * 2) Polynomial evaluation of atan(X), atan(b(i)) is tabulated.
52
+ *
53
+ * (-???)
54
+ * Approximation error: |err| < 2^
55
+ *
56
+ *
57
+ * 3) Reconstruction:
58
+ *
59
+ * atan(x) = atan(b(i)) + atan(X)
60
+ *
61
+ *
62
+ * 4) Rounding:
63
+ *
64
+ * when |x| is too big, the result is always sign(x) * Pi/2,
65
+ * because Pi/2 is appromated by the biggest value smallest than Pi/2,
66
+ * in order not to have an atan > Pi/2.
67
+ */
68
+
69
+
70
+
71
+
72
+ void scs_atan(scs_ptr res_scs, scs_ptr x){
73
+ scs_t X_scs, denom1_scs, denom2_scs, poly_scs, X2;
74
+ scs_t atanbhihi,atanbhilo, atanblo, atanbhi, atanb;
75
+ scs_t bsc_ptr;
76
+ db_number db;
77
+ double test;
78
+ int k, i=31;
79
+
80
+
81
+ scs_get_d(&db.d, x);
82
+
83
+ #if EVAL_PERF
84
+ crlibm_second_step_taken++;
85
+ #endif
86
+
87
+ /* test if x as to be reduced */
88
+ if (db.d > MIN_REDUCTION_NEEDED) {
89
+ /* Compute i so that x E [a[i],a[i+1]] */
90
+ if (db.d < arctan_table[i][A].d) i-= 16;
91
+ else i+=16;
92
+ if (db.d < arctan_table[i][A].d) i-= 8;
93
+ else i+= 8;
94
+ if (db.d < arctan_table[i][A].d) i-= 4;
95
+ else i+= 4;
96
+ if (db.d < arctan_table[i][A].d) i-= 2;
97
+ else i+= 2;
98
+ if (db.d < arctan_table[i][A].d) i-= 1;
99
+ else if (i<61) i+= 1;
100
+ if (db.d < arctan_table[i][A].d) i-= 1;
101
+
102
+ /* evaluate X = (x - b(i)) / (1 + x*b(i)) */
103
+ scs_set_d(bsc_ptr, arctan_table[i][B].d);
104
+
105
+ scs_mul(denom1_scs,bsc_ptr,x);
106
+ scs_add(denom2_scs,denom1_scs,SCS_ONE);
107
+ scs_sub(X_scs,x,bsc_ptr);
108
+ scs_div(X_scs,X_scs,denom2_scs);
109
+
110
+ scs_get_d(&test,X_scs);
111
+
112
+ /* Polynomial evaluation of atan(X) , X = (x-b(i)) / (1+ x*b(i)) */
113
+ scs_square(X2, X_scs);
114
+ scs_set(res_scs, constant_poly_ptr[0]);
115
+ for(k=1; k < 10; k++) {
116
+ /* we use Horner expression */
117
+ scs_mul(res_scs, res_scs, X2);
118
+ scs_add(res_scs, constant_poly_ptr[k], res_scs);
119
+ }
120
+ scs_mul(poly_scs, res_scs, X_scs);
121
+
122
+ /* reconstruction : */
123
+
124
+ /* 1st we load atan ( b[i] ) in a scs*/
125
+ scs_set_d( atanbhihi , arctan_table[i][ATAN_BHI].d);
126
+ scs_set_d( atanbhilo , arctan_table[i][ATAN_BLO].d);
127
+ scs_set_d( atanblo , atan_blolo[i].d);
128
+ scs_add(atanbhi,atanbhihi,atanbhilo);
129
+ scs_add(atanb,atanbhi,atanblo);
130
+ scs_add(res_scs,atanb, poly_scs);
131
+ return;
132
+ }
133
+
134
+ else
135
+ { /* no reduction needed */
136
+
137
+ /* Polynomial evaluation of atan(x) */
138
+ scs_square(X2, x);
139
+ scs_set(res_scs, constant_poly_ptr[0]);
140
+ for(k=1; k < 10; k++) {
141
+ /* we use Horner expression */
142
+ scs_mul(res_scs, res_scs, X2);
143
+ scs_add(res_scs, constant_poly_ptr[k], res_scs);
144
+ }
145
+ scs_mul(res_scs, res_scs, x);
146
+ return;
147
+ }
148
+ }
149
+
150
+ /*************************************************************
151
+ *************************************************************
152
+ * ROUNDED TO NEAREST
153
+ *************************************************************
154
+ *************************************************************/
155
+
156
+ double scs_atan_rn(double x){
157
+ /* This function does NOT compute atan(x) correctly if it isn't
158
+ * called in atan_rn()
159
+ */
160
+ scs_t sc1;
161
+ scs_t res_scs;
162
+ db_number res;
163
+ int sign =1;
164
+
165
+ res.d = x;
166
+
167
+ if (x < 0){
168
+ sign = -1;
169
+ x *= -1;
170
+ }
171
+ scs_set_d(sc1, x);
172
+ scs_atan(res_scs, sc1);
173
+ scs_get_d(&res.d, res_scs);
174
+
175
+ res.d *= sign;
176
+
177
+ return res.d;
178
+ }
179
+
180
+ /*************************************************************
181
+ *************************************************************
182
+ * ROUNDED TOWARD -INFINITY
183
+ *************************************************************
184
+ *************************************************************/
185
+
186
+ double scs_atan_rd(double x){
187
+ scs_t sc1;
188
+ scs_t res_scs;
189
+ db_number res;
190
+ int sign = 1;
191
+
192
+ res.d = x;
193
+
194
+ /* Filter cases */
195
+ if (x < 0){
196
+ sign = -1;
197
+ x *= -1;
198
+ }
199
+ scs_set_d(sc1, x);
200
+ scs_atan(res_scs, sc1);
201
+ if (sign == -1){
202
+ scs_get_d_pinf(&res.d, res_scs);
203
+ res.d *= -1;
204
+ return res.d;
205
+ }
206
+ else{
207
+ scs_get_d_minf(&res.d, res_scs);
208
+ return res.d;
209
+ }
210
+ }
211
+
212
+ /*************************************************************
213
+ *************************************************************
214
+ * ROUNDED TOWARD +INFINITY
215
+ *************************************************************
216
+ *************************************************************/
217
+
218
+ double scs_atan_ru(double x){
219
+ scs_t sc1;
220
+ scs_t res_scs;
221
+ db_number res;
222
+ int sign = 1;
223
+
224
+ res.d = x;
225
+
226
+ /* Filter cases */
227
+ if (x < 0){
228
+ sign = -1;
229
+ x *= -1;
230
+ }
231
+
232
+ scs_set_d(sc1, x);
233
+ scs_atan(res_scs, sc1);
234
+ if (sign == -1){
235
+ scs_get_d_minf(&res.d, res_scs);
236
+ res.d *= -1;
237
+ return res.d;
238
+ }
239
+ else{
240
+ scs_get_d_pinf(&res.d, res_scs);
241
+ return res.d;
242
+ }
243
+ }
244
+
@@ -0,0 +1,191 @@
1
+ #include "crlibm.h"
2
+ #include "crlibm_private.h"
3
+ #include "atan_fast.h"
4
+
5
+ /*File generated by maple/coef_atan.mw */
6
+ static const scs constant_poly [10]=
7
+ /* ~-5.26315789473684210526315789473684210526315789473684e-02 */
8
+ {{{0x035e50d7, 0x250d7943, 0x179435e5, 0x035e50d7,
9
+ 0x250d7943, 0x179435e5, 0x035e50d7, 0x250d7943},
10
+ DB_ONE, -1, -1 }
11
+ ,
12
+ /* ~5.88235294117647058823529411764705882352941176470588e-02 */
13
+ {{0x03c3c3c3, 0x30f0f0f0, 0x3c3c3c3c, 0x0f0f0f0f,
14
+ 0x03c3c3c3, 0x30f0f0f0, 0x3c3c3c3c, 0x0f0f0f0f},
15
+ DB_ONE, -1, 1 }
16
+ ,
17
+ /* ~-6.66666666666666666666666666666666666666666666666667e-02 */
18
+ {{0x04444444, 0x11111111, 0x04444444, 0x11111111,
19
+ 0x04444444, 0x11111111, 0x04444444, 0x11111111},
20
+ DB_ONE, -1, -1 }
21
+ ,
22
+ /* ~7.69230769230769230769230769230769230769230769230769e-02 */
23
+ {{0x04ec4ec4, 0x3b13b13b, 0x04ec4ec4, 0x3b13b13b,
24
+ 0x04ec4ec4, 0x3b13b13b, 0x04ec4ec4, 0x3b13b13b},
25
+ DB_ONE, -1, 1 }
26
+ ,
27
+ /* ~-9.09090909090909090909090909090909090909090909090909e-02 */
28
+ {{0x05d1745d, 0x05d1745d, 0x05d1745d, 0x05d1745d,
29
+ 0x05d1745d, 0x05d1745d, 0x05d1745d, 0x05d1745d},
30
+ DB_ONE, -1, -1 }
31
+ ,
32
+ /* ~1.11111111111111111111111111111111111111111111111111e-01 */
33
+ {{0x071c71c7, 0x071c71c7, 0x071c71c7, 0x071c71c7,
34
+ 0x071c71c7, 0x071c71c7, 0x071c71c7, 0x071c71c7},
35
+ DB_ONE, -1, 1 }
36
+ ,
37
+ /* ~-1.42857142857142857142857142857142857142857142857143e-01 */
38
+ {{0x09249249, 0x09249249, 0x09249249, 0x09249249,
39
+ 0x09249249, 0x09249249, 0x09249249, 0x09249249},
40
+ DB_ONE, -1, -1 }
41
+ ,
42
+ /* ~2.00000000000000000000000000000000000000000000000000e-01 */
43
+ {{0x0ccccccc, 0x33333333, 0x0ccccccc, 0x33333333,
44
+ 0x0ccccccc, 0x33333333, 0x0ccccccc, 0x33333333},
45
+ DB_ONE, -1, 1 }
46
+ ,
47
+ /* ~-3.33333333333333333333333333333333333333333333333333e-01 */
48
+ {{0x15555555, 0x15555555, 0x15555555, 0x15555555,
49
+ 0x15555555, 0x15555555, 0x15555555, 0x15555555},
50
+ DB_ONE, -1, -1 }
51
+ ,
52
+ /* ~1.00000000000000000000000000000000000000000000000000e+00 */
53
+ {{0x00000001, 0x00000000, 0x00000000, 0x00000000,
54
+ 0x00000000, 0x00000000, 0x00000000, 0x00000000},
55
+ DB_ONE, 0, 1 }
56
+ };
57
+ #define constant_poly_ptr (scs_ptr)&constant_poly
58
+ #ifdef WORDS_BIGENDIAN
59
+
60
+ static const db_number atan_blolo[62] = {
61
+ /* 0 */ {{0xB8D1C5F3,0xA947CCE9}} /* -5.3484426395e-35 */,
62
+ /* 1 */ {{0xB8B05943,0x3C749846}} /* -1.2299381479e-35 */,
63
+ /* 2 */ {{0x38FC2F2A,0x267751FB}} /* +3.3925541143e-34 */,
64
+ /* 3 */ {{0x38D44E61,0xDDA4249D}} /* +6.1106690132e-35 */,
65
+ /* 4 */ {{0xB906FBFA,0xA5B245C8}} /* -5.5332673453e-34 */,
66
+ /* 5 */ {{0xB8DE1E98,0x67CABE65}} /* -9.0637612563e-35 */,
67
+ /* 6 */ {{0x38BD7B8F,0x45D13048}} /* +2.2180284354e-35 */,
68
+ /* 7 */ {{0xB9049436,0x23AD369B}} /* -4.9542022687e-34 */,
69
+ /* 8 */ {{0xB8F98586,0xF6BB1DB7}} /* -3.0720497269e-34 */,
70
+ /* 9 */ {{0xB89BC985,0xCB4D6219}} /* -5.2261910438e-36 */,
71
+ /* 10 */ {{0xB8C4002C,0x9C3884F4}} /* -3.0093679582e-35 */,
72
+ /* 11 */ {{0x3910CBC4,0x893058D9}} /* +8.0869642604e-34 */,
73
+ /* 12 */ {{0xB8F5408B,0xFF010BB5}} /* -2.5581328396e-34 */,
74
+ /* 13 */ {{0xB908570F,0xB5813578}} /* -5.8596619457e-34 */,
75
+ /* 14 */ {{0x39155B89,0x7E967248}} /* +1.0283294335e-33 */,
76
+ /* 15 */ {{0xB8CD159A,0x2031F115}} /* -4.3761315763e-35 */,
77
+ /* 16 */ {{0xB8E8D9C6,0x0FC3C81C}} /* -1.4956458040e-34 */,
78
+ /* 17 */ {{0x38C0AC30,0x8219F20D}} /* +2.5086163140e-35 */,
79
+ /* 18 */ {{0x38B36506,0x32EDCB95}} /* +1.4590894790e-35 */,
80
+ /* 19 */ {{0xB8FD57B0,0x5932E7C2}} /* -3.5319791285e-34 */,
81
+ /* 20 */ {{0x38C73827,0x91A2D916}} /* +3.4936600564e-35 */,
82
+ /* 21 */ {{0xB92FE60D,0x9EC5116C}} /* -3.0717278111e-33 */,
83
+ /* 22 */ {{0x3903AADF,0x6A3B8AE2}} /* +4.7347715466e-34 */,
84
+ /* 23 */ {{0xB88D6A01,0x71B87C3C}} /* -2.7660872166e-36 */,
85
+ /* 24 */ {{0xB8E17427,0xEA5AC8E8}} /* -1.0504584084e-34 */,
86
+ /* 25 */ {{0x38F4ED52,0xF776B005}} /* +2.5190016806e-34 */,
87
+ /* 26 */ {{0xB9265B23,0x75D2B05C}} /* -2.1528054385e-33 */,
88
+ /* 27 */ {{0xB8DA45DA,0xAFEAB282}} /* -7.9062036715e-35 */,
89
+ /* 28 */ {{0x3912EF75,0xBD16D3D4}} /* +9.1170587963e-34 */,
90
+ /* 29 */ {{0x390AB3D7,0xE904B022}} /* +6.4283962392e-34 */,
91
+ /* 30 */ {{0xB8EE688B,0x3F9F468B}} /* -1.8301374849e-34 */,
92
+ /* 31 */ {{0xB9225DF6,0x71A98823}} /* -1.7686817787e-33 */,
93
+ /* 32 */ {{0xB8CC82B0,0x522BE0F8}} /* -4.2897836993e-35 */,
94
+ /* 33 */ {{0xB912AFE0,0x88BB6A0B}} /* -8.9974727841e-34 */,
95
+ /* 34 */ {{0x38D4DC99,0x8640FAE5}} /* +6.2778447830e-35 */,
96
+ /* 35 */ {{0xB9016FC6,0x406A343B}} /* -4.1977132916e-34 */,
97
+ /* 36 */ {{0x3909804C,0x126FC74C}} /* +6.1391811422e-34 */,
98
+ /* 37 */ {{0x39051033,0xE5B0956F}} /* +5.0708030720e-34 */,
99
+ /* 38 */ {{0xB910CADC,0x203B114C}} /* -8.0852567814e-34 */,
100
+ /* 39 */ {{0x38EFCAC7,0xF97ED36B}} /* +1.9134182531e-34 */,
101
+ /* 40 */ {{0xB92464C0,0xB51D77B4}} /* -1.9638289218e-33 */,
102
+ /* 41 */ {{0x391157F3,0x2D4A03DE}} /* +8.3506176591e-34 */,
103
+ /* 42 */ {{0xB92BD929,0x136A8DDE}} /* -2.6816921082e-33 */,
104
+ /* 43 */ {{0x390F1514,0x035DF6B3}} /* +7.4828003563e-34 */,
105
+ /* 44 */ {{0xB92606EC,0x19DB7E3B}} /* -2.1211268072e-33 */,
106
+ /* 45 */ {{0x393B104B,0xCDA1B51D}} /* +5.2122706777e-33 */,
107
+ /* 46 */ {{0x3935FB01,0xF88A520C}} /* +4.2332900876e-33 */,
108
+ /* 47 */ {{0xB9189ED1,0x1940944D}} /* -1.1854280852e-33 */,
109
+ /* 48 */ {{0xB914E8F2,0x38D4794B}} /* -1.0067772791e-33 */,
110
+ /* 49 */ {{0xB93DF07A,0x73581CF5}} /* -5.7661126209e-33 */,
111
+ /* 50 */ {{0xB939C22F,0x727CE10C}} /* -4.9609136744e-33 */,
112
+ /* 51 */ {{0xB8EF37D2,0x26E1A810}} /* -1.8788680655e-34 */,
113
+ /* 52 */ {{0x391A4251,0x45155DAA}} /* +1.2643273919e-33 */,
114
+ /* 53 */ {{0xB9126D2F,0xA42D0A9A}} /* -8.8720409776e-34 */,
115
+ /* 54 */ {{0xB93CAF8B,0x3DFAFFA5}} /* -5.5246684074e-33 */,
116
+ /* 55 */ {{0x3919C170,0xA9A35831}} /* +1.2400882522e-33 */,
117
+ /* 56 */ {{0xB924C2B3,0xAE51E4B3}} /* -1.9991686511e-33 */,
118
+ /* 57 */ {{0xB8DEFB7D,0x0DE98917}} /* -9.3234199178e-35 */,
119
+ /* 58 */ {{0xB916EC39,0x1ABE373B}} /* -1.1036900898e-33 */,
120
+ /* 59 */ {{0x391C5BA4,0x4135ADBE}} /* +1.3653868341e-33 */,
121
+ /* 60 */ {{0xB9112692,0xD7179E60}} /* -8.2577511316e-34 */,
122
+ /* 61 */ {{0x392F96B5,0xBCC93753}} /* +3.0418821818e-33 */,
123
+ };
124
+
125
+ #else
126
+ static const db_number atan_blolo[62] = {
127
+ /* 0 */ {{0xA947CCE9,0xB8D1C5F3}} /* -5.3484426395e-35 */,
128
+ /* 1 */ {{0x3C749846,0xB8B05943}} /* -1.2299381479e-35 */,
129
+ /* 2 */ {{0x267751FB,0x38FC2F2A}} /* +3.3925541143e-34 */,
130
+ /* 3 */ {{0xDDA4249D,0x38D44E61}} /* +6.1106690132e-35 */,
131
+ /* 4 */ {{0xA5B245C8,0xB906FBFA}} /* -5.5332673453e-34 */,
132
+ /* 5 */ {{0x67CABE65,0xB8DE1E98}} /* -9.0637612563e-35 */,
133
+ /* 6 */ {{0x45D13048,0x38BD7B8F}} /* +2.2180284354e-35 */,
134
+ /* 7 */ {{0x23AD369B,0xB9049436}} /* -4.9542022687e-34 */,
135
+ /* 8 */ {{0xF6BB1DB7,0xB8F98586}} /* -3.0720497269e-34 */,
136
+ /* 9 */ {{0xCB4D6219,0xB89BC985}} /* -5.2261910438e-36 */,
137
+ /* 10 */ {{0x9C3884F4,0xB8C4002C}} /* -3.0093679582e-35 */,
138
+ /* 11 */ {{0x893058D9,0x3910CBC4}} /* +8.0869642604e-34 */,
139
+ /* 12 */ {{0xFF010BB5,0xB8F5408B}} /* -2.5581328396e-34 */,
140
+ /* 13 */ {{0xB5813578,0xB908570F}} /* -5.8596619457e-34 */,
141
+ /* 14 */ {{0x7E967248,0x39155B89}} /* +1.0283294335e-33 */,
142
+ /* 15 */ {{0x2031F115,0xB8CD159A}} /* -4.3761315763e-35 */,
143
+ /* 16 */ {{0x0FC3C81C,0xB8E8D9C6}} /* -1.4956458040e-34 */,
144
+ /* 17 */ {{0x8219F20D,0x38C0AC30}} /* +2.5086163140e-35 */,
145
+ /* 18 */ {{0x32EDCB95,0x38B36506}} /* +1.4590894790e-35 */,
146
+ /* 19 */ {{0x5932E7C2,0xB8FD57B0}} /* -3.5319791285e-34 */,
147
+ /* 20 */ {{0x91A2D916,0x38C73827}} /* +3.4936600564e-35 */,
148
+ /* 21 */ {{0x9EC5116C,0xB92FE60D}} /* -3.0717278111e-33 */,
149
+ /* 22 */ {{0x6A3B8AE2,0x3903AADF}} /* +4.7347715466e-34 */,
150
+ /* 23 */ {{0x71B87C3C,0xB88D6A01}} /* -2.7660872166e-36 */,
151
+ /* 24 */ {{0xEA5AC8E8,0xB8E17427}} /* -1.0504584084e-34 */,
152
+ /* 25 */ {{0xF776B005,0x38F4ED52}} /* +2.5190016806e-34 */,
153
+ /* 26 */ {{0x75D2B05C,0xB9265B23}} /* -2.1528054385e-33 */,
154
+ /* 27 */ {{0xAFEAB282,0xB8DA45DA}} /* -7.9062036715e-35 */,
155
+ /* 28 */ {{0xBD16D3D4,0x3912EF75}} /* +9.1170587963e-34 */,
156
+ /* 29 */ {{0xE904B022,0x390AB3D7}} /* +6.4283962392e-34 */,
157
+ /* 30 */ {{0x3F9F468B,0xB8EE688B}} /* -1.8301374849e-34 */,
158
+ /* 31 */ {{0x71A98823,0xB9225DF6}} /* -1.7686817787e-33 */,
159
+ /* 32 */ {{0x522BE0F8,0xB8CC82B0}} /* -4.2897836993e-35 */,
160
+ /* 33 */ {{0x88BB6A0B,0xB912AFE0}} /* -8.9974727841e-34 */,
161
+ /* 34 */ {{0x8640FAE5,0x38D4DC99}} /* +6.2778447830e-35 */,
162
+ /* 35 */ {{0x406A343B,0xB9016FC6}} /* -4.1977132916e-34 */,
163
+ /* 36 */ {{0x126FC74C,0x3909804C}} /* +6.1391811422e-34 */,
164
+ /* 37 */ {{0xE5B0956F,0x39051033}} /* +5.0708030720e-34 */,
165
+ /* 38 */ {{0x203B114C,0xB910CADC}} /* -8.0852567814e-34 */,
166
+ /* 39 */ {{0xF97ED36B,0x38EFCAC7}} /* +1.9134182531e-34 */,
167
+ /* 40 */ {{0xB51D77B4,0xB92464C0}} /* -1.9638289218e-33 */,
168
+ /* 41 */ {{0x2D4A03DE,0x391157F3}} /* +8.3506176591e-34 */,
169
+ /* 42 */ {{0x136A8DDE,0xB92BD929}} /* -2.6816921082e-33 */,
170
+ /* 43 */ {{0x035DF6B3,0x390F1514}} /* +7.4828003563e-34 */,
171
+ /* 44 */ {{0x19DB7E3B,0xB92606EC}} /* -2.1211268072e-33 */,
172
+ /* 45 */ {{0xCDA1B51D,0x393B104B}} /* +5.2122706777e-33 */,
173
+ /* 46 */ {{0xF88A520C,0x3935FB01}} /* +4.2332900876e-33 */,
174
+ /* 47 */ {{0x1940944D,0xB9189ED1}} /* -1.1854280852e-33 */,
175
+ /* 48 */ {{0x38D4794B,0xB914E8F2}} /* -1.0067772791e-33 */,
176
+ /* 49 */ {{0x73581CF5,0xB93DF07A}} /* -5.7661126209e-33 */,
177
+ /* 50 */ {{0x727CE10C,0xB939C22F}} /* -4.9609136744e-33 */,
178
+ /* 51 */ {{0x26E1A810,0xB8EF37D2}} /* -1.8788680655e-34 */,
179
+ /* 52 */ {{0x45155DAA,0x391A4251}} /* +1.2643273919e-33 */,
180
+ /* 53 */ {{0xA42D0A9A,0xB9126D2F}} /* -8.8720409776e-34 */,
181
+ /* 54 */ {{0x3DFAFFA5,0xB93CAF8B}} /* -5.5246684074e-33 */,
182
+ /* 55 */ {{0xA9A35831,0x3919C170}} /* +1.2400882522e-33 */,
183
+ /* 56 */ {{0xAE51E4B3,0xB924C2B3}} /* -1.9991686511e-33 */,
184
+ /* 57 */ {{0x0DE98917,0xB8DEFB7D}} /* -9.3234199178e-35 */,
185
+ /* 58 */ {{0x1ABE373B,0xB916EC39}} /* -1.1036900898e-33 */,
186
+ /* 59 */ {{0x4135ADBE,0x391C5BA4}} /* +1.3653868341e-33 */,
187
+ /* 60 */ {{0xD7179E60,0xB9112692}} /* -8.2577511316e-34 */,
188
+ /* 61 */ {{0xBCC93753,0x392F96B5}} /* +3.0418821818e-33 */,
189
+ };
190
+
191
+ #endif /* WORDS_BIGENDIAN */