00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040
00041
00042
00043
00044
00045
00046
00047
00048
00049
00050
00051
00052
00053
00054
00055
00056
00057
00058
00059 static char *rcs_id = "$Source: /home/bos/bk/kpro64-pending/libm/mips/SCCS/s.pow.c $ $Revision: 1.5 $";
00060
00061 #ifdef _CALL_MATHERR
00062 #include <stdio.h>
00063 #include <math.h>
00064 #include <errno.h>
00065 #endif
00066
00067 #include "libm.h"
00068
00069
00070
00071
00072
00073
00074
00075
00076
00077
00078
00079 #if defined(mips) && !defined(__GNUC__)
00080 extern double pow(double, double);
00081
00082 #pragma weak pow = __pow
00083 #endif
00084
00085 #if defined(BUILD_OS_DARWIN)
00086 extern double __pow(double, double);
00087 #pragma weak pow
00088 double pow( double arg1, double arg2) {
00089 return __pow( arg1, arg2 );
00090 }
00091 #elif defined(__GNUC__)
00092 extern double __pow(double, double);
00093
00094 double pow() __attribute__ ((weak, alias ("__pow")));
00095
00096 #endif
00097
00098 extern const du _exptabhi[];
00099 extern const du _exptablo[];
00100 extern const du _logtabhi[];
00101 extern const du _logtablo[];
00102 extern const du _log_rulo[];
00103 extern const fu _log_ruhi[];
00104
00105 static const du Qnan =
00106 {D(QNANHI, QNANLO)};
00107
00108 static const du Neginf =
00109 {D(0xfff00000, 0x00000000)};
00110
00111 static const du Inf =
00112 {D(0x7ff00000, 0x00000000)};
00113
00114 static const du twopm7 =
00115 {D(0x3f800000, 0x00000000)};
00116
00117 static const du twopm55 =
00118 {D(0x3c800000, 0x00000000)};
00119
00120 static const du twop52 =
00121 {D(0x43300000, 0x00000000)};
00122
00123 static const du twop53 =
00124 {D(0x43400000, 0x00000000)};
00125
00126 static const du twopm54 =
00127 {D(0x3c900000, 0x00000000)};
00128
00129 static const du twop512 =
00130 {D(0x5ff00000, 0x00000000)};
00131
00132 static const du twopm1021 =
00133 {D(0x00200000, 0x00000000)};
00134
00135
00136
00137 static const du root2by2p538 =
00138 {D(0x1e56a09e, 0x667f3bcd)};
00139
00140
00141
00142
00143
00144 static const du ylimit =
00145 {D(0x43d74910, 0xd52d3051)};
00146
00147 static const du three2703 =
00148 {D(0x40dfefc0, 0x00000000)};
00149
00150 static const du twopm1024 =
00151 {D(0x00040000, 0x00000000)};
00152
00153 static const du log2_lead =
00154 {D(0x3fe62e42, 0xfefa4000)};
00155
00156 static const du log2_trail =
00157 {D(0xbd48432a, 0x1b0e2634)};
00158
00159 static const du ymin =
00160 {D(0x3b500000, 0x00000000)};
00161
00162 static const du Scaleup =
00163 {D(0x43300000, 0x00000000)};
00164
00165 static const du Magic =
00166 {D(0x43380000, 0x00000000)};
00167
00168
00169
00170 static const du Llimit =
00171 {D(0xc0874910, 0xd52d3052)};
00172
00173
00174
00175 static const du Ulimit =
00176 {D(0x40862e42, 0xfefa39ef)};
00177
00178 static const du rln2by32 =
00179 {D(0x40471547, 0x652b82fe)};
00180
00181 static const du ln2by32hi =
00182 {D(0x3f962e42, 0xfef00000)};
00183
00184 static const du ln2by32lo =
00185 {D(0x3d8473de, 0x6af278ed)};
00186
00187 static const du one =
00188 {D(0x3ff00000, 0x00000000)};
00189
00190
00191
00192 static const du P[] =
00193 {
00194 {D(0x3ff00000, 0x00000000)},
00195 {D(0xbfe00000, 0x00000000)},
00196 {D(0x3fd55555, 0x55555557)},
00197 {D(0xbfd00000, 0x00000001)},
00198 {D(0x3fc99999, 0x9989c6a5)},
00199 {D(0xbfc55555, 0x554a41aa)},
00200 {D(0x3fc2493f, 0xe154c5f3)},
00201 {D(0xbfc00015, 0xd8d52d9d)},
00202 };
00203
00204
00205
00206 static const du Q[] =
00207 {
00208 {D(0x3ff00000, 0x00000000)},
00209 {D(0x3ff00000, 0x00000000)},
00210 {D(0x3fe00000, 0x00000000)},
00211 {D(0x3fc55555, 0x55548f7c)},
00212 {D(0x3fa55555, 0x55545d4e)},
00213 {D(0x3f811115, 0xb7aa905e)},
00214 {D(0x3f56c172, 0x8d739765)},
00215 };
00216
00217 #ifdef _32BIT_MACHINE
00218
00219 static const int twop7 =
00220 {0x40600000};
00221
00222 #else
00223
00224 static const long long twop7 =
00225 {0x4060000000000000ll};
00226
00227 #endif
00228
00229
00230
00231
00232
00233
00234
00235
00236
00237
00238
00239 double
00240 __pow( arg1, arg2 )
00241 double arg1, arg2;
00242 {
00243 #ifdef _32BIT_MACHINE
00244
00245 int ix, iy, xptx, xpty;
00246 int l;
00247 int signx;
00248
00249 #else
00250
00251 long long ix, iy, xptx, xpty;
00252 long long l;
00253 long long signx;
00254
00255 #endif
00256
00257 double x, y;
00258 int i;
00259 int k;
00260 int j, m, n;
00261 double s, z, zz;
00262 double result;
00263 double u;
00264 double xmu, tlo, thi, t, tt;
00265 double q;
00266 double l_lead, l_trail;
00267 double low, high;
00268 double w, ww, v;
00269 double p;
00270 double nd;
00271 double s_lead, s_trail;
00272 double x1, x2;
00273 double twopm;
00274 double sign;
00275 #ifndef _FUSED_MADD
00276 double ylo, yhi;
00277 double zhi, zlo;
00278 #endif
00279 #ifdef _CALL_MATHERR
00280 struct exception exstruct;
00281 #endif
00282
00283
00284
00285
00286
00287 x = arg1;
00288 y = arg2;
00289
00290 sign = 1.0;
00291
00292
00293
00294 #ifdef _32BIT_MACHINE
00295
00296 DBLHI2INT(x, ix);
00297 DBLHI2INT(y, iy);
00298 #else
00299 DBL2LL(x, ix);
00300 DBL2LL(y, iy);
00301 #endif
00302 xptx = (ix >> DMANTWIDTH);
00303 signx = ((xptx >> DEXPWIDTH) & 1);
00304 xptx = (xptx & 0x7ff);
00305
00306 xpty = (iy >> DMANTWIDTH);
00307 xpty &= 0x7ff;
00308
00309 if ( xptx == 0 )
00310 {
00311 x *= Scaleup.d;
00312
00313
00314
00315
00316
00317 if ( x != 0.0 )
00318 {
00319
00320 #ifdef _32BIT_MACHINE
00321
00322 DBLHI2INT(x, ix);
00323 #else
00324 DBL2LL(x, ix);
00325 #endif
00326 xptx = (ix >> DMANTWIDTH);
00327 xptx &= 0x7ff;
00328 xptx -= 52;
00329 }
00330 }
00331
00332
00333
00334
00335
00336 i = (x == 0.0) | (xptx == 0x7ff) | (ix <= 0);
00337 j = (y == 0.0) | (xpty == 0x7ff) | (fabs(y) == 1.0);
00338
00339 if ( i + j != 0 )
00340 goto special;
00341
00342 L:
00343
00344
00345
00346 if ( x == 1.0 )
00347 goto xeqone;
00348
00349 if ( y == 2.0 )
00350 goto yeqtwo;
00351
00352 if ( fabs(y) > ylimit.d )
00353 goto overunder;
00354
00355 if ( xpty < 0x3b5 )
00356 {
00357 if ( y > 0.0 )
00358 y = ymin.d;
00359 else
00360 y = -ymin.d;
00361 }
00362
00363 xptx -= DEXPBIAS;
00364 ix &= (DSIGNMASK & DEXPMASK);
00365 ix |= twop7;
00366
00367 #ifdef _32BIT_MACHINE
00368
00369 INT2DBLHI(ix, x);
00370 #else
00371 LL2DBL(ix, x);
00372 #endif
00373 k = ROUND(x);
00374
00375 u = k;
00376
00377 k -= 128;
00378
00379
00380
00381
00382
00383
00384
00385 xmu = twopm7.d*(x - u);
00386
00387 tlo = _log_rulo[k].d*xmu;
00388 thi = _log_ruhi[k].f*xmu;
00389
00390 t = thi + tlo;
00391 tt = tlo - (t - thi);
00392
00393
00394
00395
00396
00397 if ( k > 64 )
00398 xptx++;
00399
00400
00401
00402 u = (float)t;
00403 v = t - u;
00404 s = u*u*0.5;
00405 z = v*(t + u)*0.5;
00406
00407 w = s + z;
00408 ww = z - (w - s);
00409
00410 l_lead = _logtabhi[k].d;
00411 l_trail = _logtablo[k].d;
00412
00413 l_lead += xptx*log2_lead.d;
00414 l_trail += xptx*log2_trail.d;
00415
00416
00417
00418 q = (((((P[7].d*t + P[6].d)*t + P[5].d)*t +
00419 P[4].d)*t + P[3].d)*t + P[2].d)*(t*t*t);
00420
00421
00422
00423
00424
00425
00426
00427
00428
00429
00430
00431
00432 high = t - w;
00433 ww = w + (high - t) + ww;
00434
00435 w = l_lead + high;
00436 ww = high - (w - l_lead) - ww;
00437
00438 low = (q + (l_trail + (tt - t*tt)));
00439
00440 ww += low;
00441
00442
00443
00444 #ifdef _FUSED_MADD
00445
00446 t = y*w;
00447 tt = y*w - t;
00448
00449 tt += y*ww;
00450
00451
00452
00453 z = t + tt;
00454 zz = t - z + tt;
00455
00456 #else
00457
00458 zhi = (float)w;
00459 zlo = w - zhi + ww;
00460
00461 yhi = (float)y;
00462 ylo = y - yhi;
00463
00464 w = yhi*zhi;
00465 ww = ylo*zhi + y*zlo;
00466
00467
00468
00469 z = w + ww;
00470 zz = ww - (z - w);
00471
00472 #endif
00473
00474
00475
00476 if ( fabs(z) < twopm55.d )
00477 return ( sign*one.d );
00478
00479
00480
00481 if ( z < Llimit.d )
00482 {
00483
00484
00485 #ifdef _CALL_MATHERR
00486
00487 exstruct.type = UNDERFLOW;
00488 exstruct.name = "pow";
00489 exstruct.arg1 = arg1;
00490 exstruct.arg2 = arg2;
00491 exstruct.retval = (sign > 0.0) ? 0.0 : -0.0;
00492
00493 if ( matherr( &exstruct ) == 0 )
00494 {
00495 fprintf(stderr, "underflow range error in pow\n");
00496 SETERRNO(ERANGE);
00497 }
00498
00499 return ( exstruct.retval );
00500 #else
00501 SETERRNO(ERANGE);
00502
00503 return ( (sign > 0.0) ? 0.0 : -0.0 );
00504 #endif
00505 }
00506
00507 if ( z > Ulimit.d )
00508 {
00509
00510
00511 #ifdef _CALL_MATHERR
00512
00513 exstruct.type = OVERFLOW;
00514 exstruct.name = "pow";
00515 exstruct.arg1 = arg1;
00516 exstruct.arg2 = arg2;
00517 exstruct.retval = (sign > 0.0) ? Inf.d : Neginf.d;
00518
00519 if ( matherr( &exstruct ) == 0 )
00520 {
00521 fprintf(stderr, "overflow range error in pow\n");
00522 SETERRNO(ERANGE);
00523 }
00524
00525 return ( exstruct.retval );
00526 #else
00527 SETERRNO(ERANGE);
00528
00529 return ( (sign > 0.0) ? Inf.d : Neginf.d );
00530 #endif
00531 }
00532
00533 nd = z*rln2by32.d;
00534 n = ROUND(nd);
00535 nd = n;
00536
00537 j = n & 0x1f;
00538 m = n >> 5;
00539
00540 s_lead = _exptabhi[j].d;
00541 s_trail = _exptablo[j].d;
00542 s = s_lead + s_trail;
00543
00544 x1 = z - nd*ln2by32hi.d;
00545
00546 x2 = nd*ln2by32lo.d;
00547
00548 x2 -= zz;
00549 y = x1 - x2;
00550
00551
00552
00553
00554
00555 q = ((((Q[6].d*y + Q[5].d)*y + Q[4].d)*y + Q[3].d)*y +
00556 Q[2].d)*(y*y);
00557
00558 p = q - x2 + x1;
00559
00560 result = s_lead + (s_trail + s*p);
00561
00562 if ( fabs(nd) <= three2703.d )
00563 {
00564
00565
00566
00567
00568 #ifdef _32BIT_MACHINE
00569
00570 twopm = 0.0;
00571 l = DEXPBIAS + m;
00572 l <<= DMANTWIDTH;
00573 INT2DBLHI(l, twopm);
00574 #else
00575 l = DEXPBIAS + m;
00576 l <<= DMANTWIDTH;
00577 LL2DBL(l, twopm);
00578 #endif
00579 result *= twopm;
00580
00581 return ( sign*result );
00582 }
00583
00584 if ( m > 1021 )
00585 {
00586 #ifdef _32BIT_MACHINE
00587
00588 DBLHI2INT(result, l);
00589 #else
00590 DBL2LL(result, l);
00591 #endif
00592 n = (l >> DMANTWIDTH);
00593 n &= 0x7ff;
00594
00595 if ( (m + n) > 0x7fe )
00596 {
00597
00598
00599 #ifdef _CALL_MATHERR
00600
00601 exstruct.type = OVERFLOW;
00602 exstruct.name = "pow";
00603 exstruct.arg1 = arg1;
00604 exstruct.arg2 = arg2;
00605 exstruct.retval = (sign > 0.0) ? Inf.d : Neginf.d;
00606
00607 if ( matherr( &exstruct ) == 0 )
00608 {
00609 fprintf(stderr, "overflow range error in pow\n");
00610 SETERRNO(ERANGE);
00611 }
00612
00613 return ( exstruct.retval );
00614 #else
00615 SETERRNO(ERANGE);
00616
00617 return ( (sign > 0.0) ? Inf.d : Neginf.d );
00618 #endif
00619 }
00620
00621 #ifdef _32BIT_MACHINE
00622
00623 l += (m << DMANTWIDTH);
00624 INT2DBLHI(l, result);
00625 #else
00626 l += ((long long)m << DMANTWIDTH);
00627 LL2DBL(l, result);
00628 #endif
00629
00630 return ( sign*result );
00631 }
00632 else
00633 {
00634 m += 1021;
00635
00636 #ifdef _32BIT_MACHINE
00637
00638 twopm = 0.0;
00639 l = DEXPBIAS + m;
00640 l <<= DMANTWIDTH;
00641 INT2DBLHI(l, twopm);
00642 #else
00643 l = DEXPBIAS + m;
00644 l <<= DMANTWIDTH;
00645 LL2DBL(l, twopm);
00646 #endif
00647 result *= twopm;
00648
00649 if ( fabs(result) <= twopm54.d )
00650 {
00651
00652
00653 #ifdef _CALL_MATHERR
00654
00655 exstruct.type = UNDERFLOW;
00656 exstruct.name = "pow";
00657 exstruct.arg1 = arg1;
00658 exstruct.arg2 = arg2;
00659 exstruct.retval = (sign > 0.0) ? 0.0 : -0.0;
00660
00661 if ( matherr( &exstruct ) == 0 )
00662 {
00663 fprintf(stderr, "underflow range error in pow\n");
00664 SETERRNO(ERANGE);
00665 }
00666
00667 return ( exstruct.retval );
00668 #else
00669 SETERRNO(ERANGE);
00670
00671 return ( (sign > 0.0) ? 0.0 : -0.0 );
00672 #endif
00673 }
00674
00675 return ( twopm1021.d*sign*result );
00676 }
00677
00678 special:
00679 if ( y == 0.0 )
00680 return ( one.d );
00681
00682 if ( y == 1.0 )
00683 return ( arg1 );
00684
00685 if ( (y != y) || (x != x) )
00686 {
00687
00688
00689 #ifdef _CALL_MATHERR
00690
00691 exstruct.type = DOMAIN;
00692 exstruct.name = "pow";
00693 exstruct.arg1 = arg1;
00694 exstruct.arg2 = arg2;
00695 exstruct.retval = Qnan.d;
00696
00697 if ( matherr( &exstruct ) == 0 )
00698 {
00699 fprintf(stderr, "domain error in pow\n");
00700 SETERRNO(EDOM);
00701 }
00702
00703 return ( exstruct.retval );
00704 #else
00705
00706 NAN_SETERRNO(EDOM);
00707
00708 return ( Qnan.d );
00709 #endif
00710 }
00711
00712 if ( (y == Inf.d) && (x != 0.0) )
00713 {
00714 if ( fabs(x) > 1.0 )
00715 {
00716
00717
00718 #ifdef _CALL_MATHERR
00719
00720 exstruct.type = OVERFLOW;
00721 exstruct.name = "pow";
00722 exstruct.arg1 = arg1;
00723 exstruct.arg2 = arg2;
00724 exstruct.retval = Inf.d;
00725
00726 if ( matherr( &exstruct ) == 0 )
00727 {
00728 fprintf(stderr, "overflow range error in pow\n");
00729 SETERRNO(ERANGE);
00730 }
00731
00732 return ( exstruct.retval );
00733 #else
00734 SETERRNO(ERANGE);
00735
00736 return ( Inf.d );
00737 #endif
00738 }
00739
00740 if ( fabs(x) < 1.0 )
00741 {
00742
00743
00744 #ifdef _CALL_MATHERR
00745
00746 exstruct.type = UNDERFLOW;
00747 exstruct.name = "pow";
00748 exstruct.arg1 = arg1;
00749 exstruct.arg2 = arg2;
00750 exstruct.retval = 0.0;
00751
00752 if ( matherr( &exstruct ) == 0 )
00753 {
00754 fprintf(stderr, "underflow range error in pow\n");
00755 SETERRNO(ERANGE);
00756 }
00757
00758 return ( exstruct.retval );
00759 #else
00760 SETERRNO(ERANGE);
00761
00762 return ( 0.0 );
00763 #endif
00764 }
00765 }
00766
00767 if ( (y == Neginf.d) && (x != 0.0) )
00768 {
00769 if ( fabs(x) < 1.0 )
00770 {
00771
00772
00773 #ifdef _CALL_MATHERR
00774
00775 exstruct.type = OVERFLOW;
00776 exstruct.name = "pow";
00777 exstruct.arg1 = arg1;
00778 exstruct.arg2 = arg2;
00779 exstruct.retval = Inf.d;
00780
00781 if ( matherr( &exstruct ) == 0 )
00782 {
00783 fprintf(stderr, "overflow range error in pow\n");
00784 SETERRNO(ERANGE);
00785 }
00786
00787 return ( exstruct.retval );
00788 #else
00789 SETERRNO(ERANGE);
00790
00791 return ( Inf.d );
00792 #endif
00793 }
00794
00795 if ( fabs(x) > 1.0 )
00796 {
00797
00798
00799 #ifdef _CALL_MATHERR
00800
00801 exstruct.type = UNDERFLOW;
00802 exstruct.name = "pow";
00803 exstruct.arg1 = arg1;
00804 exstruct.arg2 = arg2;
00805 exstruct.retval = 0.0;
00806
00807 if ( matherr( &exstruct ) == 0 )
00808 {
00809 fprintf(stderr, "underflow range error in pow\n");
00810 SETERRNO(ERANGE);
00811 }
00812
00813 return ( exstruct.retval );
00814 #else
00815 SETERRNO(ERANGE);
00816
00817 return ( 0.0 );
00818 #endif
00819 }
00820 }
00821
00822 if ( (x == 1.0) && (fabs(y) == Inf.d) )
00823 return ( 1.0 );
00824
00825 if ( (x == -1.0) && (fabs(y) == Inf.d) )
00826 {
00827
00828
00829 #ifdef _CALL_MATHERR
00830
00831 exstruct.type = DOMAIN;
00832 exstruct.name = "pow";
00833 exstruct.arg1 = arg1;
00834 exstruct.arg2 = arg2;
00835 exstruct.retval = Qnan.d;
00836
00837 if ( matherr( &exstruct ) == 0 )
00838 {
00839 fprintf(stderr, "domain error in pow\n");
00840 SETERRNO(ERANGE);
00841 }
00842
00843 return ( exstruct.retval );
00844 #else
00845
00846 SETERRNO(ERANGE);
00847
00848 return ( Qnan.d );
00849 #endif
00850 }
00851
00852 if ( (x == 0.0) && (signx == 0) )
00853 {
00854 if ( y > 0.0 )
00855 return ( 0.0 );
00856
00857 if ( y < 0.0 )
00858 {
00859
00860
00861 #ifdef _CALL_MATHERR
00862
00863 exstruct.type = OVERFLOW;
00864 exstruct.name = "pow";
00865 exstruct.arg1 = arg1;
00866 exstruct.arg2 = arg2;
00867 exstruct.retval = Inf.d;
00868
00869 if ( matherr( &exstruct ) == 0 )
00870 {
00871 fprintf(stderr, "overflow range error in pow\n");
00872 SETERRNO(ERANGE);
00873 }
00874
00875 return ( exstruct.retval );
00876 #else
00877
00878 SETERRNO(ERANGE);
00879
00880 return ( Inf.d );
00881 #endif
00882 }
00883 }
00884
00885 if ( y == -1.0 )
00886 {
00887 if ( fabs(arg1) > twopm1024.d )
00888 {
00889 return ( 1/arg1 );
00890 }
00891
00892
00893
00894 #ifdef _CALL_MATHERR
00895
00896 exstruct.type = OVERFLOW;
00897 exstruct.name = "pow";
00898 exstruct.arg1 = arg1;
00899 exstruct.arg2 = arg2;
00900 exstruct.retval = (x > 0.0) ? Inf.d : Neginf.d;
00901
00902 if ( matherr( &exstruct ) == 0 )
00903 {
00904 fprintf(stderr, "overflow range error in pow\n");
00905 SETERRNO(ERANGE);
00906 }
00907
00908 return ( exstruct.retval );
00909 #else
00910
00911 SETERRNO(ERANGE);
00912
00913 if ( x > 0.0 )
00914 return ( Inf.d );
00915 else
00916 return ( Neginf.d );
00917 #endif
00918 }
00919
00920 if ( (x == 0.0) && (signx != 0) )
00921 {
00922
00923
00924 if ( fabs(y) >= twop53.d )
00925 {
00926 goto next;
00927 }
00928 else if ( fabs(y) >= twop52.d )
00929 {
00930
00931
00932 #ifdef _32BIT_MACHINE
00933
00934 DBLLO2INT(y, l);
00935 #else
00936 DBL2LL(y, l);
00937 #endif
00938 }
00939 else
00940 {
00941 u = y + Magic.d;
00942
00943 #ifdef _32BIT_MACHINE
00944
00945 DBLLO2INT(u, l);
00946 #else
00947 DBL2LL(u, l);
00948 #endif
00949 u = u - Magic.d;
00950
00951 if ( u != y )
00952 {
00953
00954
00955 goto next;
00956 }
00957
00958 }
00959
00960 if ( (l&1) == 1 )
00961 {
00962 if ( y > 0.0 )
00963 return ( -0.0 );
00964 else
00965 {
00966
00967
00968 #ifdef _CALL_MATHERR
00969
00970 exstruct.type = OVERFLOW;
00971 exstruct.name = "pow";
00972 exstruct.arg1 = arg1;
00973 exstruct.arg2 = arg2;
00974 exstruct.retval = Neginf.d;
00975
00976 if ( matherr( &exstruct ) == 0 )
00977 {
00978 fprintf(stderr, "overflow range error in pow\n");
00979 SETERRNO(ERANGE);
00980 }
00981
00982 return ( exstruct.retval );
00983 #else
00984
00985 SETERRNO(ERANGE);
00986
00987 return ( Neginf.d );
00988 #endif
00989 }
00990
00991 }
00992
00993 next:
00994 if ( y > 0.0 )
00995 return ( 0.0 );
00996
00997 if ( y < 0.0 )
00998 {
00999
01000
01001 #ifdef _CALL_MATHERR
01002
01003 exstruct.type = OVERFLOW;
01004 exstruct.name = "pow";
01005 exstruct.arg1 = arg1;
01006 exstruct.arg2 = arg2;
01007 exstruct.retval = Inf.d;
01008
01009 if ( matherr( &exstruct ) == 0 )
01010 {
01011 fprintf(stderr, "overflow range error in pow\n");
01012 SETERRNO(ERANGE);
01013 }
01014
01015 return ( exstruct.retval );
01016 #else
01017
01018 SETERRNO(ERANGE);
01019
01020 return ( Inf.d );
01021 #endif
01022 }
01023 }
01024
01025 if ( x == Inf.d )
01026 {
01027 if ( y > 0.0 )
01028 return ( Inf.d );
01029
01030 if ( y < 0.0 )
01031 return ( 0.0 );
01032 }
01033
01034 if ( x == Neginf.d )
01035 {
01036
01037
01038 if ( fabs(y) >= twop53.d )
01039 {
01040 goto next_2;
01041 }
01042 else if ( fabs(y) >= twop52.d )
01043 {
01044
01045
01046 #ifdef _32BIT_MACHINE
01047
01048 DBLLO2INT(y, l);
01049 #else
01050 DBL2LL(y, l);
01051 #endif
01052 }
01053 else
01054 {
01055 u = y + Magic.d;
01056
01057 #ifdef _32BIT_MACHINE
01058
01059 DBLLO2INT(u, l);
01060 #else
01061 DBL2LL(u, l);
01062 #endif
01063 u = u - Magic.d;
01064
01065 if ( u != y )
01066 {
01067
01068
01069 goto next_2;
01070 }
01071 }
01072
01073 if ( (l&1) == 1 )
01074 {
01075 if ( y > 0.0 )
01076 return ( Neginf.d );
01077 else
01078 return ( -0.0 );
01079
01080 }
01081
01082 next_2:
01083 if ( y > 0.0 )
01084 return ( Inf.d );
01085
01086 if ( y < 0.0 )
01087 return ( 0.0 );
01088 }
01089
01090 if ( x < 0.0 )
01091 {
01092
01093
01094 if ( fabs(y) >= twop53.d )
01095 {
01096 sign = 1.0;
01097 }
01098 else if ( fabs(y) >= twop52.d )
01099 {
01100
01101
01102 #ifdef _32BIT_MACHINE
01103
01104 DBLLO2INT(y, l);
01105 #else
01106 DBL2LL(y, l);
01107 #endif
01108 if ( l%2 == 0 )
01109 {
01110 sign = 1.0;
01111 }
01112 else
01113 {
01114 sign = -1.0;
01115 }
01116 }
01117 else
01118 {
01119
01120
01121 u = y + Magic.d;
01122
01123 #ifdef _32BIT_MACHINE
01124
01125 DBLLO2INT(u, l);
01126 #else
01127 DBL2LL(u, l);
01128 #endif
01129 u = u - Magic.d;
01130
01131 if ( u != y )
01132 {
01133
01134
01135 #ifdef _CALL_MATHERR
01136 exstruct.type = DOMAIN;
01137 exstruct.name = "pow";
01138 exstruct.arg1 = x;
01139 exstruct.arg2 = y;
01140 exstruct.retval = Qnan.d;
01141
01142 if ( matherr( &exstruct ) == 0 )
01143 {
01144 fprintf(stderr, "domain error in pow\n");
01145 SETERRNO(EDOM);
01146 }
01147
01148 return ( exstruct.retval );
01149 #else
01150 SETERRNO(EDOM);
01151
01152 return ( Qnan.d );
01153 #endif
01154 }
01155
01156 if ( l%2 == 0 )
01157 {
01158 sign = 1.0;
01159 }
01160 else
01161 {
01162 sign = -1.0;
01163 }
01164 }
01165
01166 x = fabs(x);
01167 }
01168
01169 goto L;
01170
01171 xeqone:
01172 return ( sign*x );
01173
01174 yeqtwo:
01175 if ( fabs(arg1) >= twop512.d )
01176 {
01177
01178
01179 #ifdef _CALL_MATHERR
01180
01181 exstruct.type = OVERFLOW;
01182 exstruct.name = "pow";
01183 exstruct.arg1 = arg1;
01184 exstruct.arg2 = arg2;
01185 exstruct.retval = Inf.d;
01186
01187 if ( matherr( &exstruct ) == 0 )
01188 {
01189 fprintf(stderr, "overflow range error in pow\n");
01190 SETERRNO(ERANGE);
01191 }
01192
01193 return ( exstruct.retval );
01194 #else
01195 SETERRNO(ERANGE);
01196
01197 return ( Inf.d );
01198 #endif
01199 }
01200
01201 if ( fabs(arg1) < root2by2p538.d )
01202 {
01203
01204
01205 #ifdef _CALL_MATHERR
01206
01207 exstruct.type = UNDERFLOW;
01208 exstruct.name = "pow";
01209 exstruct.arg1 = arg1;
01210 exstruct.arg2 = arg2;
01211 exstruct.retval = 0.0;
01212
01213 if ( matherr( &exstruct ) == 0 )
01214 {
01215 fprintf(stderr, "underflow range error in pow\n");
01216 SETERRNO(ERANGE);
01217 }
01218
01219 return ( exstruct.retval );
01220 #else
01221 SETERRNO(ERANGE);
01222
01223 return ( 0.0 );
01224 #endif
01225 }
01226
01227 return ( arg1*arg1 );
01228
01229 overunder:
01230
01231
01232
01233
01234
01235 if ( ((x > 1.0) && (y > 0.0)) ||
01236 ((x < 1.0) && (y < 0.0))
01237 )
01238 {
01239
01240
01241 #ifdef _CALL_MATHERR
01242
01243 exstruct.type = OVERFLOW;
01244 exstruct.name = "pow";
01245 exstruct.arg1 = arg1;
01246 exstruct.arg2 = arg2;
01247 exstruct.retval = (sign > 0.0) ? Inf.d : Neginf.d;
01248
01249 if ( matherr( &exstruct ) == 0 )
01250 {
01251 fprintf(stderr, "overflow error in pow\n");
01252 SETERRNO(ERANGE);
01253 }
01254
01255 return ( exstruct.retval );
01256 #else
01257 SETERRNO(ERANGE);
01258
01259 return ( (sign > 0.0) ? Inf.d : Neginf.d );
01260 #endif
01261 }
01262
01263
01264
01265 #ifdef _CALL_MATHERR
01266
01267 exstruct.type = UNDERFLOW;
01268 exstruct.name = "pow";
01269 exstruct.arg1 = arg1;
01270 exstruct.arg2 = arg2;
01271 exstruct.retval = (sign > 0.0) ? 0.0 : -0.0;
01272
01273 if ( matherr( &exstruct ) == 0 )
01274 {
01275 fprintf(stderr, "underflow error in pow\n");
01276 SETERRNO(ERANGE);
01277 }
01278
01279 return ( exstruct.retval );
01280 #else
01281 SETERRNO(ERANGE);
01282
01283 return ( (sign > 0.0) ? 0.0 : -0.0 );
01284 #endif
01285
01286 }
01287
01288 #ifdef NO_LONG_DOUBLE
01289
01290 #if defined(BUILD_OS_DARWIN)
01291 extern long double __powl(long double, long double);
01292 long double powl( long double arg1, long double arg2) {
01293 return ( (long double)__pow((double)arg1, (double)arg2) );
01294 }
01295 #elif defined(__GNUC__)
01296 extern long double __powl(long double, long double);
01297
01298 long double powl() __attribute__ ((weak, alias ("__powl")));
01299
01300 #endif
01301
01302 long double
01303 __powl( arg1, arg2 )
01304 long double arg1, arg2;
01305 {
01306 return ( (long double)__pow((double)arg1, (double)arg2) );
01307 }
01308
01309 #endif
01310