clang -cc1 -cc1 -triple x86_64-unknown-linux-gnu -analyze -disable-free -clear-ast-before-backend -disable-llvm-verifier -discard-value-names -main-file-name ieee754.cc -analyzer-checker=core -analyzer-checker=apiModeling -analyzer-checker=unix -analyzer-checker=deadcode -analyzer-checker=cplusplus -analyzer-checker=security.insecureAPI.UncheckedReturn -analyzer-checker=security.insecureAPI.getpw -analyzer-checker=security.insecureAPI.gets -analyzer-checker=security.insecureAPI.mktemp -analyzer-checker=security.insecureAPI.mkstemp -analyzer-checker=security.insecureAPI.vfork -analyzer-checker=nullability.NullPassedToNonnull -analyzer-checker=nullability.NullReturnedFromNonnull -analyzer-output plist -w -setup-static-analyzer -mrelocation-model pic -pic-level 2 -pic-is-pie -mframe-pointer=all -relaxed-aliasing -fmath-errno -ffp-contract=on -fno-rounding-math -mconstructor-aliases -funwind-tables=2 -target-cpu x86-64 -tune-cpu generic -debugger-tuning=gdb -ffunction-sections -fdata-sections -fcoverage-compilation-dir=/home/maurizio/node-v18.6.0/out -resource-dir /usr/local/lib/clang/16.0.0 -D _GLIBCXX_USE_CXX11_ABI=1 -D NODE_OPENSSL_CONF_NAME=nodejs_conf -D NODE_OPENSSL_HAS_QUIC -D V8_GYP_BUILD -D V8_TYPED_ARRAY_MAX_SIZE_IN_HEAP=64 -D __STDC_FORMAT_MACROS -D OPENSSL_NO_PINSHARED -D OPENSSL_THREADS -D V8_TARGET_ARCH_X64 -D V8_HAVE_TARGET_OS -D V8_TARGET_OS_LINUX -D V8_EMBEDDER_STRING="-node.8" -D ENABLE_DISASSEMBLER -D V8_PROMISE_INTERNAL_FIELD_COUNT=1 -D V8_SHORT_BUILTIN_CALLS -D OBJECT_PRINT -D V8_INTL_SUPPORT -D V8_ATOMIC_OBJECT_FIELD_WRITES -D V8_ENABLE_LAZY_SOURCE_POSITIONS -D V8_USE_SIPHASH -D V8_SHARED_RO_HEAP -D V8_WIN64_UNWINDING_INFO -D V8_ENABLE_REGEXP_INTERPRETER_THREADED_DISPATCH -D V8_SNAPSHOT_COMPRESSION -D V8_ENABLE_WEBASSEMBLY -D V8_ENABLE_JAVASCRIPT_PROMISE_HOOKS -D V8_ALLOCATION_FOLDING -D V8_ALLOCATION_SITE_TRACKING -D V8_SCRIPTORMODULE_LEGACY_LIFETIME -D V8_ADVANCED_BIGINT_ALGORITHMS -D BUILDING_V8_BASE_SHARED -I ../deps/v8 -I ../deps/v8/include -internal-isystem /usr/lib/gcc/x86_64-redhat-linux/8/../../../../include/c++/8 -internal-isystem /usr/lib/gcc/x86_64-redhat-linux/8/../../../../include/c++/8/x86_64-redhat-linux -internal-isystem /usr/lib/gcc/x86_64-redhat-linux/8/../../../../include/c++/8/backward -internal-isystem /usr/local/lib/clang/16.0.0/include -internal-isystem /usr/local/include -internal-isystem /usr/lib/gcc/x86_64-redhat-linux/8/../../../../x86_64-redhat-linux/include -internal-externc-isystem /include -internal-externc-isystem /usr/include -O3 -Wno-unused-parameter -Wno-return-type -std=gnu++17 -fdeprecated-macro -fdebug-compilation-dir=/home/maurizio/node-v18.6.0/out -ferror-limit 19 -fno-rtti -fgnuc-version=4.2.1 -vectorize-loops -vectorize-slp -analyzer-output=html -faddrsig -D__GCC_HAVE_DWARF2_CFI_ASM=1 -o /tmp/scan-build-2022-08-22-142216-507842-1 -x c++ ../deps/v8/src/base/ieee754.cc
1 | |
2 | |
3 | |
4 | |
5 | |
6 | |
7 | |
8 | |
9 | |
10 | |
11 | |
12 | |
13 | |
14 | |
15 | |
16 | #include "src/base/ieee754.h" |
17 | |
18 | #include <cmath> |
19 | #include <limits> |
20 | |
21 | #include "src/base/build_config.h" |
22 | #include "src/base/macros.h" |
23 | #include "src/base/overflowing-math.h" |
24 | |
25 | namespace v8 { |
26 | namespace base { |
27 | namespace ieee754 { |
28 | |
29 | namespace { |
30 | |
31 | |
32 | |
33 | #if V8_CC_MSVC |
34 | |
35 | #pragma warning(disable : 4723) |
36 | |
37 | #endif |
38 | |
39 | |
40 | |
41 | |
42 | |
43 | |
44 | |
45 | |
46 | |
47 | |
48 | |
49 | |
50 | |
51 | |
52 | |
53 | |
54 | #define EXTRACT_WORDS(ix0, ix1, d) \ |
55 | do { \ |
56 | uint64_t bits = bit_cast<uint64_t>(d); \ |
57 | (ix0) = bits >> 32; \ |
58 | (ix1) = bits & 0xFFFFFFFFu; \ |
59 | } while (false) |
60 | |
61 | |
62 | |
63 | #define GET_HIGH_WORD(i, d) \ |
64 | do { \ |
65 | uint64_t bits = bit_cast<uint64_t>(d); \ |
66 | (i) = bits >> 32; \ |
67 | } while (false) |
68 | |
69 | |
70 | |
71 | #define GET_LOW_WORD(i, d) \ |
72 | do { \ |
73 | uint64_t bits = bit_cast<uint64_t>(d); \ |
74 | (i) = bits & 0xFFFFFFFFu; \ |
75 | } while (false) |
76 | |
77 | |
78 | |
79 | #define INSERT_WORDS(d, ix0, ix1) \ |
80 | do { \ |
81 | uint64_t bits = 0; \ |
82 | bits |= static_cast<uint64_t>(ix0) << 32; \ |
83 | bits |= static_cast<uint32_t>(ix1); \ |
84 | (d) = bit_cast<double>(bits); \ |
85 | } while (false) |
86 | |
87 | |
88 | |
89 | #define SET_HIGH_WORD(d, v) \ |
90 | do { \ |
91 | uint64_t bits = bit_cast<uint64_t>(d); \ |
92 | bits &= 0x0000'0000'FFFF'FFFF; \ |
93 | bits |= static_cast<uint64_t>(v) << 32; \ |
94 | (d) = bit_cast<double>(bits); \ |
95 | } while (false) |
96 | |
97 | |
98 | |
99 | #define SET_LOW_WORD(d, v) \ |
100 | do { \ |
101 | uint64_t bits = bit_cast<uint64_t>(d); \ |
102 | bits &= 0xFFFF'FFFF'0000'0000; \ |
103 | bits |= static_cast<uint32_t>(v); \ |
104 | (d) = bit_cast<double>(bits); \ |
105 | } while (false) |
106 | |
107 | int32_t __ieee754_rem_pio2(double x, double* y) V8_WARN_UNUSED_RESULT; |
108 | double __kernel_cos(double x, double y) V8_WARN_UNUSED_RESULT; |
109 | int __kernel_rem_pio2(double* x, double* y, int e0, int nx, int prec, |
110 | const int32_t* ipio2) V8_WARN_UNUSED_RESULT; |
111 | double __kernel_sin(double x, double y, int iy) V8_WARN_UNUSED_RESULT; |
112 | |
113 | |
114 | |
115 | |
116 | |
117 | |
118 | int32_t __ieee754_rem_pio2(double x, double *y) { |
119 | |
120 | |
121 | |
122 | static const int32_t two_over_pi[] = { |
123 | 0xA2F983, 0x6E4E44, 0x1529FC, 0x2757D1, 0xF534DD, 0xC0DB62, 0x95993C, |
124 | 0x439041, 0xFE5163, 0xABDEBB, 0xC561B7, 0x246E3A, 0x424DD2, 0xE00649, |
125 | 0x2EEA09, 0xD1921C, 0xFE1DEB, 0x1CB129, 0xA73EE8, 0x8235F5, 0x2EBB44, |
126 | 0x84E99C, 0x7026B4, 0x5F7E41, 0x3991D6, 0x398353, 0x39F49C, 0x845F8B, |
127 | 0xBDF928, 0x3B1FF8, 0x97FFDE, 0x05980F, 0xEF2F11, 0x8B5A0A, 0x6D1F6D, |
128 | 0x367ECF, 0x27CB09, 0xB74F46, 0x3F669E, 0x5FEA2D, 0x7527BA, 0xC7EBE5, |
129 | 0xF17B3D, 0x0739F7, 0x8A5292, 0xEA6BFB, 0x5FB11F, 0x8D5D08, 0x560330, |
130 | 0x46FC7B, 0x6BABF0, 0xCFBC20, 0x9AF436, 0x1DA9E3, 0x91615E, 0xE61B08, |
131 | 0x659985, 0x5F14A0, 0x68408D, 0xFFD880, 0x4D7327, 0x310606, 0x1556CA, |
132 | 0x73A8C9, 0x60E27B, 0xC08C6B, |
133 | }; |
134 | |
135 | static const int32_t npio2_hw[] = { |
136 | 0x3FF921FB, 0x400921FB, 0x4012D97C, 0x401921FB, 0x401F6A7A, 0x4022D97C, |
137 | 0x4025FDBB, 0x402921FB, 0x402C463A, 0x402F6A7A, 0x4031475C, 0x4032D97C, |
138 | 0x40346B9C, 0x4035FDBB, 0x40378FDB, 0x403921FB, 0x403AB41B, 0x403C463A, |
139 | 0x403DD85A, 0x403F6A7A, 0x40407E4C, 0x4041475C, 0x4042106C, 0x4042D97C, |
140 | 0x4043A28C, 0x40446B9C, 0x404534AC, 0x4045FDBB, 0x4046C6CB, 0x40478FDB, |
141 | 0x404858EB, 0x404921FB, |
142 | }; |
143 | |
144 | |
145 | |
146 | |
147 | |
148 | |
149 | |
150 | |
151 | |
152 | |
153 | |
154 | static const double |
155 | zero = 0.00000000000000000000e+00, |
156 | half = 5.00000000000000000000e-01, |
157 | two24 = 1.67772160000000000000e+07, |
158 | invpio2 = 6.36619772367581382433e-01, |
159 | pio2_1 = 1.57079632673412561417e+00, |
160 | pio2_1t = 6.07710050650619224932e-11, |
161 | pio2_2 = 6.07710050630396597660e-11, |
162 | pio2_2t = 2.02226624879595063154e-21, |
163 | pio2_3 = 2.02226624871116645580e-21, |
164 | pio2_3t = 8.47842766036889956997e-32; |
165 | |
166 | double z, w, t, r, fn; |
167 | double tx[3]; |
168 | int32_t e0, i, j, nx, n, ix, hx; |
169 | uint32_t low; |
170 | |
171 | z = 0; |
172 | GET_HIGH_WORD(hx, x); |
173 | ix = hx & 0x7FFFFFFF; |
174 | if (ix <= 0x3FE921FB) { |
175 | y[0] = x; |
176 | y[1] = 0; |
177 | return 0; |
178 | } |
179 | if (ix < 0x4002D97C) { |
180 | if (hx > 0) { |
181 | z = x - pio2_1; |
182 | if (ix != 0x3FF921FB) { |
183 | y[0] = z - pio2_1t; |
184 | y[1] = (z - y[0]) - pio2_1t; |
185 | } else { |
186 | z -= pio2_2; |
187 | y[0] = z - pio2_2t; |
188 | y[1] = (z - y[0]) - pio2_2t; |
189 | } |
190 | return 1; |
191 | } else { |
192 | z = x + pio2_1; |
193 | if (ix != 0x3FF921FB) { |
194 | y[0] = z + pio2_1t; |
195 | y[1] = (z - y[0]) + pio2_1t; |
196 | } else { |
197 | z += pio2_2; |
198 | y[0] = z + pio2_2t; |
199 | y[1] = (z - y[0]) + pio2_2t; |
200 | } |
201 | return -1; |
202 | } |
203 | } |
204 | if (ix <= 0x413921FB) { |
205 | t = fabs(x); |
206 | n = static_cast<int32_t>(t * invpio2 + half); |
207 | fn = static_cast<double>(n); |
208 | r = t - fn * pio2_1; |
209 | w = fn * pio2_1t; |
210 | if (n < 32 && ix != npio2_hw[n - 1]) { |
211 | y[0] = r - w; |
212 | } else { |
213 | uint32_t high; |
214 | j = ix >> 20; |
215 | y[0] = r - w; |
216 | GET_HIGH_WORD(high, y[0]); |
217 | i = j - ((high >> 20) & 0x7FF); |
218 | if (i > 16) { |
219 | t = r; |
220 | w = fn * pio2_2; |
221 | r = t - w; |
222 | w = fn * pio2_2t - ((t - r) - w); |
223 | y[0] = r - w; |
224 | GET_HIGH_WORD(high, y[0]); |
225 | i = j - ((high >> 20) & 0x7FF); |
226 | if (i > 49) { |
227 | t = r; |
228 | w = fn * pio2_3; |
229 | r = t - w; |
230 | w = fn * pio2_3t - ((t - r) - w); |
231 | y[0] = r - w; |
232 | } |
233 | } |
234 | } |
235 | y[1] = (r - y[0]) - w; |
236 | if (hx < 0) { |
237 | y[0] = -y[0]; |
238 | y[1] = -y[1]; |
239 | return -n; |
240 | } else { |
241 | return n; |
242 | } |
243 | } |
244 | |
245 | |
246 | |
247 | if (ix >= 0x7FF00000) { |
248 | y[0] = y[1] = x - x; |
249 | return 0; |
250 | } |
251 | |
252 | GET_LOW_WORD(low, x); |
253 | SET_LOW_WORD(z, low); |
254 | e0 = (ix >> 20) - 1046; |
255 | SET_HIGH_WORD(z, ix - static_cast<int32_t>(static_cast<uint32_t>(e0) << 20)); |
256 | for (i = 0; i < 2; i++) { |
257 | tx[i] = static_cast<double>(static_cast<int32_t>(z)); |
258 | z = (z - tx[i]) * two24; |
259 | } |
260 | tx[2] = z; |
261 | nx = 3; |
262 | while (tx[nx - 1] == zero) nx--; |
263 | n = __kernel_rem_pio2(tx, y, e0, nx, 2, two_over_pi); |
264 | if (hx < 0) { |
265 | y[0] = -y[0]; |
266 | y[1] = -y[1]; |
267 | return -n; |
268 | } |
269 | return n; |
270 | } |
271 | |
272 | |
273 | |
274 | |
275 | |
276 | |
277 | |
278 | |
279 | |
280 | |
281 | |
282 | |
283 | |
284 | |
285 | |
286 | |
287 | |
288 | |
289 | |
290 | |
291 | |
292 | |
293 | |
294 | |
295 | |
296 | |
297 | |
298 | |
299 | |
300 | |
301 | |
302 | |
303 | |
304 | |
305 | V8_INLINE double __kernel_cos(double x, double y) { |
306 | static const double |
307 | one = 1.00000000000000000000e+00, |
308 | C1 = 4.16666666666666019037e-02, |
309 | C2 = -1.38888888888741095749e-03, |
310 | C3 = 2.48015872894767294178e-05, |
311 | C4 = -2.75573143513906633035e-07, |
312 | C5 = 2.08757232129817482790e-09, |
313 | C6 = -1.13596475577881948265e-11; |
314 | |
315 | double a, iz, z, r, qx; |
316 | int32_t ix; |
317 | GET_HIGH_WORD(ix, x); |
318 | ix &= 0x7FFFFFFF; |
319 | if (ix < 0x3E400000) { |
320 | if (static_cast<int>(x) == 0) return one; |
321 | } |
322 | z = x * x; |
323 | r = z * (C1 + z * (C2 + z * (C3 + z * (C4 + z * (C5 + z * C6))))); |
324 | if (ix < 0x3FD33333) { |
325 | return one - (0.5 * z - (z * r - x * y)); |
326 | } else { |
327 | if (ix > 0x3FE90000) { |
328 | qx = 0.28125; |
329 | } else { |
330 | INSERT_WORDS(qx, ix - 0x00200000, 0); |
331 | } |
332 | iz = 0.5 * z - qx; |
333 | a = one - qx; |
334 | return a - (iz - (z * r - x * y)); |
335 | } |
336 | } |
337 | |
338 | |
339 | |
340 | |
341 | |
342 | |
343 | |
344 | |
345 | |
346 | |
347 | |
348 | |
349 | |
350 | |
351 | |
352 | |
353 | |
354 | |
355 | |
356 | |
357 | |
358 | |
359 | |
360 | |
361 | |
362 | |
363 | |
364 | |
365 | |
366 | |
367 | |
368 | |
369 | |
370 | |
371 | |
372 | |
373 | |
374 | |
375 | |
376 | |
377 | |
378 | |
379 | |
380 | |
381 | |
382 | |
383 | |
384 | |
385 | |
386 | |
387 | |
388 | |
389 | |
390 | |
391 | |
392 | |
393 | |
394 | |
395 | |
396 | |
397 | |
398 | |
399 | |
400 | |
401 | |
402 | |
403 | |
404 | |
405 | |
406 | |
407 | |
408 | |
409 | |
410 | |
411 | |
412 | |
413 | |
414 | |
415 | |
416 | |
417 | |
418 | |
419 | |
420 | |
421 | |
422 | |
423 | |
424 | |
425 | |
426 | |
427 | |
428 | |
429 | |
430 | |
431 | |
432 | |
433 | |
434 | |
435 | |
436 | |
437 | |
438 | |
439 | |
440 | |
441 | |
442 | |
443 | int __kernel_rem_pio2(double *x, double *y, int e0, int nx, int prec, |
444 | const int32_t *ipio2) { |
445 | |
446 | |
447 | |
448 | |
449 | |
450 | |
451 | static const int init_jk[] = {2, 3, 4, 6}; |
452 | |
453 | static const double PIo2[] = { |
454 | 1.57079625129699707031e+00, |
455 | 7.54978941586159635335e-08, |
456 | 5.39030252995776476554e-15, |
457 | 3.28200341580791294123e-22, |
458 | 1.27065575308067607349e-29, |
459 | 1.22933308981111328932e-36, |
460 | 2.73370053816464559624e-44, |
461 | 2.16741683877804819444e-51, |
462 | }; |
463 | |
464 | static const double |
465 | zero = 0.0, |
466 | one = 1.0, |
467 | two24 = 1.67772160000000000000e+07, |
468 | twon24 = 5.96046447753906250000e-08; |
469 | |
470 | int32_t jz, jx, jv, jp, jk, carry, n, iq[20], i, j, k, m, q0, ih; |
471 | double z, fw, f[20], fq[20], q[20]; |
472 | |
473 | |
474 | jk = init_jk[prec]; |
475 | jp = jk; |
476 | |
477 | |
478 | jx = nx - 1; |
479 | jv = (e0 - 3) / 24; |
480 | if (jv < 0) jv = 0; |
| |
| |
481 | q0 = e0 - 24 * (jv + 1); |
482 | |
483 | |
484 | j = jv - jx; |
485 | m = jx + jk; |
486 | for (i = 0; i <= m; i++, j++) { |
| |
| 4 | | Loop condition is false. Execution continues on line 491 | |
|
487 | f[i] = (j < 0) ? zero : static_cast<double>(ipio2[j]); |
488 | } |
489 | |
490 | |
491 | for (i = 0; i <= jk; i++) { |
| |
| 6 | | Loop condition is true. Entering loop body | |
|
| |
| 10 | | Loop condition is false. Execution continues on line 496 | |
|
492 | for (j = 0, fw = 0.0; j <= jx; j++) fw += x[j] * f[jx + i - j]; |
| |
| 8 | | Loop condition is false. Execution continues on line 493 | |
|
493 | q[i] = fw; |
494 | } |
495 | |
496 | jz = jk; |
497 | recompute: |
498 | |
499 | for (i = 0, j = jz, z = q[jz]; j > 0; i++, j--) { |
| 11 | | Loop condition is false. Execution continues on line 506 | |
|
500 | fw = static_cast<double>(static_cast<int32_t>(twon24 * z)); |
501 | iq[i] = static_cast<int32_t>(z - two24 * fw); |
502 | z = q[j - 1] + fw; |
503 | } |
504 | |
505 | |
506 | z = scalbn(z, q0); |
507 | z -= 8.0 * floor(z * 0.125); |
508 | n = static_cast<int32_t>(z); |
509 | z -= static_cast<double>(n); |
510 | ih = 0; |
511 | if (q0 > 0) { |
| |
| |
512 | i = (iq[jz - 1] >> (24 - q0)); |
513 | n += i; |
514 | iq[jz - 1] -= i << (24 - q0); |
515 | ih = iq[jz - 1] >> (23 - q0); |
516 | } else if (q0 == 0) { |
| 14 | | Assuming 'q0' is equal to 0 | |
|
| |
517 | ih = iq[jz - 1] >> 23; |
| 16 | | The left operand of '>>' is a garbage value due to array index out of bounds |
|
518 | } else if (z >= 0.5) { |
519 | ih = 2; |
520 | } |
521 | |
522 | if (ih > 0) { |
523 | n += 1; |
524 | carry = 0; |
525 | for (i = 0; i < jz; i++) { |
526 | j = iq[i]; |
527 | if (carry == 0) { |
528 | if (j != 0) { |
529 | carry = 1; |
530 | iq[i] = 0x1000000 - j; |
531 | } |
532 | } else { |
533 | iq[i] = 0xFFFFFF - j; |
534 | } |
535 | } |
536 | if (q0 > 0) { |
537 | switch (q0) { |
538 | case 1: |
539 | iq[jz - 1] &= 0x7FFFFF; |
540 | break; |
541 | case 2: |
542 | iq[jz - 1] &= 0x3FFFFF; |
543 | break; |
544 | } |
545 | } |
546 | if (ih == 2) { |
547 | z = one - z; |
548 | if (carry != 0) z -= scalbn(one, q0); |
549 | } |
550 | } |
551 | |
552 | |
553 | if (z == zero) { |
554 | j = 0; |
555 | for (i = jz - 1; i >= jk; i--) j |= iq[i]; |
556 | if (j == 0) { |
557 | for (k = 1; jk >= k && iq[jk - k] == 0; k++) { |
558 | |
559 | } |
560 | |
561 | for (i = jz + 1; i <= jz + k; i++) { |
562 | f[jx + i] = ipio2[jv + i]; |
563 | for (j = 0, fw = 0.0; j <= jx; j++) fw += x[j] * f[jx + i - j]; |
564 | q[i] = fw; |
565 | } |
566 | jz += k; |
567 | goto recompute; |
568 | } |
569 | } |
570 | |
571 | |
572 | if (z == 0.0) { |
573 | jz -= 1; |
574 | q0 -= 24; |
575 | while (iq[jz] == 0) { |
576 | jz--; |
577 | q0 -= 24; |
578 | } |
579 | } else { |
580 | z = scalbn(z, -q0); |
581 | if (z >= two24) { |
582 | fw = static_cast<double>(static_cast<int32_t>(twon24 * z)); |
583 | iq[jz] = z - two24 * fw; |
584 | jz += 1; |
585 | q0 += 24; |
586 | iq[jz] = fw; |
587 | } else { |
588 | iq[jz] = z; |
589 | } |
590 | } |
591 | |
592 | |
593 | fw = scalbn(one, q0); |
594 | for (i = jz; i >= 0; i--) { |
595 | q[i] = fw * iq[i]; |
596 | fw *= twon24; |
597 | } |
598 | |
599 | |
600 | for (i = jz; i >= 0; i--) { |
601 | for (fw = 0.0, k = 0; k <= jp && k <= jz - i; k++) fw += PIo2[k] * q[i + k]; |
602 | fq[jz - i] = fw; |
603 | } |
604 | |
605 | |
606 | switch (prec) { |
607 | case 0: |
608 | fw = 0.0; |
609 | for (i = jz; i >= 0; i--) fw += fq[i]; |
610 | y[0] = (ih == 0) ? fw : -fw; |
611 | break; |
612 | case 1: |
613 | case 2: |
614 | fw = 0.0; |
615 | for (i = jz; i >= 0; i--) fw += fq[i]; |
616 | y[0] = (ih == 0) ? fw : -fw; |
617 | fw = fq[0] - fw; |
618 | for (i = 1; i <= jz; i++) fw += fq[i]; |
619 | y[1] = (ih == 0) ? fw : -fw; |
620 | break; |
621 | case 3: |
622 | for (i = jz; i > 0; i--) { |
623 | fw = fq[i - 1] + fq[i]; |
624 | fq[i] += fq[i - 1] - fw; |
625 | fq[i - 1] = fw; |
626 | } |
627 | for (i = jz; i > 1; i--) { |
628 | fw = fq[i - 1] + fq[i]; |
629 | fq[i] += fq[i - 1] - fw; |
630 | fq[i - 1] = fw; |
631 | } |
632 | for (fw = 0.0, i = jz; i >= 2; i--) fw += fq[i]; |
633 | if (ih == 0) { |
634 | y[0] = fq[0]; |
635 | y[1] = fq[1]; |
636 | y[2] = fw; |
637 | } else { |
638 | y[0] = -fq[0]; |
639 | y[1] = -fq[1]; |
640 | y[2] = -fw; |
641 | } |
642 | } |
643 | return n & 7; |
644 | } |
645 | |
646 | |
647 | |
648 | |
649 | |
650 | |
651 | |
652 | |
653 | |
654 | |
655 | |
656 | |
657 | |
658 | |
659 | |
660 | |
661 | |
662 | |
663 | |
664 | |
665 | |
666 | |
667 | |
668 | |
669 | |
670 | |
671 | |
672 | |
673 | V8_INLINE double __kernel_sin(double x, double y, int iy) { |
674 | static const double |
675 | half = 5.00000000000000000000e-01, |
676 | S1 = -1.66666666666666324348e-01, |
677 | S2 = 8.33333333332248946124e-03, |
678 | S3 = -1.98412698298579493134e-04, |
679 | S4 = 2.75573137070700676789e-06, |
680 | S5 = -2.50507602534068634195e-08, |
681 | S6 = 1.58969099521155010221e-10; |
682 | |
683 | double z, r, v; |
684 | int32_t ix; |
685 | GET_HIGH_WORD(ix, x); |
686 | ix &= 0x7FFFFFFF; |
687 | if (ix < 0x3E400000) { |
688 | if (static_cast<int>(x) == 0) return x; |
689 | } |
690 | z = x * x; |
691 | v = z * x; |
692 | r = S2 + z * (S3 + z * (S4 + z * (S5 + z * S6))); |
693 | if (iy == 0) { |
694 | return x + v * (S1 + z * r); |
695 | } else { |
696 | return x - ((z * (half * y - v * r) - y) - v * S1); |
697 | } |
698 | } |
699 | |
700 | |
701 | |
702 | |
703 | |
704 | |
705 | |
706 | |
707 | |
708 | |
709 | |
710 | |
711 | |
712 | |
713 | |
714 | |
715 | |
716 | |
717 | |
718 | |
719 | |
720 | |
721 | |
722 | |
723 | |
724 | |
725 | |
726 | |
727 | |
728 | |
729 | |
730 | |
731 | |
732 | |
733 | double __kernel_tan(double x, double y, int iy) { |
734 | static const double xxx[] = { |
735 | 3.33333333333334091986e-01, |
736 | 1.33333333333201242699e-01, |
737 | 5.39682539762260521377e-02, |
738 | 2.18694882948595424599e-02, |
739 | 8.86323982359930005737e-03, |
740 | 3.59207910759131235356e-03, |
741 | 1.45620945432529025516e-03, |
742 | 5.88041240820264096874e-04, |
743 | 2.46463134818469906812e-04, |
744 | 7.81794442939557092300e-05, |
745 | 7.14072491382608190305e-05, |
746 | -1.85586374855275456654e-05, |
747 | 2.59073051863633712884e-05, |
748 | 1.00000000000000000000e+00, |
749 | 7.85398163397448278999e-01, |
750 | 3.06161699786838301793e-17 |
751 | }; |
752 | #define one xxx[13] |
753 | #define pio4 xxx[14] |
754 | #define pio4lo xxx[15] |
755 | #define T xxx |
756 | |
757 | double z, r, v, w, s; |
758 | int32_t ix, hx; |
759 | |
760 | GET_HIGH_WORD(hx, x); |
761 | ix = hx & 0x7FFFFFFF; |
762 | if (ix < 0x3E300000) { |
763 | if (static_cast<int>(x) == 0) { |
764 | uint32_t low; |
765 | GET_LOW_WORD(low, x); |
766 | if (((ix | low) | (iy + 1)) == 0) { |
767 | return one / fabs(x); |
768 | } else { |
769 | if (iy == 1) { |
770 | return x; |
771 | } else { |
772 | double a, t; |
773 | |
774 | z = w = x + y; |
775 | SET_LOW_WORD(z, 0); |
776 | v = y - (z - x); |
777 | t = a = -one / w; |
778 | SET_LOW_WORD(t, 0); |
779 | s = one + t * z; |
780 | return t + a * (s + t * v); |
781 | } |
782 | } |
783 | } |
784 | } |
785 | if (ix >= 0x3FE59428) { |
786 | if (hx < 0) { |
787 | x = -x; |
788 | y = -y; |
789 | } |
790 | z = pio4 - x; |
791 | w = pio4lo - y; |
792 | x = z + w; |
793 | y = 0.0; |
794 | } |
795 | z = x * x; |
796 | w = z * z; |
797 | |
798 | |
799 | |
800 | |
801 | |
802 | r = T[1] + w * (T[3] + w * (T[5] + w * (T[7] + w * (T[9] + w * T[11])))); |
803 | v = z * |
804 | (T[2] + w * (T[4] + w * (T[6] + w * (T[8] + w * (T[10] + w * T[12]))))); |
805 | s = z * x; |
806 | r = y + z * (s * (r + v) + y); |
807 | r += T[0] * s; |
808 | w = x + r; |
809 | if (ix >= 0x3FE59428) { |
810 | v = iy; |
811 | return (1 - ((hx >> 30) & 2)) * (v - 2.0 * (x - (w * w / (w + v) - r))); |
812 | } |
813 | if (iy == 1) { |
814 | return w; |
815 | } else { |
816 | |
817 | |
818 | |
819 | |
820 | |
821 | double a, t; |
822 | z = w; |
823 | SET_LOW_WORD(z, 0); |
824 | v = r - (z - x); |
825 | t = a = -1.0 / w; |
826 | SET_LOW_WORD(t, 0); |
827 | s = 1.0 + t * z; |
828 | return t + a * (s + t * v); |
829 | } |
830 | |
831 | #undef one |
832 | #undef pio4 |
833 | #undef pio4lo |
834 | #undef T |
835 | } |
836 | |
837 | } |
838 | |
839 | |
840 | |
841 | |
842 | |
843 | |
844 | |
845 | |
846 | |
847 | |
848 | |
849 | |
850 | |
851 | |
852 | |
853 | |
854 | |
855 | |
856 | |
857 | |
858 | |
859 | |
860 | |
861 | |
862 | double acos(double x) { |
863 | static const double |
864 | one = 1.00000000000000000000e+00, |
865 | pi = 3.14159265358979311600e+00, |
866 | pio2_hi = 1.57079632679489655800e+00, |
867 | pio2_lo = 6.12323399573676603587e-17, |
868 | pS0 = 1.66666666666666657415e-01, |
869 | pS1 = -3.25565818622400915405e-01, |
870 | pS2 = 2.01212532134862925881e-01, |
871 | pS3 = -4.00555345006794114027e-02, |
872 | pS4 = 7.91534994289814532176e-04, |
873 | pS5 = 3.47933107596021167570e-05, |
874 | qS1 = -2.40339491173441421878e+00, |
875 | qS2 = 2.02094576023350569471e+00, |
876 | qS3 = -6.88283971605453293030e-01, |
877 | qS4 = 7.70381505559019352791e-02; |
878 | |
879 | double z, p, q, r, w, s, c, df; |
880 | int32_t hx, ix; |
881 | GET_HIGH_WORD(hx, x); |
882 | ix = hx & 0x7FFFFFFF; |
883 | if (ix >= 0x3FF00000) { |
884 | uint32_t lx; |
885 | GET_LOW_WORD(lx, x); |
886 | if (((ix - 0x3FF00000) | lx) == 0) { |
887 | if (hx > 0) |
888 | return 0.0; |
889 | else |
890 | return pi + 2.0 * pio2_lo; |
891 | } |
892 | return std::numeric_limits<double>::signaling_NaN(); |
893 | } |
894 | if (ix < 0x3FE00000) { |
895 | if (ix <= 0x3C600000) return pio2_hi + pio2_lo; |
896 | z = x * x; |
897 | p = z * (pS0 + z * (pS1 + z * (pS2 + z * (pS3 + z * (pS4 + z * pS5))))); |
898 | q = one + z * (qS1 + z * (qS2 + z * (qS3 + z * qS4))); |
899 | r = p / q; |
900 | return pio2_hi - (x - (pio2_lo - x * r)); |
901 | } else if (hx < 0) { |
902 | z = (one + x) * 0.5; |
903 | p = z * (pS0 + z * (pS1 + z * (pS2 + z * (pS3 + z * (pS4 + z * pS5))))); |
904 | q = one + z * (qS1 + z * (qS2 + z * (qS3 + z * qS4))); |
905 | s = sqrt(z); |
906 | r = p / q; |
907 | w = r * s - pio2_lo; |
908 | return pi - 2.0 * (s + w); |
909 | } else { |
910 | z = (one - x) * 0.5; |
911 | s = sqrt(z); |
912 | df = s; |
913 | SET_LOW_WORD(df, 0); |
914 | c = (z - df * df) / (s + df); |
915 | p = z * (pS0 + z * (pS1 + z * (pS2 + z * (pS3 + z * (pS4 + z * pS5))))); |
916 | q = one + z * (qS1 + z * (qS2 + z * (qS3 + z * qS4))); |
917 | r = p / q; |
918 | w = r * s + c; |
919 | return 2.0 * (df + w); |
920 | } |
921 | } |
922 | |
923 | |
924 | |
925 | |
926 | |
927 | |
928 | |
929 | |
930 | |
931 | |
932 | |
933 | |
934 | |
935 | |
936 | double acosh(double x) { |
937 | static const double |
938 | one = 1.0, |
939 | ln2 = 6.93147180559945286227e-01; |
940 | double t; |
941 | int32_t hx; |
942 | uint32_t lx; |
943 | EXTRACT_WORDS(hx, lx, x); |
944 | if (hx < 0x3FF00000) { |
945 | return std::numeric_limits<double>::signaling_NaN(); |
946 | } else if (hx >= 0x41B00000) { |
947 | if (hx >= 0x7FF00000) { |
948 | return x + x; |
949 | } else { |
950 | return log(x) + ln2; |
951 | } |
952 | } else if (((hx - 0x3FF00000) | lx) == 0) { |
953 | return 0.0; |
954 | } else if (hx > 0x40000000) { |
955 | t = x * x; |
956 | return log(2.0 * x - one / (x + sqrt(t - one))); |
957 | } else { |
958 | t = x - one; |
959 | return log1p(t + sqrt(2.0 * t + t * t)); |
960 | } |
961 | } |
962 | |
963 | |
964 | |
965 | |
966 | |
967 | |
968 | |
969 | |
970 | |
971 | |
972 | |
973 | |
974 | |
975 | |
976 | |
977 | |
978 | |
979 | |
980 | |
981 | |
982 | |
983 | |
984 | |
985 | |
986 | |
987 | |
988 | |
989 | |
990 | |
991 | double asin(double x) { |
992 | static const double |
993 | one = 1.00000000000000000000e+00, |
994 | huge = 1.000e+300, |
995 | pio2_hi = 1.57079632679489655800e+00, |
996 | pio2_lo = 6.12323399573676603587e-17, |
997 | pio4_hi = 7.85398163397448278999e-01, |
998 | |
999 | pS0 = 1.66666666666666657415e-01, |
1000 | pS1 = -3.25565818622400915405e-01, |
1001 | pS2 = 2.01212532134862925881e-01, |
1002 | pS3 = -4.00555345006794114027e-02, |
1003 | pS4 = 7.91534994289814532176e-04, |
1004 | pS5 = 3.47933107596021167570e-05, |
1005 | qS1 = -2.40339491173441421878e+00, |
1006 | qS2 = 2.02094576023350569471e+00, |
1007 | qS3 = -6.88283971605453293030e-01, |
1008 | qS4 = 7.70381505559019352791e-02; |
1009 | |
1010 | double t, w, p, q, c, r, s; |
1011 | int32_t hx, ix; |
1012 | |
1013 | t = 0; |
1014 | GET_HIGH_WORD(hx, x); |
1015 | ix = hx & 0x7FFFFFFF; |
1016 | if (ix >= 0x3FF00000) { |
1017 | uint32_t lx; |
1018 | GET_LOW_WORD(lx, x); |
1019 | if (((ix - 0x3FF00000) | lx) == 0) { |
1020 | return x * pio2_hi + x * pio2_lo; |
1021 | } |
1022 | return std::numeric_limits<double>::signaling_NaN(); |
1023 | } else if (ix < 0x3FE00000) { |
1024 | if (ix < 0x3E400000) { |
1025 | if (huge + x > one) return x; |
1026 | } else { |
1027 | t = x * x; |
1028 | } |
1029 | p = t * (pS0 + t * (pS1 + t * (pS2 + t * (pS3 + t * (pS4 + t * pS5))))); |
1030 | q = one + t * (qS1 + t * (qS2 + t * (qS3 + t * qS4))); |
1031 | w = p / q; |
1032 | return x + x * w; |
1033 | } |
1034 | |
1035 | w = one - fabs(x); |
1036 | t = w * 0.5; |
1037 | p = t * (pS0 + t * (pS1 + t * (pS2 + t * (pS3 + t * (pS4 + t * pS5))))); |
1038 | q = one + t * (qS1 + t * (qS2 + t * (qS3 + t * qS4))); |
1039 | s = sqrt(t); |
1040 | if (ix >= 0x3FEF3333) { |
1041 | w = p / q; |
1042 | t = pio2_hi - (2.0 * (s + s * w) - pio2_lo); |
1043 | } else { |
1044 | w = s; |
1045 | SET_LOW_WORD(w, 0); |
1046 | c = (t - w * w) / (s + w); |
1047 | r = p / q; |
1048 | p = 2.0 * s * r - (pio2_lo - 2.0 * c); |
1049 | q = pio4_hi - 2.0 * w; |
1050 | t = pio4_hi - (p - q); |
1051 | } |
1052 | if (hx > 0) |
1053 | return t; |
1054 | else |
1055 | return -t; |
1056 | } |
1057 | |
1058 | |
1059 | |
1060 | |
1061 | |
1062 | |
1063 | |
1064 | |
1065 | |
1066 | |
1067 | double asinh(double x) { |
1068 | static const double |
1069 | one = 1.00000000000000000000e+00, |
1070 | ln2 = 6.93147180559945286227e-01, |
1071 | huge = 1.00000000000000000000e+300; |
1072 | |
1073 | double t, w; |
1074 | int32_t hx, ix; |
1075 | GET_HIGH_WORD(hx, x); |
1076 | ix = hx & 0x7FFFFFFF; |
1077 | if (ix >= 0x7FF00000) return x + x; |
1078 | if (ix < 0x3E300000) { |
1079 | if (huge + x > one) return x; |
1080 | } |
1081 | if (ix > 0x41B00000) { |
1082 | w = log(fabs(x)) + ln2; |
1083 | } else if (ix > 0x40000000) { |
1084 | t = fabs(x); |
1085 | w = log(2.0 * t + one / (sqrt(x * x + one) + t)); |
1086 | } else { |
1087 | t = x * x; |
1088 | w = log1p(fabs(x) + t / (one + sqrt(one + t))); |
1089 | } |
1090 | if (hx > 0) { |
1091 | return w; |
1092 | } else { |
1093 | return -w; |
1094 | } |
1095 | } |
1096 | |
1097 | |
1098 | |
1099 | |
1100 | |
1101 | |
1102 | |
1103 | |
1104 | |
1105 | |
1106 | |
1107 | |
1108 | |
1109 | |
1110 | |
1111 | |
1112 | |
1113 | |
1114 | |
1115 | |
1116 | double atan(double x) { |
1117 | static const double atanhi[] = { |
1118 | 4.63647609000806093515e-01, |
1119 | 7.85398163397448278999e-01, |
1120 | 9.82793723247329054082e-01, |
1121 | 1.57079632679489655800e+00, |
1122 | }; |
1123 | |
1124 | static const double atanlo[] = { |
1125 | 2.26987774529616870924e-17, |
1126 | 3.06161699786838301793e-17, |
1127 | 1.39033110312309984516e-17, |
1128 | 6.12323399573676603587e-17, |
1129 | }; |
1130 | |
1131 | static const double aT[] = { |
1132 | 3.33333333333329318027e-01, |
1133 | -1.99999999998764832476e-01, |
1134 | 1.42857142725034663711e-01, |
1135 | -1.11111104054623557880e-01, |
1136 | 9.09088713343650656196e-02, |
1137 | -7.69187620504482999495e-02, |
1138 | 6.66107313738753120669e-02, |
1139 | -5.83357013379057348645e-02, |
1140 | 4.97687799461593236017e-02, |
1141 | -3.65315727442169155270e-02, |
1142 | 1.62858201153657823623e-02, |
1143 | }; |
1144 | |
1145 | static const double one = 1.0, huge = 1.0e300; |
1146 | |
1147 | double w, s1, s2, z; |
1148 | int32_t ix, hx, id; |
1149 | |
1150 | GET_HIGH_WORD(hx, x); |
1151 | ix = hx & 0x7FFFFFFF; |
1152 | if (ix >= 0x44100000) { |
1153 | uint32_t low; |
1154 | GET_LOW_WORD(low, x); |
1155 | if (ix > 0x7FF00000 || (ix == 0x7FF00000 && (low != 0))) |
1156 | return x + x; |
1157 | if (hx > 0) |
1158 | return atanhi[3] + *const_cast<volatile double*>(&atanlo[3]); |
1159 | else |
1160 | return -atanhi[3] - *const_cast<volatile double*>(&atanlo[3]); |
1161 | } |
1162 | if (ix < 0x3FDC0000) { |
1163 | if (ix < 0x3E400000) { |
1164 | if (huge + x > one) return x; |
1165 | } |
1166 | id = -1; |
1167 | } else { |
1168 | x = fabs(x); |
1169 | if (ix < 0x3FF30000) { |
1170 | if (ix < 0x3FE60000) { |
1171 | id = 0; |
1172 | x = (2.0 * x - one) / (2.0 + x); |
1173 | } else { |
1174 | id = 1; |
1175 | x = (x - one) / (x + one); |
1176 | } |
1177 | } else { |
1178 | if (ix < 0x40038000) { |
1179 | id = 2; |
1180 | x = (x - 1.5) / (one + 1.5 * x); |
1181 | } else { |
1182 | id = 3; |
1183 | x = -1.0 / x; |
1184 | } |
1185 | } |
1186 | } |
1187 | |
1188 | z = x * x; |
1189 | w = z * z; |
1190 | |
1191 | s1 = z * (aT[0] + |
1192 | w * (aT[2] + w * (aT[4] + w * (aT[6] + w * (aT[8] + w * aT[10]))))); |
1193 | s2 = w * (aT[1] + w * (aT[3] + w * (aT[5] + w * (aT[7] + w * aT[9])))); |
1194 | if (id < 0) { |
1195 | return x - x * (s1 + s2); |
1196 | } else { |
1197 | z = atanhi[id] - ((x * (s1 + s2) - atanlo[id]) - x); |
1198 | return (hx < 0) ? -z : z; |
1199 | } |
1200 | } |
1201 | |
1202 | |
1203 | |
1204 | |
1205 | |
1206 | |
1207 | |
1208 | |
1209 | |
1210 | |
1211 | |
1212 | |
1213 | |
1214 | |
1215 | |
1216 | |
1217 | |
1218 | |
1219 | |
1220 | |
1221 | |
1222 | |
1223 | |
1224 | |
1225 | |
1226 | |
1227 | |
1228 | double atan2(double y, double x) { |
1229 | static volatile double tiny = 1.0e-300; |
1230 | static const double |
1231 | zero = 0.0, |
1232 | pi_o_4 = 7.8539816339744827900E-01, |
1233 | pi_o_2 = 1.5707963267948965580E+00, |
1234 | pi = 3.1415926535897931160E+00; |
1235 | static volatile double pi_lo = |
1236 | 1.2246467991473531772E-16; |
1237 | |
1238 | double z; |
1239 | int32_t k, m, hx, hy, ix, iy; |
1240 | uint32_t lx, ly; |
1241 | |
1242 | EXTRACT_WORDS(hx, lx, x); |
1243 | ix = hx & 0x7FFFFFFF; |
1244 | EXTRACT_WORDS(hy, ly, y); |
1245 | iy = hy & 0x7FFFFFFF; |
1246 | if (((ix | ((lx | NegateWithWraparound<int32_t>(lx)) >> 31)) > 0x7FF00000) || |
1247 | ((iy | ((ly | NegateWithWraparound<int32_t>(ly)) >> 31)) > 0x7FF00000)) { |
1248 | return x + y; |
1249 | } |
1250 | if ((SubWithWraparound(hx, 0x3FF00000) | lx) == 0) { |
1251 | return atan(y); |
1252 | } |
1253 | m = ((hy >> 31) & 1) | ((hx >> 30) & 2); |
1254 | |
1255 | |
1256 | if ((iy | ly) == 0) { |
1257 | switch (m) { |
1258 | case 0: |
1259 | case 1: |
1260 | return y; |
1261 | case 2: |
1262 | return pi + tiny; |
1263 | case 3: |
1264 | return -pi - tiny; |
1265 | } |
1266 | } |
1267 | |
1268 | if ((ix | lx) == 0) return (hy < 0) ? -pi_o_2 - tiny : pi_o_2 + tiny; |
1269 | |
1270 | |
1271 | if (ix == 0x7FF00000) { |
1272 | if (iy == 0x7FF00000) { |
1273 | switch (m) { |
1274 | case 0: |
1275 | return pi_o_4 + tiny; |
1276 | case 1: |
1277 | return -pi_o_4 - tiny; |
1278 | case 2: |
1279 | return 3.0 * pi_o_4 + tiny; |
1280 | case 3: |
1281 | return -3.0 * pi_o_4 - tiny; |
1282 | } |
1283 | } else { |
1284 | switch (m) { |
1285 | case 0: |
1286 | return zero; |
1287 | case 1: |
1288 | return -zero; |
1289 | case 2: |
1290 | return pi + tiny; |
1291 | case 3: |
1292 | return -pi - tiny; |
1293 | } |
1294 | } |
1295 | } |
1296 | |
1297 | if (iy == 0x7FF00000) return (hy < 0) ? -pi_o_2 - tiny : pi_o_2 + tiny; |
1298 | |
1299 | |
1300 | k = (iy - ix) >> 20; |
1301 | if (k > 60) { |
1302 | z = pi_o_2 + 0.5 * pi_lo; |
1303 | m &= 1; |
1304 | } else if (hx < 0 && k < -60) { |
1305 | z = 0.0; |
1306 | } else { |
1307 | z = atan(fabs(y / x)); |
1308 | } |
1309 | switch (m) { |
1310 | case 0: |
1311 | return z; |
1312 | case 1: |
1313 | return -z; |
1314 | case 2: |
1315 | return pi - (z - pi_lo); |
1316 | default: |
1317 | return (z - pi_lo) - pi; |
1318 | } |
1319 | } |
1320 | |
1321 | |
1322 | |
1323 | |
1324 | |
1325 | |
1326 | |
1327 | |
1328 | |
1329 | |
1330 | |
1331 | |
1332 | |
1333 | |
1334 | |
1335 | |
1336 | |
1337 | |
1338 | |
1339 | |
1340 | |
1341 | |
1342 | |
1343 | |
1344 | |
1345 | |
1346 | |
1347 | |
1348 | |
1349 | |
1350 | |
1351 | double cos(double x) { |
1352 | double y[2], z = 0.0; |
1353 | int32_t n, ix; |
1354 | |
1355 | |
1356 | GET_HIGH_WORD(ix, x); |
1357 | |
1358 | |
1359 | ix &= 0x7FFFFFFF; |
1360 | if (ix <= 0x3FE921FB) { |
1361 | return __kernel_cos(x, z); |
1362 | } else if (ix >= 0x7FF00000) { |
1363 | |
1364 | return x - x; |
1365 | } else { |
1366 | |
1367 | n = __ieee754_rem_pio2(x, y); |
1368 | switch (n & 3) { |
1369 | case 0: |
1370 | return __kernel_cos(y[0], y[1]); |
1371 | case 1: |
1372 | return -__kernel_sin(y[0], y[1], 1); |
1373 | case 2: |
1374 | return -__kernel_cos(y[0], y[1]); |
1375 | default: |
1376 | return __kernel_sin(y[0], y[1], 1); |
1377 | } |
1378 | } |
1379 | } |
1380 | |
1381 | |
1382 | |
1383 | |
1384 | |
1385 | |
1386 | |
1387 | |
1388 | |
1389 | |
1390 | |
1391 | |
1392 | |
1393 | |
1394 | |
1395 | |
1396 | |
1397 | |
1398 | |
1399 | |
1400 | |
1401 | |
1402 | |
1403 | |
1404 | |
1405 | |
1406 | |
1407 | |
1408 | |
1409 | |
1410 | |
1411 | |
1412 | |
1413 | |
1414 | |
1415 | |
1416 | |
1417 | |
1418 | |
1419 | |
1420 | |
1421 | |
1422 | |
1423 | |
1424 | |
1425 | |
1426 | |
1427 | |
1428 | |
1429 | |
1430 | |
1431 | |
1432 | |
1433 | |
1434 | |
1435 | |
1436 | |
1437 | |
1438 | |
1439 | |
1440 | |
1441 | |
1442 | |
1443 | double exp(double x) { |
1444 | static const double |
1445 | one = 1.0, |
1446 | halF[2] = {0.5, -0.5}, |
1447 | o_threshold = 7.09782712893383973096e+02, |
1448 | u_threshold = -7.45133219101941108420e+02, |
1449 | ln2HI[2] = {6.93147180369123816490e-01, |
1450 | -6.93147180369123816490e-01}, |
1451 | ln2LO[2] = {1.90821492927058770002e-10, |
1452 | -1.90821492927058770002e-10}, |
1453 | invln2 = 1.44269504088896338700e+00, |
1454 | P1 = 1.66666666666666019037e-01, |
1455 | P2 = -2.77777777770155933842e-03, |
1456 | P3 = 6.61375632143793436117e-05, |
1457 | P4 = -1.65339022054652515390e-06, |
1458 | P5 = 4.13813679705723846039e-08, |
1459 | E = 2.718281828459045; |
1460 | |
1461 | static volatile double |
1462 | huge = 1.0e+300, |
1463 | twom1000 = 9.33263618503218878990e-302, |
1464 | two1023 = 8.988465674311579539e307; |
1465 | |
1466 | double y, hi = 0.0, lo = 0.0, c, t, twopk; |
1467 | int32_t k = 0, xsb; |
1468 | uint32_t hx; |
1469 | |
1470 | GET_HIGH_WORD(hx, x); |
1471 | xsb = (hx >> 31) & 1; |
1472 | hx &= 0x7FFFFFFF; |
1473 | |
1474 | |
1475 | if (hx >= 0x40862E42) { |
1476 | if (hx >= 0x7FF00000) { |
1477 | uint32_t lx; |
1478 | GET_LOW_WORD(lx, x); |
1479 | if (((hx & 0xFFFFF) | lx) != 0) |
1480 | return x + x; |
1481 | else |
1482 | return (xsb == 0) ? x : 0.0; |
1483 | } |
1484 | if (x > o_threshold) return huge * huge; |
1485 | if (x < u_threshold) return twom1000 * twom1000; |
1486 | } |
1487 | |
1488 | |
1489 | if (hx > 0x3FD62E42) { |
1490 | if (hx < 0x3FF0A2B2) { |
1491 | |
1492 | |
1493 | |
1494 | |
1495 | if (x == 1.0) return E; |
1496 | hi = x - ln2HI[xsb]; |
1497 | lo = ln2LO[xsb]; |
1498 | k = 1 - xsb - xsb; |
1499 | } else { |
1500 | k = static_cast<int>(invln2 * x + halF[xsb]); |
1501 | t = k; |
1502 | hi = x - t * ln2HI[0]; |
1503 | lo = t * ln2LO[0]; |
1504 | } |
1505 | x = hi - lo; |
1506 | } else if (hx < 0x3E300000) { |
1507 | if (huge + x > one) return one + x; |
1508 | } else { |
1509 | k = 0; |
1510 | } |
1511 | |
1512 | |
1513 | t = x * x; |
1514 | if (k >= -1021) { |
1515 | INSERT_WORDS( |
1516 | twopk, |
1517 | 0x3FF00000 + static_cast<int32_t>(static_cast<uint32_t>(k) << 20), 0); |
1518 | } else { |
1519 | INSERT_WORDS(twopk, 0x3FF00000 + (static_cast<uint32_t>(k + 1000) << 20), |
1520 | 0); |
1521 | } |
1522 | c = x - t * (P1 + t * (P2 + t * (P3 + t * (P4 + t * P5)))); |
1523 | if (k == 0) { |
1524 | return one - ((x * c) / (c - 2.0) - x); |
1525 | } else { |
1526 | y = one - ((lo - (x * c) / (2.0 - c)) - hi); |
1527 | } |
1528 | if (k >= -1021) { |
1529 | if (k == 1024) return y * 2.0 * two1023; |
1530 | return y * twopk; |
1531 | } else { |
1532 | return y * twopk * twom1000; |
1533 | } |
1534 | } |
1535 | |
1536 | |
1537 | |
1538 | |
1539 | |
1540 | |
1541 | |
1542 | |
1543 | |
1544 | |
1545 | |
1546 | |
1547 | |
1548 | |
1549 | |
1550 | |
1551 | |
1552 | |
1553 | double atanh(double x) { |
1554 | static const double one = 1.0, huge = 1e300; |
1555 | static const double zero = 0.0; |
1556 | |
1557 | double t; |
1558 | int32_t hx, ix; |
1559 | uint32_t lx; |
1560 | EXTRACT_WORDS(hx, lx, x); |
1561 | ix = hx & 0x7FFFFFFF; |
1562 | if ((ix | ((lx | NegateWithWraparound<int32_t>(lx)) >> 31)) > 0x3FF00000) { |
1563 | |
1564 | return std::numeric_limits<double>::signaling_NaN(); |
1565 | } |
1566 | if (ix == 0x3FF00000) { |
1567 | return x > 0 ? std::numeric_limits<double>::infinity() |
1568 | : -std::numeric_limits<double>::infinity(); |
1569 | } |
1570 | if (ix < 0x3E300000 && (huge + x) > zero) return x; |
1571 | SET_HIGH_WORD(x, ix); |
1572 | if (ix < 0x3FE00000) { |
1573 | t = x + x; |
1574 | t = 0.5 * log1p(t + t * x / (one - x)); |
1575 | } else { |
1576 | t = 0.5 * log1p((x + x) / (one - x)); |
1577 | } |
1578 | if (hx >= 0) |
1579 | return t; |
1580 | else |
1581 | return -t; |
1582 | } |
1583 | |
1584 | |
1585 | |
1586 | |
1587 | |
1588 | |
1589 | |
1590 | |
1591 | |
1592 | |
1593 | |
1594 | |
1595 | |
1596 | |
1597 | |
1598 | |
1599 | |
1600 | |
1601 | |
1602 | |
1603 | |
1604 | |
1605 | |
1606 | |
1607 | |
1608 | |
1609 | |
1610 | |
1611 | |
1612 | |
1613 | |
1614 | |
1615 | |
1616 | |
1617 | |
1618 | |
1619 | |
1620 | |
1621 | |
1622 | |
1623 | |
1624 | |
1625 | |
1626 | |
1627 | |
1628 | |
1629 | |
1630 | |
1631 | |
1632 | |
1633 | |
1634 | double log(double x) { |
1635 | static const double |
1636 | ln2_hi = 6.93147180369123816490e-01, |
1637 | ln2_lo = 1.90821492927058770002e-10, |
1638 | two54 = 1.80143985094819840000e+16, |
1639 | Lg1 = 6.666666666666735130e-01, |
1640 | Lg2 = 3.999999999940941908e-01, |
1641 | Lg3 = 2.857142874366239149e-01, |
1642 | Lg4 = 2.222219843214978396e-01, |
1643 | Lg5 = 1.818357216161805012e-01, |
1644 | Lg6 = 1.531383769920937332e-01, |
1645 | Lg7 = 1.479819860511658591e-01; |
1646 | |
1647 | static const double zero = 0.0; |
1648 | |
1649 | double hfsq, f, s, z, R, w, t1, t2, dk; |
1650 | int32_t k, hx, i, j; |
1651 | uint32_t lx; |
1652 | |
1653 | EXTRACT_WORDS(hx, lx, x); |
1654 | |
1655 | k = 0; |
1656 | if (hx < 0x00100000) { |
1657 | if (((hx & 0x7FFFFFFF) | lx) == 0) { |
1658 | return -std::numeric_limits<double>::infinity(); |
1659 | } |
1660 | if (hx < 0) { |
1661 | return std::numeric_limits<double>::signaling_NaN(); |
1662 | } |
1663 | k -= 54; |
1664 | x *= two54; |
1665 | GET_HIGH_WORD(hx, x); |
1666 | } |
1667 | if (hx >= 0x7FF00000) return x + x; |
1668 | k += (hx >> 20) - 1023; |
1669 | hx &= 0x000FFFFF; |
1670 | i = (hx + 0x95F64) & 0x100000; |
1671 | SET_HIGH_WORD(x, hx | (i ^ 0x3FF00000)); |
1672 | k += (i >> 20); |
1673 | f = x - 1.0; |
1674 | if ((0x000FFFFF & (2 + hx)) < 3) { |
1675 | if (f == zero) { |
1676 | if (k == 0) { |
1677 | return zero; |
1678 | } else { |
1679 | dk = static_cast<double>(k); |
1680 | return dk * ln2_hi + dk * ln2_lo; |
1681 | } |
1682 | } |
1683 | R = f * f * (0.5 - 0.33333333333333333 * f); |
1684 | if (k == 0) { |
1685 | return f - R; |
1686 | } else { |
1687 | dk = static_cast<double>(k); |
1688 | return dk * ln2_hi - ((R - dk * ln2_lo) - f); |
1689 | } |
1690 | } |
1691 | s = f / (2.0 + f); |
1692 | dk = static_cast<double>(k); |
1693 | z = s * s; |
1694 | i = hx - 0x6147A; |
1695 | w = z * z; |
1696 | j = 0x6B851 - hx; |
1697 | t1 = w * (Lg2 + w * (Lg4 + w * Lg6)); |
1698 | t2 = z * (Lg1 + w * (Lg3 + w * (Lg5 + w * Lg7))); |
1699 | i |= j; |
1700 | R = t2 + t1; |
1701 | if (i > 0) { |
1702 | hfsq = 0.5 * f * f; |
1703 | if (k == 0) |
1704 | return f - (hfsq - s * (hfsq + R)); |
1705 | else |
1706 | return dk * ln2_hi - ((hfsq - (s * (hfsq + R) + dk * ln2_lo)) - f); |
1707 | } else { |
1708 | if (k == 0) |
1709 | return f - s * (f - R); |
1710 | else |
1711 | return dk * ln2_hi - ((s * (f - R) - dk * ln2_lo) - f); |
1712 | } |
1713 | } |
1714 | |
1715 | |
1716 | |
1717 | |
1718 | |
1719 | |
1720 | |
1721 | |
1722 | |
1723 | |
1724 | |
1725 | |
1726 | |
1727 | |
1728 | |
1729 | |
1730 | |
1731 | |
1732 | |
1733 | |
1734 | |
1735 | |
1736 | |
1737 | |
1738 | |
1739 | |
1740 | |
1741 | |
1742 | |
1743 | |
1744 | |
1745 | |
1746 | |
1747 | |
1748 | |
1749 | |
1750 | |
1751 | |
1752 | |
1753 | |
1754 | |
1755 | |
1756 | |
1757 | |
1758 | |
1759 | |
1760 | |
1761 | |
1762 | |
1763 | |
1764 | |
1765 | |
1766 | |
1767 | |
1768 | |
1769 | |
1770 | |
1771 | |
1772 | |
1773 | |
1774 | |
1775 | |
1776 | |
1777 | |
1778 | |
1779 | double log1p(double x) { |
1780 | static const double |
1781 | ln2_hi = 6.93147180369123816490e-01, |
1782 | ln2_lo = 1.90821492927058770002e-10, |
1783 | two54 = 1.80143985094819840000e+16, |
1784 | Lp1 = 6.666666666666735130e-01, |
1785 | Lp2 = 3.999999999940941908e-01, |
1786 | Lp3 = 2.857142874366239149e-01, |
1787 | Lp4 = 2.222219843214978396e-01, |
1788 | Lp5 = 1.818357216161805012e-01, |
1789 | Lp6 = 1.531383769920937332e-01, |
1790 | Lp7 = 1.479819860511658591e-01; |
1791 | |
1792 | static const double zero = 0.0; |
1793 | |
1794 | double hfsq, f, c, s, z, R, u; |
1795 | int32_t k, hx, hu, ax; |
1796 | |
1797 | GET_HIGH_WORD(hx, x); |
1798 | ax = hx & 0x7FFFFFFF; |
1799 | |
1800 | k = 1; |
1801 | if (hx < 0x3FDA827A) { |
1802 | if (ax >= 0x3FF00000) { |
1803 | if (x == -1.0) |
1804 | return -std::numeric_limits<double>::infinity(); |
1805 | else |
1806 | return std::numeric_limits<double>::signaling_NaN(); |
1807 | } |
1808 | if (ax < 0x3E200000) { |
1809 | if (two54 + x > zero |
1810 | && ax < 0x3C900000) |
1811 | return x; |
1812 | else |
1813 | return x - x * x * 0.5; |
1814 | } |
1815 | if (hx > 0 || hx <= static_cast<int32_t>(0xBFD2BEC4)) { |
1816 | k = 0; |
1817 | f = x; |
1818 | hu = 1; |
1819 | } |
1820 | } |
1821 | if (hx >= 0x7FF00000) return x + x; |
1822 | if (k != 0) { |
1823 | if (hx < 0x43400000) { |
1824 | u = 1.0 + x; |
1825 | GET_HIGH_WORD(hu, u); |
1826 | k = (hu >> 20) - 1023; |
1827 | c = (k > 0) ? 1.0 - (u - x) : x - (u - 1.0); |
1828 | c /= u; |
1829 | } else { |
1830 | u = x; |
1831 | GET_HIGH_WORD(hu, u); |
1832 | k = (hu >> 20) - 1023; |
1833 | c = 0; |
1834 | } |
1835 | hu &= 0x000FFFFF; |
1836 | |
1837 | |
1838 | |
1839 | |
1840 | |
1841 | |
1842 | |
1843 | if (hu < 0x6A09E) { |
1844 | SET_HIGH_WORD(u, hu | 0x3FF00000); |
1845 | } else { |
1846 | k += 1; |
1847 | SET_HIGH_WORD(u, hu | 0x3FE00000); |
1848 | hu = (0x00100000 - hu) >> 2; |
1849 | } |
1850 | f = u - 1.0; |
1851 | } |
1852 | hfsq = 0.5 * f * f; |
1853 | if (hu == 0) { |
1854 | if (f == zero) { |
1855 | if (k == 0) { |
1856 | return zero; |
1857 | } else { |
1858 | c += k * ln2_lo; |
1859 | return k * ln2_hi + c; |
1860 | } |
1861 | } |
1862 | R = hfsq * (1.0 - 0.66666666666666666 * f); |
1863 | if (k == 0) |
1864 | return f - R; |
1865 | else |
1866 | return k * ln2_hi - ((R - (k * ln2_lo + c)) - f); |
1867 | } |
1868 | s = f / (2.0 + f); |
1869 | z = s * s; |
1870 | R = z * (Lp1 + |
1871 | z * (Lp2 + z * (Lp3 + z * (Lp4 + z * (Lp5 + z * (Lp6 + z * Lp7)))))); |
1872 | if (k == 0) |
1873 | return f - (hfsq - s * (hfsq + R)); |
1874 | else |
1875 | return k * ln2_hi - ((hfsq - (s * (hfsq + R) + (k * ln2_lo + c))) - f); |
1876 | } |
1877 | |
1878 | |
1879 | |
1880 | |
1881 | |
1882 | |
1883 | |
1884 | |
1885 | |
1886 | |
1887 | |
1888 | |
1889 | |
1890 | |
1891 | |
1892 | |
1893 | |
1894 | |
1895 | |
1896 | |
1897 | |
1898 | |
1899 | |
1900 | |
1901 | |
1902 | |
1903 | |
1904 | |
1905 | |
1906 | |
1907 | |
1908 | |
1909 | |
1910 | |
1911 | |
1912 | |
1913 | |
1914 | |
1915 | |
1916 | |
1917 | |
1918 | |
1919 | |
1920 | |
1921 | |
1922 | |
1923 | |
1924 | |
1925 | |
1926 | |
1927 | |
1928 | |
1929 | |
1930 | |
1931 | |
1932 | |
1933 | |
1934 | |
1935 | static const double Lg1 = 6.666666666666735130e-01, |
1936 | Lg2 = 3.999999999940941908e-01, |
1937 | Lg3 = 2.857142874366239149e-01, |
1938 | Lg4 = 2.222219843214978396e-01, |
1939 | Lg5 = 1.818357216161805012e-01, |
1940 | Lg6 = 1.531383769920937332e-01, |
1941 | Lg7 = 1.479819860511658591e-01; |
1942 | |
1943 | |
1944 | |
1945 | |
1946 | |
1947 | static inline double k_log1p(double f) { |
1948 | double hfsq, s, z, R, w, t1, t2; |
1949 | |
1950 | s = f / (2.0 + f); |
1951 | z = s * s; |
1952 | w = z * z; |
1953 | t1 = w * (Lg2 + w * (Lg4 + w * Lg6)); |
1954 | t2 = z * (Lg1 + w * (Lg3 + w * (Lg5 + w * Lg7))); |
1955 | R = t2 + t1; |
1956 | hfsq = 0.5 * f * f; |
1957 | return s * (hfsq + R); |
1958 | } |
1959 | |
1960 | |
1961 | |
1962 | |
1963 | |
1964 | |
1965 | |
1966 | |
1967 | |
1968 | |
1969 | double log2(double x) { |
1970 | static const double |
1971 | two54 = 1.80143985094819840000e+16, |
1972 | ivln2hi = 1.44269504072144627571e+00, |
1973 | ivln2lo = 1.67517131648865118353e-10; |
1974 | |
1975 | double f, hfsq, hi, lo, r, val_hi, val_lo, w, y; |
1976 | int32_t i, k, hx; |
1977 | uint32_t lx; |
1978 | |
1979 | EXTRACT_WORDS(hx, lx, x); |
1980 | |
1981 | k = 0; |
1982 | if (hx < 0x00100000) { |
1983 | if (((hx & 0x7FFFFFFF) | lx) == 0) { |
1984 | return -std::numeric_limits<double>::infinity(); |
1985 | } |
1986 | if (hx < 0) { |
1987 | return std::numeric_limits<double>::signaling_NaN(); |
1988 | } |
1989 | k -= 54; |
1990 | x *= two54; |
1991 | GET_HIGH_WORD(hx, x); |
1992 | } |
1993 | if (hx >= 0x7FF00000) return x + x; |
1994 | if (hx == 0x3FF00000 && lx == 0) return 0.0; |
1995 | k += (hx >> 20) - 1023; |
1996 | hx &= 0x000FFFFF; |
1997 | i = (hx + 0x95F64) & 0x100000; |
1998 | SET_HIGH_WORD(x, hx | (i ^ 0x3FF00000)); |
1999 | k += (i >> 20); |
2000 | y = static_cast<double>(k); |
2001 | f = x - 1.0; |
2002 | hfsq = 0.5 * f * f; |
2003 | r = k_log1p(f); |
2004 | |
2005 | |
2006 | |
2007 | |
2008 | |
2009 | |
2010 | |
2011 | |
2012 | |
2013 | |
2014 | |
2015 | |
2016 | |
2017 | |
2018 | |
2019 | |
2020 | |
2021 | |
2022 | |
2023 | |
2024 | |
2025 | |
2026 | |
2027 | |
2028 | |
2029 | |
2030 | |
2031 | |
2032 | |
2033 | |
2034 | |
2035 | hi = f - hfsq; |
2036 | SET_LOW_WORD(hi, 0); |
2037 | lo = (f - hi) - hfsq + r; |
2038 | val_hi = hi * ivln2hi; |
2039 | val_lo = (lo + hi) * ivln2lo + lo * ivln2hi; |
2040 | |
2041 | |
2042 | w = y + val_hi; |
2043 | val_lo += (y - w) + val_hi; |
2044 | val_hi = w; |
2045 | |
2046 | return val_lo + val_hi; |
2047 | } |
2048 | |
2049 | |
2050 | |
2051 | |
2052 | |
2053 | |
2054 | |
2055 | |
2056 | |
2057 | |
2058 | |
2059 | |
2060 | |
2061 | |
2062 | |
2063 | |
2064 | |
2065 | |
2066 | |
2067 | |
2068 | |
2069 | |
2070 | |
2071 | |
2072 | |
2073 | |
2074 | |
2075 | double log10(double x) { |
2076 | static const double |
2077 | two54 = 1.80143985094819840000e+16, |
2078 | ivln10 = 4.34294481903251816668e-01, |
2079 | log10_2hi = 3.01029995663611771306e-01, |
2080 | log10_2lo = 3.69423907715893078616e-13; |
2081 | |
2082 | double y; |
2083 | int32_t i, k, hx; |
2084 | uint32_t lx; |
2085 | |
2086 | EXTRACT_WORDS(hx, lx, x); |
2087 | |
2088 | k = 0; |
2089 | if (hx < 0x00100000) { |
2090 | if (((hx & 0x7FFFFFFF) | lx) == 0) { |
2091 | return -std::numeric_limits<double>::infinity(); |
2092 | } |
2093 | if (hx < 0) { |
2094 | return std::numeric_limits<double>::quiet_NaN(); |
2095 | } |
2096 | k -= 54; |
2097 | x *= two54; |
2098 | GET_HIGH_WORD(hx, x); |
2099 | GET_LOW_WORD(lx, x); |
2100 | } |
2101 | if (hx >= 0x7FF00000) return x + x; |
2102 | if (hx == 0x3FF00000 && lx == 0) return 0.0; |
2103 | k += (hx >> 20) - 1023; |
2104 | |
2105 | i = (k & 0x80000000) >> 31; |
2106 | hx = (hx & 0x000FFFFF) | ((0x3FF - i) << 20); |
2107 | y = k + i; |
2108 | SET_HIGH_WORD(x, hx); |
2109 | SET_LOW_WORD(x, lx); |
2110 | |
2111 | double z = y * log10_2lo + ivln10 * log(x); |
2112 | return z + y * log10_2hi; |
2113 | } |
2114 | |
2115 | |
2116 | |
2117 | |
2118 | |
2119 | |
2120 | |
2121 | |
2122 | |
2123 | |
2124 | |
2125 | |
2126 | |
2127 | |
2128 | |
2129 | |
2130 | |
2131 | |
2132 | |
2133 | |
2134 | |
2135 | |
2136 | |
2137 | |
2138 | |
2139 | |
2140 | |
2141 | |
2142 | |
2143 | |
2144 | |
2145 | |
2146 | |
2147 | |
2148 | |
2149 | |
2150 | |
2151 | |
2152 | |
2153 | |
2154 | |
2155 | |
2156 | |
2157 | |
2158 | |
2159 | |
2160 | |
2161 | |
2162 | |
2163 | |
2164 | |
2165 | |
2166 | |
2167 | |
2168 | |
2169 | |
2170 | |
2171 | |
2172 | |
2173 | |
2174 | |
2175 | |
2176 | |
2177 | |
2178 | |
2179 | |
2180 | |
2181 | |
2182 | |
2183 | |
2184 | |
2185 | |
2186 | |
2187 | |
2188 | |
2189 | |
2190 | |
2191 | |
2192 | |
2193 | |
2194 | |
2195 | |
2196 | |
2197 | |
2198 | |
2199 | |
2200 | |
2201 | |
2202 | |
2203 | |
2204 | |
2205 | |
2206 | |
2207 | |
2208 | |
2209 | double expm1(double x) { |
2210 | static const double |
2211 | one = 1.0, |
2212 | tiny = 1.0e-300, |
2213 | o_threshold = 7.09782712893383973096e+02, |
2214 | ln2_hi = 6.93147180369123816490e-01, |
2215 | ln2_lo = 1.90821492927058770002e-10, |
2216 | invln2 = 1.44269504088896338700e+00, |
2217 | |
2218 | |
2219 | Q1 = -3.33333333333331316428e-02, |
2220 | Q2 = 1.58730158725481460165e-03, |
2221 | Q3 = -7.93650757867487942473e-05, |
2222 | Q4 = 4.00821782732936239552e-06, |
2223 | Q5 = -2.01099218183624371326e-07; |
2224 | |
2225 | static volatile double huge = 1.0e+300; |
2226 | |
2227 | double y, hi, lo, c, t, e, hxs, hfx, r1, twopk; |
2228 | int32_t k, xsb; |
2229 | uint32_t hx; |
2230 | |
2231 | GET_HIGH_WORD(hx, x); |
2232 | xsb = hx & 0x80000000; |
2233 | hx &= 0x7FFFFFFF; |
2234 | |
2235 | |
2236 | if (hx >= 0x4043687A) { |
2237 | if (hx >= 0x40862E42) { |
2238 | if (hx >= 0x7FF00000) { |
2239 | uint32_t low; |
2240 | GET_LOW_WORD(low, x); |
2241 | if (((hx & 0xFFFFF) | low) != 0) |
2242 | return x + x; |
2243 | else |
2244 | return (xsb == 0) ? x : -1.0; |
2245 | } |
2246 | if (x > o_threshold) return huge * huge; |
2247 | } |
2248 | if (xsb != 0) { |
2249 | if (x + tiny < 0.0) |
2250 | return tiny - one; |
2251 | } |
2252 | } |
2253 | |
2254 | |
2255 | if (hx > 0x3FD62E42) { |
2256 | if (hx < 0x3FF0A2B2) { |
2257 | if (xsb == 0) { |
2258 | hi = x - ln2_hi; |
2259 | lo = ln2_lo; |
2260 | k = 1; |
2261 | } else { |
2262 | hi = x + ln2_hi; |
2263 | lo = -ln2_lo; |
2264 | k = -1; |
2265 | } |
2266 | } else { |
2267 | k = invln2 * x + ((xsb == 0) ? 0.5 : -0.5); |
2268 | t = k; |
2269 | hi = x - t * ln2_hi; |
2270 | lo = t * ln2_lo; |
2271 | } |
2272 | x = hi - lo; |
2273 | c = (hi - x) - lo; |
2274 | } else if (hx < 0x3C900000) { |
2275 | t = huge + x; |
2276 | return x - (t - (huge + x)); |
2277 | } else { |
2278 | k = 0; |
2279 | } |
2280 | |
2281 | |
2282 | hfx = 0.5 * x; |
2283 | hxs = x * hfx; |
2284 | r1 = one + hxs * (Q1 + hxs * (Q2 + hxs * (Q3 + hxs * (Q4 + hxs * Q5)))); |
2285 | t = 3.0 - r1 * hfx; |
2286 | e = hxs * ((r1 - t) / (6.0 - x * t)); |
2287 | if (k == 0) { |
2288 | return x - (x * e - hxs); |
2289 | } else { |
2290 | INSERT_WORDS( |
2291 | twopk, |
2292 | 0x3FF00000 + static_cast<int32_t>(static_cast<uint32_t>(k) << 20), |
2293 | 0); |
2294 | e = (x * (e - c) - c); |
2295 | e -= hxs; |
2296 | if (k == -1) return 0.5 * (x - e) - 0.5; |
2297 | if (k == 1) { |
2298 | if (x < -0.25) |
2299 | return -2.0 * (e - (x + 0.5)); |
2300 | else |
2301 | return one + 2.0 * (x - e); |
2302 | } |
2303 | if (k <= -2 || k > 56) { |
2304 | y = one - (e - x); |
2305 | |
2306 | |
2307 | |
2308 | if (k == 1024) |
2309 | y = y * 2.0 * 8.98846567431158e+307; |
2310 | else |
2311 | y = y * twopk; |
2312 | return y - one; |
2313 | } |
2314 | t = one; |
2315 | if (k < 20) { |
2316 | SET_HIGH_WORD(t, 0x3FF00000 - (0x200000 >> k)); |
2317 | y = t - (e - x); |
2318 | y = y * twopk; |
2319 | } else { |
2320 | SET_HIGH_WORD(t, ((0x3FF - k) << 20)); |
2321 | y = x - (e + t); |
2322 | y += one; |
2323 | y = y * twopk; |
2324 | } |
2325 | } |
2326 | return y; |
2327 | } |
2328 | |
2329 | double cbrt(double x) { |
2330 | static const uint32_t |
2331 | B1 = 715094163, |
2332 | B2 = 696219795; |
2333 | |
2334 | |
2335 | static const double P0 = 1.87595182427177009643, |
2336 | P1 = -1.88497979543377169875, |
2337 | P2 = 1.621429720105354466140, |
2338 | P3 = -0.758397934778766047437, |
2339 | P4 = 0.145996192886612446982; |
2340 | |
2341 | int32_t hx; |
2342 | double r, s, t = 0.0, w; |
2343 | uint32_t sign; |
2344 | uint32_t high, low; |
2345 | |
2346 | EXTRACT_WORDS(hx, low, x); |
2347 | sign = hx & 0x80000000; |
2348 | hx ^= sign; |
2349 | if (hx >= 0x7FF00000) return (x + x); |
2350 | |
2351 | |
2352 | |
2353 | |
2354 | |
2355 | |
2356 | |
2357 | |
2358 | |
2359 | |
2360 | |
2361 | |
2362 | |
2363 | |
2364 | |
2365 | |
2366 | if (hx < 0x00100000) { |
2367 | if ((hx | low) == 0) return (x); |
2368 | SET_HIGH_WORD(t, 0x43500000); |
2369 | t *= x; |
2370 | GET_HIGH_WORD(high, t); |
2371 | INSERT_WORDS(t, sign | ((high & 0x7FFFFFFF) / 3 + B2), 0); |
2372 | } else { |
2373 | INSERT_WORDS(t, sign | (hx / 3 + B1), 0); |
2374 | } |
2375 | |
2376 | |
2377 | |
2378 | |
2379 | |
2380 | |
2381 | |
2382 | |
2383 | |
2384 | |
2385 | |
2386 | r = (t * t) * (t / x); |
2387 | t = t * ((P0 + r * (P1 + r * P2)) + ((r * r) * r) * (P3 + r * P4)); |
2388 | |
2389 | |
2390 | |
2391 | |
2392 | |
2393 | |
2394 | |
2395 | |
2396 | |
2397 | |
2398 | |
2399 | uint64_t bits = bit_cast<uint64_t>(t); |
2400 | bits = (bits + 0x80000000) & 0xFFFFFFFFC0000000ULL; |
2401 | t = bit_cast<double>(bits); |
2402 | |
2403 | |
2404 | s = t * t; |
2405 | r = x / s; |
2406 | w = t + t; |
2407 | r = (r - t) / (w + r); |
2408 | t = t + t * r; |
2409 | |
2410 | return (t); |
2411 | } |
2412 | |
2413 | |
2414 | |
2415 | |
2416 | |
2417 | |
2418 | |
2419 | |
2420 | |
2421 | |
2422 | |
2423 | |
2424 | |
2425 | |
2426 | |
2427 | |
2428 | |
2429 | |
2430 | |
2431 | |
2432 | |
2433 | |
2434 | |
2435 | |
2436 | |
2437 | |
2438 | |
2439 | |
2440 | |
2441 | |
2442 | |
2443 | double sin(double x) { |
2444 | double y[2], z = 0.0; |
2445 | int32_t n, ix; |
2446 | |
2447 | |
2448 | GET_HIGH_WORD(ix, x); |
2449 | |
2450 | |
2451 | ix &= 0x7FFFFFFF; |
2452 | if (ix <= 0x3FE921FB) { |
2453 | return __kernel_sin(x, z, 0); |
2454 | } else if (ix >= 0x7FF00000) { |
2455 | |
2456 | return x - x; |
2457 | } else { |
2458 | |
2459 | n = __ieee754_rem_pio2(x, y); |
2460 | switch (n & 3) { |
2461 | case 0: |
2462 | return __kernel_sin(y[0], y[1], 1); |
2463 | case 1: |
2464 | return __kernel_cos(y[0], y[1]); |
2465 | case 2: |
2466 | return -__kernel_sin(y[0], y[1], 1); |
2467 | default: |
2468 | return -__kernel_cos(y[0], y[1]); |
2469 | } |
2470 | } |
2471 | } |
2472 | |
2473 | |
2474 | |
2475 | |
2476 | |
2477 | |
2478 | |
2479 | |
2480 | |
2481 | |
2482 | |
2483 | |
2484 | |
2485 | |
2486 | |
2487 | |
2488 | |
2489 | |
2490 | |
2491 | |
2492 | |
2493 | |
2494 | |
2495 | |
2496 | |
2497 | |
2498 | |
2499 | |
2500 | |
2501 | |
2502 | double tan(double x) { |
2503 | double y[2], z = 0.0; |
2504 | int32_t n, ix; |
2505 | |
2506 | |
2507 | GET_HIGH_WORD(ix, x); |
2508 | |
2509 | |
2510 | ix &= 0x7FFFFFFF; |
2511 | if (ix <= 0x3FE921FB) { |
2512 | return __kernel_tan(x, z, 1); |
2513 | } else if (ix >= 0x7FF00000) { |
2514 | |
2515 | return x - x; |
2516 | } else { |
2517 | |
2518 | n = __ieee754_rem_pio2(x, y); |
2519 | |
2520 | return __kernel_tan(y[0], y[1], 1 - ((n & 1) << 1)); |
2521 | } |
2522 | } |
2523 | |
2524 | |
2525 | |
2526 | |
2527 | |
2528 | |
2529 | |
2530 | |
2531 | |
2532 | |
2533 | |
2534 | |
2535 | |
2536 | |
2537 | |
2538 | |
2539 | |
2540 | |
2541 | |
2542 | |
2543 | |
2544 | |
2545 | |
2546 | double cosh(double x) { |
2547 | static const double KCOSH_OVERFLOW = 710.4758600739439; |
2548 | static const double one = 1.0, half = 0.5; |
2549 | static volatile double huge = 1.0e+300; |
2550 | |
2551 | int32_t ix; |
2552 | |
2553 | |
2554 | GET_HIGH_WORD(ix, x); |
2555 | ix &= 0x7FFFFFFF; |
2556 | |
2557 | |
2558 | if (ix < 0x3FD62E43) { |
2559 | double t = expm1(fabs(x)); |
2560 | double w = one + t; |
2561 | |
2562 | if (ix < 0x3C800000) return w; |
2563 | return one + (t * t) / (w + w); |
2564 | } |
2565 | |
2566 | |
2567 | if (ix < 0x40360000) { |
2568 | double t = exp(fabs(x)); |
2569 | return half * t + half / t; |
2570 | } |
2571 | |
2572 | |
2573 | if (ix < 0x40862E42) return half * exp(fabs(x)); |
2574 | |
2575 | |
2576 | if (fabs(x) <= KCOSH_OVERFLOW) { |
2577 | double w = exp(half * fabs(x)); |
2578 | double t = half * w; |
2579 | return t * w; |
2580 | } |
2581 | |
2582 | |
2583 | if (ix >= 0x7FF00000) return x * x; |
2584 | |
2585 | |
2586 | return huge * huge; |
2587 | } |
2588 | |
2589 | |
2590 | |
2591 | |
2592 | |
2593 | |
2594 | |
2595 | |
2596 | |
2597 | |
2598 | |
2599 | |
2600 | |
2601 | |
2602 | |
2603 | |
2604 | |
2605 | |
2606 | |
2607 | |
2608 | |
2609 | |
2610 | |
2611 | |
2612 | |
2613 | |
2614 | |
2615 | |
2616 | |
2617 | |
2618 | |
2619 | |
2620 | |
2621 | |
2622 | |
2623 | |
2624 | |
2625 | |
2626 | |
2627 | |
2628 | |
2629 | |
2630 | |
2631 | |
2632 | |
2633 | |
2634 | |
2635 | |
2636 | |
2637 | double pow(double x, double y) { |
2638 | static const double |
2639 | bp[] = {1.0, 1.5}, |
2640 | dp_h[] = {0.0, 5.84962487220764160156e-01}, |
2641 | dp_l[] = {0.0, 1.35003920212974897128e-08}, |
2642 | zero = 0.0, one = 1.0, two = 2.0, |
2643 | two53 = 9007199254740992.0, |
2644 | huge = 1.0e300, tiny = 1.0e-300, |
2645 | |
2646 | L1 = 5.99999999999994648725e-01, |
2647 | L2 = 4.28571428578550184252e-01, |
2648 | L3 = 3.33333329818377432918e-01, |
2649 | L4 = 2.72728123808534006489e-01, |
2650 | L5 = 2.30660745775561754067e-01, |
2651 | L6 = 2.06975017800338417784e-01, |
2652 | P1 = 1.66666666666666019037e-01, |
2653 | P2 = -2.77777777770155933842e-03, |
2654 | P3 = 6.61375632143793436117e-05, |
2655 | P4 = -1.65339022054652515390e-06, |
2656 | P5 = 4.13813679705723846039e-08, |
2657 | lg2 = 6.93147180559945286227e-01, |
2658 | lg2_h = 6.93147182464599609375e-01, |
2659 | lg2_l = -1.90465429995776804525e-09, |
2660 | ovt = 8.0085662595372944372e-0017, |
2661 | cp = 9.61796693925975554329e-01, |
2662 | cp_h = 9.61796700954437255859e-01, |
2663 | cp_l = -7.02846165095275826516e-09, |
2664 | ivln2 = 1.44269504088896338700e+00, |
2665 | ivln2_h = |
2666 | 1.44269502162933349609e+00, |
2667 | ivln2_l = |
2668 | 1.92596299112661746887e-08; |
2669 | |
2670 | double z, ax, z_h, z_l, p_h, p_l; |
2671 | double y1, t1, t2, r, s, t, u, v, w; |
2672 | int i, j, k, yisint, n; |
2673 | int hx, hy, ix, iy; |
2674 | unsigned lx, ly; |
2675 | |
2676 | EXTRACT_WORDS(hx, lx, x); |
2677 | EXTRACT_WORDS(hy, ly, y); |
2678 | ix = hx & 0x7fffffff; |
2679 | iy = hy & 0x7fffffff; |
2680 | |
2681 | |
2682 | if ((iy | ly) == 0) return one; |
2683 | |
2684 | |
2685 | if (ix > 0x7ff00000 || ((ix == 0x7ff00000) && (lx != 0)) || iy > 0x7ff00000 || |
2686 | ((iy == 0x7ff00000) && (ly != 0))) { |
2687 | return x + y; |
2688 | } |
2689 | |
2690 | |
2691 | |
2692 | |
2693 | |
2694 | |
2695 | yisint = 0; |
2696 | if (hx < 0) { |
2697 | if (iy >= 0x43400000) { |
2698 | yisint = 2; |
2699 | } else if (iy >= 0x3ff00000) { |
2700 | k = (iy >> 20) - 0x3ff; |
2701 | if (k > 20) { |
2702 | j = ly >> (52 - k); |
2703 | if ((j << (52 - k)) == static_cast<int>(ly)) yisint = 2 - (j & 1); |
2704 | } else if (ly == 0) { |
2705 | j = iy >> (20 - k); |
2706 | if ((j << (20 - k)) == iy) yisint = 2 - (j & 1); |
2707 | } |
2708 | } |
2709 | } |
2710 | |
2711 | |
2712 | if (ly == 0) { |
2713 | if (iy == 0x7ff00000) { |
2714 | if (((ix - 0x3ff00000) | lx) == 0) { |
2715 | return y - y; |
2716 | } else if (ix >= 0x3ff00000) { |
2717 | return (hy >= 0) ? y : zero; |
2718 | } else { |
2719 | return (hy < 0) ? -y : zero; |
2720 | } |
2721 | } |
2722 | if (iy == 0x3ff00000) { |
2723 | if (hy < 0) { |
2724 | return base::Divide(one, x); |
2725 | } else { |
2726 | return x; |
2727 | } |
2728 | } |
2729 | if (hy == 0x40000000) return x * x; |
2730 | if (hy == 0x3fe00000) { |
2731 | if (hx >= 0) { |
2732 | return sqrt(x); |
2733 | } |
2734 | } |
2735 | } |
2736 | |
2737 | ax = fabs(x); |
2738 | |
2739 | if (lx == 0) { |
2740 | if (ix == 0x7ff00000 || ix == 0 || ix == 0x3ff00000) { |
2741 | z = ax; |
2742 | if (hy < 0) z = base::Divide(one, z); |
2743 | if (hx < 0) { |
2744 | if (((ix - 0x3ff00000) | yisint) == 0) { |
2745 | |
2746 | z = std::numeric_limits<double>::signaling_NaN(); |
2747 | } else if (yisint == 1) { |
2748 | z = -z; |
2749 | } |
2750 | } |
2751 | return z; |
2752 | } |
2753 | } |
2754 | |
2755 | n = (hx >> 31) + 1; |
2756 | |
2757 | |
2758 | if ((n | yisint) == 0) { |
2759 | return std::numeric_limits<double>::signaling_NaN(); |
2760 | } |
2761 | |
2762 | s = one; |
2763 | if ((n | (yisint - 1)) == 0) s = -one; |
2764 | |
2765 | |
2766 | if (iy > 0x41e00000) { |
2767 | if (iy > 0x43f00000) { |
2768 | if (ix <= 0x3fefffff) return (hy < 0) ? huge * huge : tiny * tiny; |
2769 | if (ix >= 0x3ff00000) return (hy > 0) ? huge * huge : tiny * tiny; |
2770 | } |
2771 | |
2772 | if (ix < 0x3fefffff) return (hy < 0) ? s * huge * huge : s * tiny * tiny; |
2773 | if (ix > 0x3ff00000) return (hy > 0) ? s * huge * huge : s * tiny * tiny; |
2774 | |
2775 | |
2776 | t = ax - one; |
2777 | w = (t * t) * (0.5 - t * (0.3333333333333333333333 - t * 0.25)); |
2778 | u = ivln2_h * t; |
2779 | v = t * ivln2_l - w * ivln2; |
2780 | t1 = u + v; |
2781 | SET_LOW_WORD(t1, 0); |
2782 | t2 = v - (t1 - u); |
2783 | } else { |
2784 | double ss, s2, s_h, s_l, t_h, t_l; |
2785 | n = 0; |
2786 | |
2787 | if (ix < 0x00100000) { |
2788 | ax *= two53; |
2789 | n -= 53; |
2790 | GET_HIGH_WORD(ix, ax); |
2791 | } |
2792 | n += ((ix) >> 20) - 0x3ff; |
2793 | j = ix & 0x000fffff; |
2794 | |
2795 | ix = j | 0x3ff00000; |
2796 | if (j <= 0x3988E) { |
2797 | k = 0; |
2798 | } else if (j < 0xBB67A) { |
2799 | k = 1; |
2800 | } else { |
2801 | k = 0; |
2802 | n += 1; |
2803 | ix -= 0x00100000; |
2804 | } |
2805 | SET_HIGH_WORD(ax, ix); |
2806 | |
2807 | |
2808 | u = ax - bp[k]; |
2809 | v = base::Divide(one, ax + bp[k]); |
2810 | ss = u * v; |
2811 | s_h = ss; |
2812 | SET_LOW_WORD(s_h, 0); |
2813 | |
2814 | t_h = zero; |
2815 | SET_HIGH_WORD(t_h, ((ix >> 1) | 0x20000000) + 0x00080000 + (k << 18)); |
2816 | t_l = ax - (t_h - bp[k]); |
2817 | s_l = v * ((u - s_h * t_h) - s_h * t_l); |
2818 | |
2819 | s2 = ss * ss; |
2820 | r = s2 * s2 * |
2821 | (L1 + s2 * (L2 + s2 * (L3 + s2 * (L4 + s2 * (L5 + s2 * L6))))); |
2822 | r += s_l * (s_h + ss); |
2823 | s2 = s_h * s_h; |
2824 | t_h = 3.0 + s2 + r; |
2825 | SET_LOW_WORD(t_h, 0); |
2826 | t_l = r - ((t_h - 3.0) - s2); |
2827 | |
2828 | u = s_h * t_h; |
2829 | v = s_l * t_h + t_l * ss; |
2830 | |
2831 | p_h = u + v; |
2832 | SET_LOW_WORD(p_h, 0); |
2833 | p_l = v - (p_h - u); |
2834 | z_h = cp_h * p_h; |
2835 | z_l = cp_l * p_h + p_l * cp + dp_l[k]; |
2836 | |
2837 | t = static_cast<double>(n); |
2838 | t1 = (((z_h + z_l) + dp_h[k]) + t); |
2839 | SET_LOW_WORD(t1, 0); |
2840 | t2 = z_l - (((t1 - t) - dp_h[k]) - z_h); |
2841 | } |
2842 | |
2843 | |
2844 | y1 = y; |
2845 | SET_LOW_WORD(y1, 0); |
2846 | p_l = (y - y1) * t1 + y * t2; |
2847 | p_h = y1 * t1; |
2848 | z = p_l + p_h; |
2849 | EXTRACT_WORDS(j, i, z); |
2850 | if (j >= 0x40900000) { |
2851 | if (((j - 0x40900000) | i) != 0) { |
2852 | return s * huge * huge; |
2853 | } else { |
2854 | if (p_l + ovt > z - p_h) return s * huge * huge; |
2855 | } |
2856 | } else if ((j & 0x7fffffff) >= 0x4090cc00) { |
2857 | if (((j - 0xc090cc00) | i) != 0) { |
2858 | return s * tiny * tiny; |
2859 | } else { |
2860 | if (p_l <= z - p_h) return s * tiny * tiny; |
2861 | } |
2862 | } |
2863 | |
2864 | |
2865 | |
2866 | i = j & 0x7fffffff; |
2867 | k = (i >> 20) - 0x3ff; |
2868 | n = 0; |
2869 | if (i > 0x3fe00000) { |
2870 | n = j + (0x00100000 >> (k + 1)); |
2871 | k = ((n & 0x7fffffff) >> 20) - 0x3ff; |
2872 | t = zero; |
2873 | SET_HIGH_WORD(t, n & ~(0x000fffff >> k)); |
2874 | n = ((n & 0x000fffff) | 0x00100000) >> (20 - k); |
2875 | if (j < 0) n = -n; |
2876 | p_h -= t; |
2877 | } |
2878 | t = p_l + p_h; |
2879 | SET_LOW_WORD(t, 0); |
2880 | u = t * lg2_h; |
2881 | v = (p_l - (t - p_h)) * lg2 + t * lg2_l; |
2882 | z = u + v; |
2883 | w = v - (z - u); |
2884 | t = z * z; |
2885 | t1 = z - t * (P1 + t * (P2 + t * (P3 + t * (P4 + t * P5)))); |
2886 | r = base::Divide(z * t1, (t1 - two) - (w + z * w)); |
2887 | z = one - (r - z); |
2888 | GET_HIGH_WORD(j, z); |
2889 | j += static_cast<int>(static_cast<uint32_t>(n) << 20); |
2890 | if ((j >> 20) <= 0) { |
2891 | z = scalbn(z, n); |
2892 | } else { |
2893 | int tmp; |
2894 | GET_HIGH_WORD(tmp, z); |
2895 | SET_HIGH_WORD(z, tmp + static_cast<int>(static_cast<uint32_t>(n) << 20)); |
2896 | } |
2897 | return s * z; |
2898 | } |
2899 | |
2900 | |
2901 | |
2902 | |
2903 | |
2904 | |
2905 | |
2906 | |
2907 | |
2908 | |
2909 | |
2910 | |
2911 | |
2912 | |
2913 | |
2914 | |
2915 | |
2916 | |
2917 | |
2918 | |
2919 | double sinh(double x) { |
2920 | static const double KSINH_OVERFLOW = 710.4758600739439, |
2921 | TWO_M28 = |
2922 | 3.725290298461914e-9, |
2923 | LOG_MAXD = 709.7822265625; |
2924 | static const double shuge = 1.0e307; |
2925 | |
2926 | double h = (x < 0) ? -0.5 : 0.5; |
2927 | |
2928 | double ax = fabs(x); |
2929 | if (ax < 22) { |
2930 | |
2931 | if (ax < TWO_M28) return x; |
2932 | double t = expm1(ax); |
2933 | if (ax < 1) { |
2934 | return h * (2 * t - t * t / (t + 1)); |
2935 | } |
2936 | return h * (t + t / (t + 1)); |
2937 | } |
2938 | |
2939 | if (ax < LOG_MAXD) return h * exp(ax); |
2940 | |
2941 | |
2942 | if (ax <= KSINH_OVERFLOW) { |
2943 | double w = exp(0.5 * ax); |
2944 | double t = h * w; |
2945 | return t * w; |
2946 | } |
2947 | |
2948 | |
2949 | return x * shuge; |
2950 | } |
2951 | |
2952 | |
2953 | |
2954 | |
2955 | |
2956 | |
2957 | |
2958 | |
2959 | |
2960 | |
2961 | |
2962 | |
2963 | |
2964 | |
2965 | |
2966 | |
2967 | |
2968 | |
2969 | |
2970 | |
2971 | |
2972 | |
2973 | |
2974 | |
2975 | double tanh(double x) { |
2976 | static const volatile double tiny = 1.0e-300; |
2977 | static const double one = 1.0, two = 2.0, huge = 1.0e300; |
2978 | double t, z; |
2979 | int32_t jx, ix; |
2980 | |
2981 | GET_HIGH_WORD(jx, x); |
2982 | ix = jx & 0x7FFFFFFF; |
2983 | |
2984 | |
2985 | if (ix >= 0x7FF00000) { |
2986 | if (jx >= 0) |
2987 | return one / x + one; |
2988 | else |
2989 | return one / x - one; |
2990 | } |
2991 | |
2992 | |
2993 | if (ix < 0x40360000) { |
2994 | if (ix < 0x3E300000) { |
2995 | if (huge + x > one) return x; |
2996 | } |
2997 | if (ix >= 0x3FF00000) { |
2998 | t = expm1(two * fabs(x)); |
2999 | z = one - two / (t + two); |
3000 | } else { |
3001 | t = expm1(-two * fabs(x)); |
3002 | z = -t / (t + two); |
3003 | } |
3004 | |
3005 | } else { |
3006 | z = one - tiny; |
3007 | } |
3008 | return (jx >= 0) ? z : -z; |
3009 | } |
3010 | |
3011 | #undef EXTRACT_WORDS |
3012 | #undef GET_HIGH_WORD |
3013 | #undef GET_LOW_WORD |
3014 | #undef INSERT_WORDS |
3015 | #undef SET_HIGH_WORD |
3016 | #undef SET_LOW_WORD |
3017 | |
3018 | } |
3019 | } |
3020 | } |