A modern Music Player Daemon based on Rockbox open source high quality audio player
libadwaita audio rust zig deno mpris rockbox mpd
at master 1476 lines 48 kB view raw
1#include "plugin.h" 2 3#include "fixedpoint.h" 4 5#include <SDL.h> 6 7extern bool printf_enabled; 8 9/* fixed-point wrappers */ 10static unsigned long lastphase = 0; 11static long lastsin = 0, lastcos = 0x7fffffff; 12 13#define PI 3.1415926535897932384626433832795 14 15void fatal(char *fmt, ...) 16{ 17 va_list ap; 18 19 rb->splash(HZ, "FATAL"); 20 21 va_start(ap, fmt); 22 char buf[80]; 23 vsnprintf(buf, 80, fmt, ap); 24 printf("%s", buf); 25 rb->splash(HZ * 2, buf); 26 va_end(ap); 27 28 exit(1); 29} 30 31char *strtok_wrapper(char *str, const char *delim) 32{ 33 static char *save = NULL; 34 return strtok_r(str, delim, &save); 35} 36 37/* Implementation of strtod() and atof(), 38 taken from SanOS (http://www.jbox.dk/sanos/). */ 39static int rb_errno = 0; 40 41static double rb_strtod(const char *str, char **endptr) 42{ 43 double number; 44 int exponent; 45 int negative; 46 char *p = (char *) str; 47 double p10; 48 int n; 49 int num_digits; 50 int num_decimals; 51 52 /* Reset Rockbox errno -- W.B. */ 53#ifdef ROCKBOX 54 rb_errno = 0; 55#endif 56 57 // Skip leading whitespace 58 while (isspace(*p)) p++; 59 60 // Handle optional sign 61 negative = 0; 62 switch (*p) 63 { 64 case '-': negative = 1; // Fall through to increment position 65 case '+': p++; 66 } 67 68 number = 0.; 69 exponent = 0; 70 num_digits = 0; 71 num_decimals = 0; 72 73 // Process string of digits 74 while (isdigit(*p)) 75 { 76 number = number * 10. + (*p - '0'); 77 p++; 78 num_digits++; 79 } 80 81 // Process decimal part 82 if (*p == '.') 83 { 84 p++; 85 86 while (isdigit(*p)) 87 { 88 number = number * 10. + (*p - '0'); 89 p++; 90 num_digits++; 91 num_decimals++; 92 } 93 94 exponent -= num_decimals; 95 } 96 97 if (num_digits == 0) 98 { 99#ifdef ROCKBOX 100 rb_errno = 1; 101#else 102 errno = ERANGE; 103#endif 104 return 0.0; 105 } 106 107 // Correct for sign 108 if (negative) number = -number; 109 110 // Process an exponent string 111 if (*p == 'e' || *p == 'E') 112 { 113 // Handle optional sign 114 negative = 0; 115 switch(*++p) 116 { 117 case '-': negative = 1; // Fall through to increment pos 118 case '+': p++; 119 } 120 121 // Process string of digits 122 n = 0; 123 while (isdigit(*p)) 124 { 125 n = n * 10 + (*p - '0'); 126 p++; 127 } 128 129 if (negative) 130 exponent -= n; 131 else 132 exponent += n; 133 } 134 135#ifndef ROCKBOX 136 if (exponent < DBL_MIN_EXP || exponent > DBL_MAX_EXP) 137 { 138 errno = ERANGE; 139 return HUGE_VAL; 140 } 141#endif 142 143 // Scale the result 144 p10 = 10.; 145 n = exponent; 146 if (n < 0) n = -n; 147 while (n) 148 { 149 if (n & 1) 150 { 151 if (exponent < 0) 152 number /= p10; 153 else 154 number *= p10; 155 } 156 n >>= 1; 157 p10 *= p10; 158 } 159 160#ifndef ROCKBOX 161 if (number == HUGE_VAL) errno = ERANGE; 162#endif 163 if (endptr) *endptr = p; 164 165 return number; 166} 167 168// stolen from Quake 169float atof_wrapper (char *str) 170{ 171 double val; 172 int sign; 173 int c; 174 int decimal, total; 175 176 if (*str == '-') 177 { 178 sign = -1; 179 str++; 180 } 181 else 182 sign = 1; 183 184 val = 0; 185 186// 187// check for hex 188// 189 if (str[0] == '0' && (str[1] == 'x' || str[1] == 'X') ) 190 { 191 str += 2; 192 while (1) 193 { 194 c = *str++; 195 if (c >= '0' && c <= '9') 196 val = (val*16) + c - '0'; 197 else if (c >= 'a' && c <= 'f') 198 val = (val*16) + c - 'a' + 10; 199 else if (c >= 'A' && c <= 'F') 200 val = (val*16) + c - 'A' + 10; 201 else 202 return val*sign; 203 } 204 } 205 206// 207// check for character 208// 209 if (str[0] == '\'') 210 { 211 return sign * str[1]; 212 } 213 214// 215// assume decimal 216// 217 decimal = -1; 218 total = 0; 219 while (1) 220 { 221 c = *str++; 222 if (c == '.') 223 { 224 decimal = total; 225 continue; 226 } 227 if (c <'0' || c > '9') 228 break; 229 val = val*10 + c - '0'; 230 total++; 231 } 232 233 if (decimal == -1) 234 return val*sign; 235 while (total > decimal) 236 { 237 val /= 10; 238 total--; 239 } 240 241 return val*sign; 242} 243 244double sin_wrapper(double rads) 245{ 246 /* we want [0, 2*PI) */ 247 while(rads >= 2*PI) 248 rads -= 2*PI; 249 while(rads < 0) 250 rads += 2*PI; 251 252 unsigned long phase = rads/(2*PI) * 4294967296.0; 253 254 /* caching */ 255 if(phase == lastphase) 256 { 257 return lastsin/(lastsin < 0 ? 2147483648.0 : 2147483647.0); 258 } 259 260 lastphase = phase; 261 lastsin = fp_sincos(phase, &lastcos); 262 return lastsin/(lastsin < 0 ? 2147483648.0 : 2147483647.0); 263} 264 265double cos_wrapper(double rads) 266{ 267 /* we want [0, 2*PI) */ 268 while(rads >= 2*PI) 269 rads -= 2*PI; 270 while(rads < 0) 271 rads += 2*PI; 272 273 unsigned long phase = rads/(2*PI) * 4294967296.0; 274 275 /* caching */ 276 if(phase == lastphase) 277 { 278 return lastcos/(lastcos < 0 ? 2147483648.0 : 2147483647.0); 279 } 280 281 lastphase = phase; 282 lastsin = fp_sincos(phase, &lastcos); 283 return lastcos/(lastcos < 0 ? 2147483648.0 : 2147483647.0); 284} 285 286float tan_wrapper(float f) 287{ 288 return sin_wrapper(f)/cos_wrapper(f); 289} 290 291// Total hack. Supports only format strings of the form %Cc, where C 292// is a format specifier and c is a delimiter. Surprisingly, most 293// format strings aren't that complicated to need a real fscanf. This 294// is just enough to make Quake run! 295int fscanf_wrapper(FILE *f, const char *fmt, ...) 296{ 297 va_list ap; 298 299 va_start(ap, fmt); 300 301 if(strlen(fmt) != 3) 302 return 0; // not implemented 303 304 if(fmt[0] != '%') 305 return 0; // not implemented 306 307 char format = fmt[1]; 308 char delim = fmt[2]; 309 310 // extract argument 311 char buf[1024]; 312 char *ptr = (format == 's' ? va_arg(ap, char*) : buf); 313 int c; 314 do { 315 c = fgetc(f); 316 *ptr++ = c; 317 } while(c != delim && c != EOF); 318 319 // overwrite delimiter 320 *(ptr-1) = 0; 321 322 //rb->splashf(HZ, "got argument %s, %s\n", fmt, buf); 323 324 switch(format) 325 { 326 case 'i': 327 *va_arg(ap, int*) = atoi(buf); 328 break; 329 case 'f': 330 *va_arg(ap, float*) = atof(buf); 331 break; 332 } 333 return 1; 334} 335 336 337/* stolen from doom */ 338// Here is a hacked up printf command to get the output from the game. 339int printf_wrapper(const char *fmt, ...) 340{ 341 static volatile struct mutex printf_mutex; 342 static volatile int mutex_init = 0; 343 344 if(!mutex_init) 345 { 346 rb->mutex_init(&printf_mutex); 347 mutex_init = 1; 348 } 349 350 static volatile int p_xtpt; 351 352 rb->mutex_lock(&printf_mutex); 353 354 char p_buf[256]; 355 rb->yield(); 356 va_list ap; 357 358 va_start(ap, fmt); 359 vsnprintf(p_buf,sizeof(p_buf), fmt, ap); 360 va_end(ap); 361 362 rb->lcd_setfont(FONT_SYSFIXED); 363 rb->lcd_putsxy(0,p_xtpt, (unsigned char *)p_buf); 364 if (printf_enabled) 365 rb->lcd_update(); 366 LOGF("%s", p_buf); 367 368 p_xtpt+=8; 369 if(p_xtpt>LCD_HEIGHT-8) 370 { 371 p_xtpt=0; 372 if (printf_enabled) 373 { 374 rb->lcd_set_backdrop(NULL); 375 rb->lcd_clear_display(); 376 } 377 } 378 379 rb->mutex_unlock(&printf_mutex); 380 381 return 1; 382} 383 384int vprintf(const char *fmt, va_list ap) 385{ 386 char buf[256]; 387 vsnprintf(buf, 256, fmt, ap); 388 return printf("%s", buf); 389} 390 391int sprintf_wrapper(char *str, const char *fmt, ...) 392{ 393 va_list ap; 394 va_start(ap, fmt); 395 int ret = vsnprintf(str, 9999, fmt, ap); 396 va_end(ap); 397 return ret; 398} 399 400int vsprintf_wrapper(char *str, const char *fmt, va_list ap) 401{ 402 return vsnprintf(str, 99999, fmt, ap); 403} 404 405char *strcpy_wrapper(char *dest, const char *src) 406{ 407 strlcpy(dest, src, 999); 408 return dest; 409} 410 411char *strdup_wrapper(const char *s) { 412 char *r = malloc(1+strlen(s)); 413 strcpy(r,s); 414 return r; 415} 416 417char *strcat_wrapper(char *dest, const char *src) 418{ 419 rb->strlcat(dest, src, 999); 420 return dest; 421} 422 423char *strpbrk_wrapper(const char *s1, const char *s2) 424{ 425 while(*s1) 426 if(strchr(s2, *s1++)) 427 return (char*)--s1; 428 return 0; 429} 430 431/* A union which permits us to convert between a float and a 32 bit 432 int. */ 433 434typedef union 435{ 436 float value; 437 uint32_t word; 438} ieee_float_shape_type; 439 440/* Get a 32 bit int from a float. */ 441 442#define GET_FLOAT_WORD(i,d) \ 443do { \ 444 ieee_float_shape_type gf_u; \ 445 gf_u.value = (d); \ 446 (i) = gf_u.word; \ 447} while (0) 448 449/* Set a float from a 32 bit int. */ 450 451#define SET_FLOAT_WORD(d,i) \ 452do { \ 453 ieee_float_shape_type sf_u; \ 454 sf_u.word = (i); \ 455 (d) = sf_u.value; \ 456} while (0) 457 458/* Absolute value, simple calculus */ 459float fabs_wrapper(float x) 460{ 461 return (x < 0.0f) ? -x : x; 462} 463 464float fmod(float x, float y) 465{ 466 return x - (int) (x / y) * y; 467} 468 469/* Arc tangent, 470 taken from glibc-2.8. */ 471 472static const float atanhi[] = { 473 4.6364760399e-01, /* atan(0.5)hi 0x3eed6338 */ 474 7.8539812565e-01, /* atan(1.0)hi 0x3f490fda */ 475 9.8279368877e-01, /* atan(1.5)hi 0x3f7b985e */ 476 1.5707962513e+00, /* atan(inf)hi 0x3fc90fda */ 477}; 478 479static const float atanlo[] = { 480 5.0121582440e-09, /* atan(0.5)lo 0x31ac3769 */ 481 3.7748947079e-08, /* atan(1.0)lo 0x33222168 */ 482 3.4473217170e-08, /* atan(1.5)lo 0x33140fb4 */ 483 7.5497894159e-08, /* atan(inf)lo 0x33a22168 */ 484}; 485 486static const float aT[] = { 487 3.3333334327e-01, /* 0x3eaaaaaa */ 488 -2.0000000298e-01, /* 0xbe4ccccd */ 489 1.4285714924e-01, /* 0x3e124925 */ 490 -1.1111110449e-01, /* 0xbde38e38 */ 491 9.0908870101e-02, /* 0x3dba2e6e */ 492 -7.6918758452e-02, /* 0xbd9d8795 */ 493 6.6610731184e-02, /* 0x3d886b35 */ 494 -5.8335702866e-02, /* 0xbd6ef16b */ 495 4.9768779427e-02, /* 0x3d4bda59 */ 496 -3.6531571299e-02, /* 0xbd15a221 */ 497 1.6285819933e-02, /* 0x3c8569d7 */ 498}; 499 500static const float zero = 0.0; 501 502static const float 503huge = 1.0e+30, 504tiny = 1.0e-30, 505one = 1.0f; 506 507/* Square root function, original. */ 508float sqrt_wrapper(float x) 509{ 510 float z; 511 int32_t sign = (int)0x80000000; 512 int32_t ix,s,q,m,t,i; 513 uint32_t r; 514 515 GET_FLOAT_WORD(ix,x); 516 517 /* take care of Inf and NaN */ 518 if((ix&0x7f800000)==0x7f800000) { 519 return x*x+x; /* sqrt(NaN)=NaN, sqrt(+inf)=+inf 520 sqrt(-inf)=sNaN */ 521 } 522 /* take care of zero */ 523 if(ix<=0) { 524 if((ix&(~sign))==0) return x;/* sqrt(+-0) = +-0 */ 525 else if(ix<0) 526 return (x-x)/(x-x); /* sqrt(-ve) = sNaN */ 527 } 528 /* normalize x */ 529 m = (ix>>23); 530 if(m==0) { /* subnormal x */ 531 for(i=0;(ix&0x00800000)==0;i++) ix<<=1; 532 m -= i-1; 533 } 534 m -= 127; /* unbias exponent */ 535 ix = (ix&0x007fffff)|0x00800000; 536 if(m&1) /* odd m, double x to make it even */ 537 ix += ix; 538 m >>= 1; /* m = [m/2] */ 539 540 /* generate sqrt(x) bit by bit */ 541 ix += ix; 542 q = s = 0; /* q = sqrt(x) */ 543 r = 0x01000000; /* r = moving bit from right to left */ 544 545 while(r!=0) { 546 t = s+r; 547 if(t<=ix) { 548 s = t+r; 549 ix -= t; 550 q += r; 551 } 552 ix += ix; 553 r>>=1; 554 } 555 556 /* use floating add to find out rounding direction */ 557 if(ix!=0) { 558 z = one-tiny; /* trigger inexact flag */ 559 if (z>=one) { 560 z = one+tiny; 561 if (z>one) 562 q += 2; 563 else 564 q += (q&1); 565 } 566 } 567 ix = (q>>1)+0x3f000000; 568 ix += (m <<23); 569 SET_FLOAT_WORD(z,ix); 570 return z; 571} 572 573float atan_wrapper(float x) 574{ 575 float w,s1,s2,z; 576 int32_t ix,hx,id; 577 578 GET_FLOAT_WORD(hx,x); 579 ix = hx&0x7fffffff; 580 if(ix>=0x50800000) { /* if |x| >= 2^34 */ 581 if(ix>0x7f800000) 582 return x+x; /* NaN */ 583 if(hx>0) return atanhi[3]+atanlo[3]; 584 else return -atanhi[3]-atanlo[3]; 585 } if (ix < 0x3ee00000) { /* |x| < 0.4375 */ 586 if (ix < 0x31000000) { /* |x| < 2^-29 */ 587 if(huge+x>one) return x; /* raise inexact */ 588 } 589 id = -1; 590 } else { 591 x = fabs_wrapper(x); 592 if (ix < 0x3f980000) { /* |x| < 1.1875 */ 593 if (ix < 0x3f300000) { /* 7/16 <=|x|<11/16 */ 594 id = 0; x = ((float)2.0*x-one)/((float)2.0+x); 595 } else { /* 11/16<=|x|< 19/16 */ 596 id = 1; x = (x-one)/(x+one); 597 } 598 } else { 599 if (ix < 0x401c0000) { /* |x| < 2.4375 */ 600 id = 2; x = (x-(float)1.5)/(one+(float)1.5*x); 601 } else { /* 2.4375 <= |x| < 2^66 */ 602 id = 3; x = -(float)1.0/x; 603 } 604 }} 605 /* end of argument reduction */ 606 z = x*x; 607 w = z*z; 608 /* break sum from i=0 to 10 aT[i]z**(i+1) into odd and even poly */ 609 s1 = z*(aT[0]+w*(aT[2]+w*(aT[4]+w*(aT[6]+w*(aT[8]+w*aT[10]))))); 610 s2 = w*(aT[1]+w*(aT[3]+w*(aT[5]+w*(aT[7]+w*aT[9])))); 611 if (id<0) return x - x*(s1+s2); 612 else { 613 z = atanhi[id] - ((x*(s1+s2) - atanlo[id]) - x); 614 return (hx<0)? -z:z; 615 } 616} 617 618/* Arc tangent from two variables, original. */ 619 620static const float 621pi_o_4 = 7.8539818525e-01, /* 0x3f490fdb */ 622pi_o_2 = 1.5707963705e+00, /* 0x3fc90fdb */ 623pi = 3.1415927410e+00, /* 0x40490fdb */ 624pi_lo = -8.7422776573e-08; /* 0xb3bbbd2e */ 625 626float atan2_wrapper(float y, float x) 627{ 628 float z; 629 int32_t k,m,hx,hy,ix,iy; 630 631 GET_FLOAT_WORD(hx,x); 632 ix = hx&0x7fffffff; 633 GET_FLOAT_WORD(hy,y); 634 iy = hy&0x7fffffff; 635 if((ix>0x7f800000)|| 636 (iy>0x7f800000)) /* x or y is NaN */ 637 return x+y; 638 if(hx==0x3f800000) return atan_wrapper(y); /* x=1.0 */ 639 m = ((hy>>31)&1)|((hx>>30)&2); /* 2*sign(x)+sign(y) */ 640 641 /* when y = 0 */ 642 if(iy==0) { 643 switch(m) { 644 case 0: 645 case 1: return y; /* atan(+-0,+anything)=+-0 */ 646 case 2: return pi+tiny;/* atan(+0,-anything) = pi */ 647 case 3: return -pi-tiny;/* atan(-0,-anything) =-pi */ 648 } 649 } 650 /* when x = 0 */ 651 if(ix==0) return (hy<0)? -pi_o_2-tiny: pi_o_2+tiny; 652 653 /* when x is INF */ 654 if(ix==0x7f800000) { 655 if(iy==0x7f800000) { 656 switch(m) { 657 case 0: return pi_o_4+tiny;/* atan(+INF,+INF) */ 658 case 1: return -pi_o_4-tiny;/* atan(-INF,+INF) */ 659 case 2: return (float)3.0*pi_o_4+tiny;/*atan(+INF,-INF)*/ 660 case 3: return (float)-3.0*pi_o_4-tiny;/*atan(-INF,-INF)*/ 661 } 662 } else { 663 switch(m) { 664 case 0: return zero ; /* atan(+...,+INF) */ 665 case 1: return -zero ; /* atan(-...,+INF) */ 666 case 2: return pi+tiny ; /* atan(+...,-INF) */ 667 case 3: return -pi-tiny ; /* atan(-...,-INF) */ 668 } 669 } 670 } 671 /* when y is INF */ 672 if(iy==0x7f800000) return (hy<0)? -pi_o_2-tiny: pi_o_2+tiny; 673 674 /* compute y/x */ 675 k = (iy-ix)>>23; 676 if(k > 60) z=pi_o_2+(float)0.5*pi_lo; /* |y/x| > 2**60 */ 677 else if(hx<0&&k<-60) z=0.0; /* |y|/x < -2**60 */ 678 else z=atan_wrapper(fabs_wrapper(y/x)); /* safe to do y/x */ 679 switch (m) { 680 case 0: return z ; /* atan(+,+) */ 681 case 1: { 682 uint32_t zh; 683 GET_FLOAT_WORD(zh,z); 684 SET_FLOAT_WORD(z,zh ^ 0x80000000); 685 } 686 return z ; /* atan(-,+) */ 687 case 2: return pi-(z-pi_lo);/* atan(+,-) */ 688 default: /* case 3 */ 689 return (z-pi_lo)-pi;/* atan(-,-) */ 690 } 691} 692union ieee754_double 693 { 694 double d; 695 696 /* This is the IEEE 754 double-precision format. */ 697 struct 698 { 699#ifdef ROCKBOX_BIG_ENDIAN 700 unsigned int negative:1; 701 unsigned int exponent:11; 702 /* Together these comprise the mantissa. */ 703 unsigned int mantissa0:20; 704 unsigned int mantissa1:32; 705#else /* ROCKBOX_LITTLE_ENDIAN */ 706 /* Together these comprise the mantissa. */ 707 unsigned int mantissa1:32; 708 unsigned int mantissa0:20; 709 unsigned int exponent:11; 710 unsigned int negative:1; 711#endif /* ROCKBOX_LITTLE_ENDIAN */ 712 } ieee; 713 714 /* This format makes it easier to see if a NaN is a signalling NaN. */ 715 struct 716 { 717#ifdef ROCKBOX_BIG_ENDIAN 718 unsigned int negative:1; 719 unsigned int exponent:11; 720 unsigned int quiet_nan:1; 721 /* Together these comprise the mantissa. */ 722 unsigned int mantissa0:19; 723 unsigned int mantissa1:32; 724#else /* ROCKBOX_LITTLE_ENDIAN */ 725 /* Together these comprise the mantissa. */ 726 unsigned int mantissa1:32; 727 unsigned int mantissa0:19; 728 unsigned int quiet_nan:1; 729 unsigned int exponent:11; 730 unsigned int negative:1; 731#endif /* ROCKBOX_LITTLE_ENDIAN */ 732 } ieee_nan; 733 }; 734 735static const volatile float TWOM100 = 7.88860905e-31; 736static const volatile float TWO127 = 1.7014118346e+38; 737 738/* Exponential function, 739 taken from glibc-2.8 740 As it uses double values and udefines some symbols, 741 it was moved to the end of the source code */ 742 743#define W52 (2.22044605e-16) 744#define W55 (2.77555756e-17) 745#define W58 (3.46944695e-18) 746#define W59 (1.73472348e-18) 747#define W60 (8.67361738e-19) 748const float __exp_deltatable[178] = { 749 0*W60, 16558714*W60, -10672149*W59, 1441652*W60, 750 -15787963*W55, 462888*W60, 7291806*W60, 1698880*W60, 751 -14375103*W58, -2021016*W60, 728829*W60, -3759654*W60, 752 3202123*W60, -10916019*W58, -251570*W60, -1043086*W60, 753 8207536*W60, -409964*W60, -5993931*W60, -475500*W60, 754 2237522*W60, 324170*W60, -244117*W60, 32077*W60, 755 123907*W60, -1019734*W60, -143*W60, 813077*W60, 756 743345*W60, 462461*W60, 629794*W60, 2125066*W60, 757 -2339121*W60, -337951*W60, 9922067*W60, -648704*W60, 758 149407*W60, -2687209*W60, -631608*W60, 2128280*W60, 759 -4882082*W60, 2001360*W60, 175074*W60, 2923216*W60, 760 -538947*W60, -1212193*W60, -1920926*W60, -1080577*W60, 761 3690196*W60, 2643367*W60, 2911937*W60, 671455*W60, 762 -1128674*W60, 593282*W60, -5219347*W60, -1941490*W60, 763 11007953*W60, 239609*W60, -2969658*W60, -1183650*W60, 764 942998*W60, 699063*W60, 450569*W60, -329250*W60, 765 -7257875*W60, -312436*W60, 51626*W60, 555877*W60, 766 -641761*W60, 1565666*W60, 884327*W60, -10960035*W60, 767 -2004679*W60, -995793*W60, -2229051*W60, -146179*W60, 768 -510327*W60, 1453482*W60, -3778852*W60, -2238056*W60, 769 -4895983*W60, 3398883*W60, -252738*W60, 1230155*W60, 770 346918*W60, 1109352*W60, 268941*W60, -2930483*W60, 771 -1036263*W60, -1159280*W60, 1328176*W60, 2937642*W60, 772 -9371420*W60, -6902650*W60, -1419134*W60, 1442904*W60, 773 -1319056*W60, -16369*W60, 696555*W60, -279987*W60, 774 -7919763*W60, 252741*W60, 459711*W60, -1709645*W60, 775 354913*W60, 6025867*W60, -421460*W60, -853103*W60, 776 -338649*W60, 962151*W60, 955965*W60, 784419*W60, 777 -3633653*W60, 2277133*W60, -8847927*W52, 1223028*W60, 778 5907079*W60, 623167*W60, 5142888*W60, 2599099*W60, 779 1214280*W60, 4870359*W60, 593349*W60, -57705*W60, 780 7761209*W60, -5564097*W60, 2051261*W60, 6216869*W60, 781 4692163*W60, 601691*W60, -5264906*W60, 1077872*W60, 782 -3205949*W60, 1833082*W60, 2081746*W60, -987363*W60, 783 -1049535*W60, 2015244*W60, 874230*W60, 2168259*W60, 784 -1740124*W60, -10068269*W60, -18242*W60, -3013583*W60, 785 580601*W60, -2547161*W60, -535689*W60, 2220815*W60, 786 1285067*W60, 2806933*W60, -983086*W60, -1729097*W60, 787 -1162985*W60, -2561904*W60, 801988*W60, 244351*W60, 788 1441893*W60, -7517981*W60, 271781*W60, -15021588*W60, 789 -2341588*W60, -919198*W60, 1642232*W60, 4771771*W60, 790 -1220099*W60, -3062372*W60, 628624*W60, 1278114*W60, 791 13083513*W60, -10521925*W60, 3180310*W60, -1659307*W60, 792 3543773*W60, 2501203*W60, 4151*W60, -340748*W60, 793 -2285625*W60, 2495202*W60 794}; 795 796const double __exp_atable[355] /* __attribute__((mode(DF))) */ = { 797 0.707722561055888932371, /* 0x0.b52d4e46605c27ffd */ 798 0.709106182438804188967, /* 0x0.b587fb96f75097ffb */ 799 0.710492508843861281234, /* 0x0.b5e2d649899167ffd */ 800 0.711881545564593931623, /* 0x0.b63dde74d36bdfffe */ 801 0.713273297897442870573, /* 0x0.b699142f945f87ffc */ 802 0.714667771153751463236, /* 0x0.b6f477909c4ea0001 */ 803 0.716064970655995725059, /* 0x0.b75008aec758f8004 */ 804 0.717464901723956938193, /* 0x0.b7abc7a0eea7e0002 */ 805 0.718867569715736398602, /* 0x0.b807b47e1586c7ff8 */ 806 0.720272979947266023271, /* 0x0.b863cf5d10e380003 */ 807 0.721681137825144314297, /* 0x0.b8c01855195c37ffb */ 808 0.723092048691992950199, /* 0x0.b91c8f7d213740004 */ 809 0.724505717938892290800, /* 0x0.b97934ec5002d0007 */ 810 0.725922150953176470431, /* 0x0.b9d608b9c92ea7ffc */ 811 0.727341353138962865022, /* 0x0.ba330afcc29e98003 */ 812 0.728763329918453162104, /* 0x0.ba903bcc8618b7ffc */ 813 0.730188086709957051568, /* 0x0.baed9b40591ba0000 */ 814 0.731615628948127705309, /* 0x0.bb4b296f931e30002 */ 815 0.733045962086486091436, /* 0x0.bba8e671a05617ff9 */ 816 0.734479091556371366251, /* 0x0.bc06d25dd49568001 */ 817 0.735915022857225542529, /* 0x0.bc64ed4bce8f6fff9 */ 818 0.737353761441304711410, /* 0x0.bcc33752f915d7ff9 */ 819 0.738795312814142124419, /* 0x0.bd21b08af98e78005 */ 820 0.740239682467211168593, /* 0x0.bd80590b65e9a8000 */ 821 0.741686875913991849885, /* 0x0.bddf30ebec4a10000 */ 822 0.743136898669507939299, /* 0x0.be3e38443c84e0007 */ 823 0.744589756269486091620, /* 0x0.be9d6f2c1d32a0002 */ 824 0.746045454254026796384, /* 0x0.befcd5bb59baf8004 */ 825 0.747503998175051087583, /* 0x0.bf5c6c09ca84c0003 */ 826 0.748965393601880857739, /* 0x0.bfbc322f5b18b7ff8 */ 827 0.750429646104262104698, /* 0x0.c01c2843f776fffff */ 828 0.751896761271877989160, /* 0x0.c07c4e5fa18b88002 */ 829 0.753366744698445112140, /* 0x0.c0dca49a5fb18fffd */ 830 0.754839601988627206827, /* 0x0.c13d2b0c444db0005 */ 831 0.756315338768691947122, /* 0x0.c19de1cd798578006 */ 832 0.757793960659406629066, /* 0x0.c1fec8f623723fffd */ 833 0.759275473314173443536, /* 0x0.c25fe09e8a0f47ff8 */ 834 0.760759882363831851927, /* 0x0.c2c128dedc88f8000 */ 835 0.762247193485956486805, /* 0x0.c322a1cf7d6e7fffa */ 836 0.763737412354726363781, /* 0x0.c3844b88cb9347ffc */ 837 0.765230544649828092739, /* 0x0.c3e626232bd8f7ffc */ 838 0.766726596071518051729, /* 0x0.c44831b719bf18002 */ 839 0.768225572321911687194, /* 0x0.c4aa6e5d12d078001 */ 840 0.769727479119219348810, /* 0x0.c50cdc2da64a37ffb */ 841 0.771232322196981678892, /* 0x0.c56f7b41744490001 */ 842 0.772740107296721268087, /* 0x0.c5d24bb1259e70004 */ 843 0.774250840160724651565, /* 0x0.c6354d95640dd0007 */ 844 0.775764526565368872643, /* 0x0.c6988106fec447fff */ 845 0.777281172269557396602, /* 0x0.c6fbe61eb1bd0ffff */ 846 0.778800783068235302750, /* 0x0.c75f7cf560942fffc */ 847 0.780323364758801041312, /* 0x0.c7c345a3f1983fffe */ 848 0.781848923151573727006, /* 0x0.c8274043594cb0002 */ 849 0.783377464064598849602, /* 0x0.c88b6cec94b3b7ff9 */ 850 0.784908993312207869935, /* 0x0.c8efcbb89cba27ffe */ 851 0.786443516765346961618, /* 0x0.c9545cc0a88c70003 */ 852 0.787981040257604625744, /* 0x0.c9b9201dc643bfffa */ 853 0.789521569657452682047, /* 0x0.ca1e15e92a5410007 */ 854 0.791065110849462849192, /* 0x0.ca833e3c1ae510005 */ 855 0.792611669712891875319, /* 0x0.cae8992fd84667ffd */ 856 0.794161252150049179450, /* 0x0.cb4e26ddbc207fff8 */ 857 0.795713864077794763584, /* 0x0.cbb3e75f301b60003 */ 858 0.797269511407239561694, /* 0x0.cc19dacd978cd8002 */ 859 0.798828200086368567220, /* 0x0.cc8001427e55d7ffb */ 860 0.800389937624300440456, /* 0x0.cce65ade24d360006 */ 861 0.801954725261124767840, /* 0x0.cd4ce7a5de839fffb */ 862 0.803522573691593189330, /* 0x0.cdb3a7c79a678fffd */ 863 0.805093487311204114563, /* 0x0.ce1a9b563965ffffc */ 864 0.806667472122675088819, /* 0x0.ce81c26b838db8000 */ 865 0.808244534127439906441, /* 0x0.cee91d213f8428002 */ 866 0.809824679342317166307, /* 0x0.cf50ab9144d92fff9 */ 867 0.811407913793616542005, /* 0x0.cfb86dd5758c2ffff */ 868 0.812994243520784198882, /* 0x0.d0206407c20e20005 */ 869 0.814583674571603966162, /* 0x0.d0888e4223facfff9 */ 870 0.816176213022088536960, /* 0x0.d0f0ec9eb3f7c8002 */ 871 0.817771864936188586101, /* 0x0.d1597f377d6768002 */ 872 0.819370636400374108252, /* 0x0.d1c24626a46eafff8 */ 873 0.820972533518165570298, /* 0x0.d22b41865ff1e7ff9 */ 874 0.822577562404315121269, /* 0x0.d2947170f32ec7ff9 */ 875 0.824185729164559344159, /* 0x0.d2fdd60097795fff8 */ 876 0.825797039949601741075, /* 0x0.d3676f4fb796d0001 */ 877 0.827411500902565544264, /* 0x0.d3d13d78b5f68fffb */ 878 0.829029118181348834154, /* 0x0.d43b40960546d8001 */ 879 0.830649897953322891022, /* 0x0.d4a578c222a058000 */ 880 0.832273846408250750368, /* 0x0.d50fe617a3ba78005 */ 881 0.833900969738858188772, /* 0x0.d57a88b1218e90002 */ 882 0.835531274148056613016, /* 0x0.d5e560a94048f8006 */ 883 0.837164765846411529371, /* 0x0.d6506e1aac8078003 */ 884 0.838801451086016225394, /* 0x0.d6bbb1204074e0001 */ 885 0.840441336100884561780, /* 0x0.d72729d4c28518004 */ 886 0.842084427144139224814, /* 0x0.d792d8530e12b0001 */ 887 0.843730730487052604790, /* 0x0.d7febcb61273e7fff */ 888 0.845380252404570153833, /* 0x0.d86ad718c308dfff9 */ 889 0.847032999194574087728, /* 0x0.d8d727962c69d7fff */ 890 0.848688977161248581090, /* 0x0.d943ae49621ce7ffb */ 891 0.850348192619261200615, /* 0x0.d9b06b4d832ef8005 */ 892 0.852010651900976245816, /* 0x0.da1d5ebdc22220005 */ 893 0.853676361342631029337, /* 0x0.da8a88b555baa0006 */ 894 0.855345327311054837175, /* 0x0.daf7e94f965f98004 */ 895 0.857017556155879489641, /* 0x0.db6580a7c98f7fff8 */ 896 0.858693054267390953857, /* 0x0.dbd34ed9617befff8 */ 897 0.860371828028939855647, /* 0x0.dc4153ffc8b65fff9 */ 898 0.862053883854957292436, /* 0x0.dcaf90368bfca8004 */ 899 0.863739228154875360306, /* 0x0.dd1e0399328d87ffe */ 900 0.865427867361348468455, /* 0x0.dd8cae435d303fff9 */ 901 0.867119807911702289458, /* 0x0.ddfb9050b1cee8006 */ 902 0.868815056264353846599, /* 0x0.de6aa9dced8448001 */ 903 0.870513618890481399881, /* 0x0.ded9fb03db7320006 */ 904 0.872215502247877139094, /* 0x0.df4983e1380657ff8 */ 905 0.873920712852848668986, /* 0x0.dfb94490ffff77ffd */ 906 0.875629257204025623884, /* 0x0.e0293d2f1cb01fff9 */ 907 0.877341141814212965880, /* 0x0.e0996dd786fff0007 */ 908 0.879056373217612985183, /* 0x0.e109d6a64f5d57ffc */ 909 0.880774957955916648615, /* 0x0.e17a77b78e72a7ffe */ 910 0.882496902590150900078, /* 0x0.e1eb5127722cc7ff8 */ 911 0.884222213673356738383, /* 0x0.e25c63121fb0c8006 */ 912 0.885950897802399772740, /* 0x0.e2cdad93ec5340003 */ 913 0.887682961567391237685, /* 0x0.e33f30c925fb97ffb */ 914 0.889418411575228162725, /* 0x0.e3b0ecce2d05ffff9 */ 915 0.891157254447957902797, /* 0x0.e422e1bf727718006 */ 916 0.892899496816652704641, /* 0x0.e4950fb9713fc7ffe */ 917 0.894645145323828439008, /* 0x0.e50776d8b0e60fff8 */ 918 0.896394206626591749641, /* 0x0.e57a1739c8fadfffc */ 919 0.898146687421414902124, /* 0x0.e5ecf0f97c5798007 */ 920 0.899902594367530173098, /* 0x0.e660043464e378005 */ 921 0.901661934163603406867, /* 0x0.e6d3510747e150006 */ 922 0.903424713533971135418, /* 0x0.e746d78f06cd97ffd */ 923 0.905190939194458810123, /* 0x0.e7ba97e879c91fffc */ 924 0.906960617885092856864, /* 0x0.e82e92309390b0007 */ 925 0.908733756358986566306, /* 0x0.e8a2c6845544afffa */ 926 0.910510361377119825629, /* 0x0.e9173500c8abc7ff8 */ 927 0.912290439722343249336, /* 0x0.e98bddc30f98b0002 */ 928 0.914073998177417412765, /* 0x0.ea00c0e84bc4c7fff */ 929 0.915861043547953501680, /* 0x0.ea75de8db8094fffe */ 930 0.917651582652244779397, /* 0x0.eaeb36d09d3137ffe */ 931 0.919445622318405764159, /* 0x0.eb60c9ce4ed3dffff */ 932 0.921243169397334638073, /* 0x0.ebd697a43995b0007 */ 933 0.923044230737526172328, /* 0x0.ec4ca06fc7768fffa */ 934 0.924848813220121135342, /* 0x0.ecc2e44e865b6fffb */ 935 0.926656923710931002014, /* 0x0.ed39635df34e70006 */ 936 0.928468569126343790092, /* 0x0.edb01dbbc2f5b7ffa */ 937 0.930283756368834757725, /* 0x0.ee2713859aab57ffa */ 938 0.932102492359406786818, /* 0x0.ee9e44d9342870004 */ 939 0.933924784042873379360, /* 0x0.ef15b1d4635438005 */ 940 0.935750638358567643520, /* 0x0.ef8d5a94f60f50007 */ 941 0.937580062297704630580, /* 0x0.f0053f38f345cffff */ 942 0.939413062815381727516, /* 0x0.f07d5fde3a2d98001 */ 943 0.941249646905368053689, /* 0x0.f0f5bca2d481a8004 */ 944 0.943089821583810716806, /* 0x0.f16e55a4e497d7ffe */ 945 0.944933593864477061592, /* 0x0.f1e72b028a2827ffb */ 946 0.946780970781518460559, /* 0x0.f2603cd9fb5430001 */ 947 0.948631959382661205081, /* 0x0.f2d98b497d2a87ff9 */ 948 0.950486566729423554277, /* 0x0.f353166f63e3dffff */ 949 0.952344799896018723290, /* 0x0.f3ccde6a11ae37ffe */ 950 0.954206665969085765512, /* 0x0.f446e357f66120000 */ 951 0.956072172053890279009, /* 0x0.f4c12557964f0fff9 */ 952 0.957941325265908139014, /* 0x0.f53ba48781046fffb */ 953 0.959814132734539637840, /* 0x0.f5b66106555d07ffa */ 954 0.961690601603558903308, /* 0x0.f6315af2c2027fffc */ 955 0.963570739036113010927, /* 0x0.f6ac926b8aeb80004 */ 956 0.965454552202857141381, /* 0x0.f728078f7c5008002 */ 957 0.967342048278315158608, /* 0x0.f7a3ba7d66a908001 */ 958 0.969233234469444204768, /* 0x0.f81fab543e1897ffb */ 959 0.971128118008140250896, /* 0x0.f89bda33122c78007 */ 960 0.973026706099345495256, /* 0x0.f9184738d4cf97ff8 */ 961 0.974929006031422851235, /* 0x0.f994f284d3a5c0008 */ 962 0.976835024947348973265, /* 0x0.fa11dc35bc7820002 */ 963 0.978744770239899142285, /* 0x0.fa8f046b4fb7f8007 */ 964 0.980658249138918636210, /* 0x0.fb0c6b449ab1cfff9 */ 965 0.982575468959622777535, /* 0x0.fb8a10e1088fb7ffa */ 966 0.984496437054508843888, /* 0x0.fc07f5602d79afffc */ 967 0.986421160608523028820, /* 0x0.fc8618e0e55e47ffb */ 968 0.988349647107594098099, /* 0x0.fd047b83571b1fffa */ 969 0.990281903873210800357, /* 0x0.fd831d66f4c018002 */ 970 0.992217938695037382475, /* 0x0.fe01fead3320bfff8 */ 971 0.994157757657894713987, /* 0x0.fe811f703491e8006 */ 972 0.996101369488558541238, /* 0x0.ff007fd5744490005 */ 973 0.998048781093141101932, /* 0x0.ff801ffa9b9280007 */ 974 1.000000000000000000000, /* 0x1.00000000000000000 */ 975 1.001955033605393285965, /* 0x1.0080200565d29ffff */ 976 1.003913889319761887310, /* 0x1.0100802aa0e80fff0 */ 977 1.005876574715736104818, /* 0x1.01812090377240007 */ 978 1.007843096764807100351, /* 0x1.020201541aad7fff6 */ 979 1.009813464316352327214, /* 0x1.0283229c4c9820007 */ 980 1.011787683565730677817, /* 0x1.030484836910a000e */ 981 1.013765762469146736174, /* 0x1.0386272b9c077fffe */ 982 1.015747708536026694351, /* 0x1.04080ab526304fff0 */ 983 1.017733529475172815584, /* 0x1.048a2f412375ffff0 */ 984 1.019723232714418781378, /* 0x1.050c94ef7ad5e000a */ 985 1.021716825883923762690, /* 0x1.058f3be0f1c2d0004 */ 986 1.023714316605201180057, /* 0x1.06122436442e2000e */ 987 1.025715712440059545995, /* 0x1.06954e0fec63afff2 */ 988 1.027721021151397406936, /* 0x1.0718b98f41c92fff6 */ 989 1.029730250269221158939, /* 0x1.079c66d49bb2ffff1 */ 990 1.031743407506447551857, /* 0x1.082056011a9230009 */ 991 1.033760500517691527387, /* 0x1.08a487359ebd50002 */ 992 1.035781537016238873464, /* 0x1.0928fa93490d4fff3 */ 993 1.037806524719013578963, /* 0x1.09adb03b3e5b3000d */ 994 1.039835471338248051878, /* 0x1.0a32a84e9e5760004 */ 995 1.041868384612101516848, /* 0x1.0ab7e2eea5340ffff */ 996 1.043905272300907460835, /* 0x1.0b3d603ca784f0009 */ 997 1.045946142174331239262, /* 0x1.0bc3205a042060000 */ 998 1.047991002016745332165, /* 0x1.0c4923682a086fffe */ 999 1.050039859627715177527, /* 0x1.0ccf698898f3a000d */ 1000 1.052092722826109660856, /* 0x1.0d55f2dce5d1dfffb */ 1001 1.054149599440827866881, /* 0x1.0ddcbf86b09a5fff6 */ 1002 1.056210497317612961855, /* 0x1.0e63cfa7abc97fffd */ 1003 1.058275424318780855142, /* 0x1.0eeb23619c146fffb */ 1004 1.060344388322010722446, /* 0x1.0f72bad65714bffff */ 1005 1.062417397220589476718, /* 0x1.0ffa9627c38d30004 */ 1006 1.064494458915699715017, /* 0x1.1082b577d0eef0003 */ 1007 1.066575581342167566880, /* 0x1.110b18e893a90000a */ 1008 1.068660772440545025953, /* 0x1.1193c09c267610006 */ 1009 1.070750040138235936705, /* 0x1.121cacb4959befff6 */ 1010 1.072843392435016474095, /* 0x1.12a5dd543cf36ffff */ 1011 1.074940837302467588937, /* 0x1.132f529d59552000b */ 1012 1.077042382749654914030, /* 0x1.13b90cb250d08fff5 */ 1013 1.079148036789447484528, /* 0x1.14430bb58da3dfff9 */ 1014 1.081257807444460983297, /* 0x1.14cd4fc984c4a000e */ 1015 1.083371702785017154417, /* 0x1.1557d910df9c7000e */ 1016 1.085489730853784307038, /* 0x1.15e2a7ae292d30002 */ 1017 1.087611899742884524772, /* 0x1.166dbbc422d8c0004 */ 1018 1.089738217537583819804, /* 0x1.16f9157586772ffff */ 1019 1.091868692357631731528, /* 0x1.1784b4e533cacfff0 */ 1020 1.094003332327482702577, /* 0x1.18109a360fc23fff2 */ 1021 1.096142145591650907149, /* 0x1.189cc58b155a70008 */ 1022 1.098285140311341168136, /* 0x1.1929370751ea50002 */ 1023 1.100432324652149906842, /* 0x1.19b5eecdd79cefff0 */ 1024 1.102583706811727015711, /* 0x1.1a42ed01dbdba000e */ 1025 1.104739294993289488947, /* 0x1.1ad031c69a2eafff0 */ 1026 1.106899097422573863281, /* 0x1.1b5dbd3f66e120003 */ 1027 1.109063122341542140286, /* 0x1.1beb8f8fa8150000b */ 1028 1.111231377994659874592, /* 0x1.1c79a8dac6ad0fff4 */ 1029 1.113403872669181282605, /* 0x1.1d0809445a97ffffc */ 1030 1.115580614653132185460, /* 0x1.1d96b0effc9db000e */ 1031 1.117761612217810673898, /* 0x1.1e25a001332190000 */ 1032 1.119946873713312474002, /* 0x1.1eb4d69bdb2a9fff1 */ 1033 1.122136407473298902480, /* 0x1.1f4454e3bfae00006 */ 1034 1.124330221845670330058, /* 0x1.1fd41afcbb48bfff8 */ 1035 1.126528325196519908506, /* 0x1.2064290abc98c0001 */ 1036 1.128730725913251964394, /* 0x1.20f47f31c9aa7000f */ 1037 1.130937432396844410880, /* 0x1.21851d95f776dfff0 */ 1038 1.133148453059692917203, /* 0x1.2216045b6784efffa */ 1039 1.135363796355857157764, /* 0x1.22a733a6692ae0004 */ 1040 1.137583470716100553249, /* 0x1.2338ab9b3221a0004 */ 1041 1.139807484614418608939, /* 0x1.23ca6c5e27aadfff7 */ 1042 1.142035846532929888057, /* 0x1.245c7613b7f6c0004 */ 1043 1.144268564977221958089, /* 0x1.24eec8e06b035000c */ 1044 1.146505648458203463465, /* 0x1.258164e8cea85fff8 */ 1045 1.148747105501412235671, /* 0x1.26144a5180d380009 */ 1046 1.150992944689175123667, /* 0x1.26a7793f5de2efffa */ 1047 1.153243174560058870217, /* 0x1.273af1d712179000d */ 1048 1.155497803703682491111, /* 0x1.27ceb43d81d42fff1 */ 1049 1.157756840726344771440, /* 0x1.2862c097a3d29000c */ 1050 1.160020294239811677834, /* 0x1.28f7170a74cf4fff1 */ 1051 1.162288172883275239058, /* 0x1.298bb7bb0faed0004 */ 1052 1.164560485298402170388, /* 0x1.2a20a2ce920dffff4 */ 1053 1.166837240167474476460, /* 0x1.2ab5d86a4631ffff6 */ 1054 1.169118446164539637555, /* 0x1.2b4b58b36d5220009 */ 1055 1.171404112007080167155, /* 0x1.2be123cf786790002 */ 1056 1.173694246390975415341, /* 0x1.2c7739e3c0aac000d */ 1057 1.175988858069749065617, /* 0x1.2d0d9b15deb58fff6 */ 1058 1.178287955789017793514, /* 0x1.2da4478b627040002 */ 1059 1.180591548323240091978, /* 0x1.2e3b3f69fb794fffc */ 1060 1.182899644456603782686, /* 0x1.2ed282d76421d0004 */ 1061 1.185212252993012693694, /* 0x1.2f6a11f96c685fff3 */ 1062 1.187529382762033236513, /* 0x1.3001ecf60082ffffa */ 1063 1.189851042595508889847, /* 0x1.309a13f30f28a0004 */ 1064 1.192177241354644978669, /* 0x1.31328716a758cfff7 */ 1065 1.194507987909589896687, /* 0x1.31cb4686e1e85fffb */ 1066 1.196843291137896336843, /* 0x1.32645269dfd04000a */ 1067 1.199183159977805113226, /* 0x1.32fdaae604c39000f */ 1068 1.201527603343041317132, /* 0x1.339750219980dfff3 */ 1069 1.203876630171082595692, /* 0x1.3431424300e480007 */ 1070 1.206230249419600664189, /* 0x1.34cb8170b3fee000e */ 1071 1.208588470077065268869, /* 0x1.35660dd14dbd4fffc */ 1072 1.210951301134513435915, /* 0x1.3600e78b6bdfc0005 */ 1073 1.213318751604272271958, /* 0x1.369c0ec5c38ebfff2 */ 1074 1.215690830512196507537, /* 0x1.373783a718d29000f */ 1075 1.218067546930756250870, /* 0x1.37d3465662f480007 */ 1076 1.220448909901335365929, /* 0x1.386f56fa770fe0008 */ 1077 1.222834928513994334780, /* 0x1.390bb5ba5fc540004 */ 1078 1.225225611877684750397, /* 0x1.39a862bd3c7a8fff3 */ 1079 1.227620969111500981433, /* 0x1.3a455e2a37bcafffd */ 1080 1.230021009336254911271, /* 0x1.3ae2a8287dfbefff6 */ 1081 1.232425741726685064472, /* 0x1.3b8040df76f39fffa */ 1082 1.234835175450728295084, /* 0x1.3c1e287682e48fff1 */ 1083 1.237249319699482263931, /* 0x1.3cbc5f151b86bfff8 */ 1084 1.239668183679933477545, /* 0x1.3d5ae4e2cc0a8000f */ 1085 1.242091776620540377629, /* 0x1.3df9ba07373bf0006 */ 1086 1.244520107762172811399, /* 0x1.3e98deaa0d8cafffe */ 1087 1.246953186383919165383, /* 0x1.3f3852f32973efff0 */ 1088 1.249391019292643401078, /* 0x1.3fd816ffc72b90001 */ 1089 1.251833623164381181797, /* 0x1.40782b17863250005 */ 1090 1.254280999953110153911, /* 0x1.41188f42caf400000 */ 1091 1.256733161434815393410, /* 0x1.41b943b42945bfffd */ 1092 1.259190116985283935980, /* 0x1.425a4893e5f10000a */ 1093 1.261651875958665236542, /* 0x1.42fb9e0a2df4c0009 */ 1094 1.264118447754797758244, /* 0x1.439d443f608c4fff9 */ 1095 1.266589841787181258708, /* 0x1.443f3b5bebf850008 */ 1096 1.269066067469190262045, /* 0x1.44e183883e561fff7 */ 1097 1.271547134259576328224, /* 0x1.45841cecf7a7a0001 */ 1098 1.274033051628237434048, /* 0x1.462707b2c43020009 */ 1099 1.276523829025464573684, /* 0x1.46ca44023aa410007 */ 1100 1.279019475999373156531, /* 0x1.476dd2045d46ffff0 */ 1101 1.281520002043128991825, /* 0x1.4811b1e1f1f19000b */ 1102 1.284025416692967214122, /* 0x1.48b5e3c3edd74fff4 */ 1103 1.286535729509738823464, /* 0x1.495a67d3613c8fff7 */ 1104 1.289050950070396384145, /* 0x1.49ff3e396e19d000b */ 1105 1.291571087985403654081, /* 0x1.4aa4671f5b401fff1 */ 1106 1.294096152842774794011, /* 0x1.4b49e2ae56d19000d */ 1107 1.296626154297237043484, /* 0x1.4befb10fd84a3fff4 */ 1108 1.299161101984141142272, /* 0x1.4c95d26d41d84fff8 */ 1109 1.301701005575179204100, /* 0x1.4d3c46f01d9f0fff3 */ 1110 1.304245874766450485904, /* 0x1.4de30ec21097d0003 */ 1111 1.306795719266019562007, /* 0x1.4e8a2a0ccce3d0002 */ 1112 1.309350548792467483458, /* 0x1.4f3198fa10346fff5 */ 1113 1.311910373099227200545, /* 0x1.4fd95bb3be8cffffd */ 1114 1.314475201942565174546, /* 0x1.50817263bf0e5fffb */ 1115 1.317045045107389400535, /* 0x1.5129dd3418575000e */ 1116 1.319619912422941299109, /* 0x1.51d29c4f01c54ffff */ 1117 1.322199813675649204855, /* 0x1.527bafde83a310009 */ 1118 1.324784758729532718739, /* 0x1.5325180cfb8b3fffd */ 1119 1.327374757430096474625, /* 0x1.53ced504b2bd0fff4 */ 1120 1.329969819671041886272, /* 0x1.5478e6f02775e0001 */ 1121 1.332569955346704748651, /* 0x1.55234df9d8a59fff8 */ 1122 1.335175174370685002822, /* 0x1.55ce0a4c5a6a9fff6 */ 1123 1.337785486688218616860, /* 0x1.56791c1263abefff7 */ 1124 1.340400902247843806217, /* 0x1.57248376aef21fffa */ 1125 1.343021431036279800211, /* 0x1.57d040a420c0bfff3 */ 1126 1.345647083048053138662, /* 0x1.587c53c5a630f0002 */ 1127 1.348277868295411074918, /* 0x1.5928bd063fd7bfff9 */ 1128 1.350913796821875845231, /* 0x1.59d57c9110ad60006 */ 1129 1.353554878672557082439, /* 0x1.5a8292913d68cfffc */ 1130 1.356201123929036356254, /* 0x1.5b2fff3212db00007 */ 1131 1.358852542671913132777, /* 0x1.5bddc29edcc06fff3 */ 1132 1.361509145047255398051, /* 0x1.5c8bdd032ed16000f */ 1133 1.364170941142184734180, /* 0x1.5d3a4e8a5bf61fff4 */ 1134 1.366837941171020309735, /* 0x1.5de9176042f1effff */ 1135 1.369510155261156381121, /* 0x1.5e9837b062f4e0005 */ 1136 1.372187593620959988833, /* 0x1.5f47afa69436cfff1 */ 1137 1.374870266463378287715, /* 0x1.5ff77f6eb3f8cfffd */ 1138 1.377558184010425845733, /* 0x1.60a7a734a9742fff9 */ 1139 1.380251356531521533853, /* 0x1.6158272490016000c */ 1140 1.382949794301995272203, /* 0x1.6208ff6a8978a000f */ 1141 1.385653507605306700170, /* 0x1.62ba3032c0a280004 */ 1142 1.388362506772382154503, /* 0x1.636bb9a994784000f */ 1143 1.391076802081129493127, /* 0x1.641d9bfb29a7bfff6 */ 1144 1.393796403973427855412, /* 0x1.64cfd7545928b0002 */ 1145 1.396521322756352656542, /* 0x1.65826be167badfff8 */ 1146 1.399251568859207761660, /* 0x1.663559cf20826000c */ 1147 1.401987152677323100733, /* 0x1.66e8a14a29486fffc */ 1148 1.404728084651919228815, /* 0x1.679c427f5a4b6000b */ 1149 1.407474375243217723560, /* 0x1.68503d9ba0add000f */ 1150 1.410226034922914983815, /* 0x1.690492cbf6303fff9 */ 1151 1.412983074197955213304, /* 0x1.69b9423d7b548fff6 */ 1152}; 1153 1154/* All floating-point numbers can be put in one of these categories. */ 1155enum 1156 { 1157 FP_NAN, 1158# define FP_NAN FP_NAN 1159 FP_INFINITE, 1160# define FP_INFINITE FP_INFINITE 1161 FP_ZERO, 1162# define FP_ZERO FP_ZERO 1163 FP_SUBNORMAL, 1164# define FP_SUBNORMAL FP_SUBNORMAL 1165 FP_NORMAL 1166# define FP_NORMAL FP_NORMAL 1167 }; 1168 1169 1170int 1171__fpclassifyf (float x) 1172{ 1173 uint32_t wx; 1174 int retval = FP_NORMAL; 1175 1176 GET_FLOAT_WORD (wx, x); 1177 wx &= 0x7fffffff; 1178 if (wx == 0) 1179 retval = FP_ZERO; 1180 else if (wx < 0x800000) 1181 retval = FP_SUBNORMAL; 1182 else if (wx >= 0x7f800000) 1183 retval = wx > 0x7f800000 ? FP_NAN : FP_INFINITE; 1184 1185 return retval; 1186} 1187 1188 1189int 1190__isinff (float x) 1191{ 1192 int32_t ix,t; 1193 GET_FLOAT_WORD(ix,x); 1194 t = ix & 0x7fffffff; 1195 t ^= 0x7f800000; 1196 t |= -t; 1197 return ~(t >> 31) & (ix >> 30); 1198} 1199 1200/* Return nonzero value if arguments are unordered. */ 1201#define fpclassify(x) \ 1202 (sizeof (x) == sizeof (float) ? __fpclassifyf (x) : __fpclassifyf (x)) 1203 1204#ifndef isunordered 1205#define isunordered(u, v) \ 1206 (__extension__ \ 1207 ({ __typeof__(u) __u = (u); __typeof__(v) __v = (v); \ 1208 fpclassify (__u) == FP_NAN || fpclassify (__v) == FP_NAN; })) 1209#endif 1210 1211/* Return nonzero value if X is less than Y. */ 1212#ifndef isless 1213#define isless(x, y) \ 1214 (__extension__ \ 1215 ({ __typeof__(x) __x = (x); __typeof__(y) __y = (y); \ 1216 !isunordered (__x, __y) && __x < __y; })) 1217#endif 1218 1219/* Return nonzero value if X is greater than Y. */ 1220#ifndef isgreater 1221#define isgreater(x, y) \ 1222 (__extension__ \ 1223 ({ __typeof__(x) __x = (x); __typeof__(y) __y = (y); \ 1224 !isunordered (__x, __y) && __x > __y; })) 1225#endif 1226 1227float rb_exp(float x) 1228{ 1229 static const float himark = 88.72283935546875; 1230 static const float lomark = -103.972084045410; 1231 /* Check for usual case. */ 1232 if (isless (x, himark) && isgreater (x, lomark)) 1233 { 1234 static const float THREEp42 = 13194139533312.0; 1235 static const float THREEp22 = 12582912.0; 1236 /* 1/ln(2). */ 1237#undef M_1_LN2 1238 static const float M_1_LN2 = 1.44269502163f; 1239 /* ln(2) */ 1240#undef M_LN2 1241 static const double M_LN2 = .6931471805599452862; 1242 1243 int tval; 1244 double x22, t, result, dx; 1245 float n, delta; 1246 union ieee754_double ex2_u; 1247#ifndef ROCKBOX 1248 fenv_t oldenv; 1249 1250 feholdexcept (&oldenv); 1251#endif 1252 1253#ifdef FE_TONEAREST 1254 fesetround (FE_TONEAREST); 1255#endif 1256 1257 /* Calculate n. */ 1258 n = x * M_1_LN2 + THREEp22; 1259 n -= THREEp22; 1260 dx = x - n*M_LN2; 1261 1262 /* Calculate t/512. */ 1263 t = dx + THREEp42; 1264 t -= THREEp42; 1265 dx -= t; 1266 1267 /* Compute tval = t. */ 1268 tval = (int) (t * 512.0); 1269 1270 if (t >= 0) 1271 delta = - __exp_deltatable[tval]; 1272 else 1273 delta = __exp_deltatable[-tval]; 1274 1275 /* Compute ex2 = 2^n e^(t/512+delta[t]). */ 1276 ex2_u.d = __exp_atable[tval+177]; 1277 ex2_u.ieee.exponent += (int) n; 1278 1279 /* Approximate e^(dx+delta) - 1, using a second-degree polynomial, 1280 with maximum error in [-2^-10-2^-28,2^-10+2^-28] 1281 less than 5e-11. */ 1282 x22 = (0.5000000496709180453 * dx + 1.0000001192102037084) * dx + delta; 1283 1284 /* Return result. */ 1285#ifndef ROCKBOX 1286 fesetenv (&oldenv); 1287#endif 1288 1289 result = x22 * ex2_u.d + ex2_u.d; 1290 return (float) result; 1291 } 1292 /* Exceptional cases: */ 1293 else if (isless (x, himark)) 1294 { 1295 if (__isinff (x)) 1296 /* e^-inf == 0, with no error. */ 1297 return 0; 1298 else 1299 /* Underflow */ 1300 return TWOM100 * TWOM100; 1301 } 1302 else 1303 /* Return x, if x is a NaN or Inf; or overflow, otherwise. */ 1304 return TWO127*x; 1305} 1306 1307/* Power function, taken from glibc-2.8 and dietlibc-0.32 */ 1308float pow_wrapper(float x, float y) 1309{ 1310 unsigned int e; 1311 float result; 1312 1313 /* Special cases 0^x */ 1314 if(x == 0.0f) 1315 { 1316 if(y > 0.0f) 1317 return 0.0f; 1318 else if(y == 0.0f) 1319 return 1.0f; 1320 else 1321 return 1.0f / x; 1322 } 1323 1324 /* Special case x^n where n is integer */ 1325 if(y == (int) (e = (int) y)) 1326 { 1327 if((int) e < 0) 1328 { 1329 e = -e; 1330 x = 1.0f / x; 1331 } 1332 1333 result = 1.0f; 1334 1335 while(1) 1336 { 1337 if(e & 1) 1338 result *= x; 1339 1340 if((e >>= 1) == 0) 1341 break; 1342 1343 x *= x; 1344 } 1345 1346 return result; 1347 } 1348 1349 /* Normal case */ 1350 return rb_exp(rb_log(x) * y); 1351} 1352 1353double floor_wrapper(double n) 1354{ 1355 if(n < 0.0) 1356 { 1357 int y = (int)n; 1358 return ((float)y == n) ? y : y - 1; 1359 } 1360 else 1361 return (int)n; 1362} 1363 1364double ceil_wrapper(double n) 1365{ 1366 return floor_wrapper(n) + 1.0; 1367} 1368 1369/* Natural logarithm. 1370 Taken from glibc-2.8 */ 1371static const float 1372ln2_hi = 6.9313812256e-01, /* 0x3f317180 */ 1373ln2_lo = 9.0580006145e-06, /* 0x3717f7d1 */ 1374two25 = 3.355443200e+07, /* 0x4c000000 */ 1375Lg1 = 6.6666668653e-01, /* 3F2AAAAB */ 1376Lg2 = 4.0000000596e-01, /* 3ECCCCCD */ 1377Lg3 = 2.8571429849e-01, /* 3E924925 */ 1378Lg4 = 2.2222198546e-01, /* 3E638E29 */ 1379Lg5 = 1.8183572590e-01, /* 3E3A3325 */ 1380Lg6 = 1.5313838422e-01, /* 3E1CD04F */ 1381Lg7 = 1.4798198640e-01; /* 3E178897 */ 1382 1383/* Get a 32 bit int from a float. */ 1384 1385#define GET_FLOAT_WORD(i,d) \ 1386do { \ 1387 ieee_float_shape_type gf_u; \ 1388 gf_u.value = (d); \ 1389 (i) = gf_u.word; \ 1390} while (0) 1391 1392/* Set a float from a 32 bit int. */ 1393 1394#define SET_FLOAT_WORD(d,i) \ 1395do { \ 1396 ieee_float_shape_type sf_u; \ 1397 sf_u.word = (i); \ 1398 (d) = sf_u.value; \ 1399} while (0) 1400 1401#ifdef ROCKBOX_LITTLE_ENDIAN 1402#define __HI(x) *(1+(int*)&x) 1403#define __LO(x) *(int*)&x 1404#define __HIp(x) *(1+(int*)x) 1405#define __LOp(x) *(int*)x 1406#else 1407#define __HI(x) *(int*)&x 1408#define __LO(x) *(1+(int*)&x) 1409#define __HIp(x) *(int*)x 1410#define __LOp(x) *(1+(int*)x) 1411#endif 1412 1413float rb_log(float x) 1414{ 1415 float hfsq, f, s, z, R, w, t1, t2, dk; 1416 int32_t k, ix, i, j; 1417 1418 GET_FLOAT_WORD(ix,x); 1419 1420 k=0; 1421 if (ix < 0x00800000) { /* x < 2**-126 */ 1422 if ((ix&0x7fffffff)==0) 1423 return -two25/(x-x); /* log(+-0)=-inf */ 1424 if (ix<0) return (x-x)/(x-x); /* log(-#) = NaN */ 1425 k -= 25; x *= two25; /* subnormal number, scale up x */ 1426 GET_FLOAT_WORD(ix,x); 1427 } 1428 if (ix >= 0x7f800000) return x+x; 1429 k += (ix>>23)-127; 1430 ix &= 0x007fffff; 1431 i = (ix+(0x95f64<<3))&0x800000; 1432 SET_FLOAT_WORD(x,ix|(i^0x3f800000)); /* normalize x or x/2 */ 1433 k += (i>>23); 1434 f = x-(float)1.0; 1435 if((0x007fffff&(15+ix))<16) { /* |f| < 2**-20 */ 1436 if(f==zero) { 1437 if(k==0) 1438 return zero; 1439 else 1440 { 1441 dk=(float)k; 1442 return dk*ln2_hi+dk*ln2_lo; 1443 } 1444 } 1445 R = f*f*((float)0.5-(float)0.33333333333333333*f); 1446 if(k==0) 1447 return f-R; 1448 else 1449 { 1450 dk=(float)k; 1451 return dk*ln2_hi-((R-dk*ln2_lo)-f); 1452 } 1453 } 1454 s = f/((float)2.0+f); 1455 dk = (float)k; 1456 z = s*s; 1457 i = ix-(0x6147a<<3); 1458 w = z*z; 1459 j = (0x6b851<<3)-ix; 1460 t1= w*(Lg2+w*(Lg4+w*Lg6)); 1461 t2= z*(Lg1+w*(Lg3+w*(Lg5+w*Lg7))); 1462 i |= j; 1463 R = t2+t1; 1464 if(i>0) { 1465 hfsq=(float)0.5*f*f; 1466 if(k==0) 1467 return f-(hfsq-s*(hfsq+R)); 1468 else 1469 return dk*ln2_hi-((hfsq-(s*(hfsq+R)+dk*ln2_lo))-f); 1470 } else { 1471 if(k==0) 1472 return f-s*(f-R); 1473 else 1474 return dk*ln2_hi-((s*(f-R)-dk*ln2_lo)-f); 1475 } 1476}