- double c,s,t,z,tx,ty;
-#ifdef tahoe
- double tahoe_tmp;
-#endif /* tahoe */
- float sx,sy;
- long k=0;
- int n,m;
-
- if(x==zero||!finite(x)) { /* if x is +INF or +0 */
-#if defined(vax)||defined(tahoe)
- return((y>zero)?x:infnan(ERANGE)); /* if y<zero, return +INF */
-#else /* defined(vax)||defined(tahoe) */
- return((y>zero)?x:one/x);
-#endif /* defined(vax)||defined(tahoe) */
- }
- if(x==1.0) return(x); /* if x=1.0, return 1 since y is finite */
-
- /* reduce x to z in [sqrt(1/2)-1, sqrt(2)-1] */
- z=scalb(x,-(n=logb(x)));
-#if !defined(vax)&&!defined(tahoe) /* IEEE double; subnormal number */
- if(n <= -1022) {n += (m=logb(z)); z=scalb(z,-m);}
-#endif /* !defined(vax)&&!defined(tahoe) */
- if(z >= sqrt2 ) {n += 1; z *= half;} z -= one ;
-
- /* log(x) = nlog2+log(1+z) ~ nlog2 + t + tx */
- s=z/(two+z); c=z*z*half; tx=s*(c+log__L(s*s));
- t= z-(c-tx); tx += (z-t)-c;
-
- /* if y*log(x) is neither too big nor too small */
- if((s=logb(y)+logb(n+t)) < 12.0)
- if(s>-60.0) {
-
- /* compute y*log(x) ~ mlog2 + t + c */
- s=y*(n+invln2*t);
- m=s+copysign(half,s); /* m := nint(y*log(x)) */
- k=y;
- if((double)k==y) { /* if y is an integer */
- k = m-k*n;
- sx=t; tx+=(t-sx); }
- else { /* if y is not an integer */
- k =m;
- tx+=n*ln2lo;
- sx=(c=n*ln2hi)+t; tx+=(c-sx)+t; }
- /* end of checking whether k==y */
-
- sy=y; ty=y-sy; /* y ~ sy + ty */
-#ifdef tahoe
- s = (tahoe_tmp = sx)*sy-k*ln2hi;
-#else /* tahoe */
- s=(double)sx*sy-k*ln2hi; /* (sy+ty)*(sx+tx)-kln2 */
-#endif /* tahoe */
- z=(tx*ty-k*ln2lo);
- tx=tx*sy; ty=sx*ty;
- t=ty+z; t+=tx; t+=s;
- c= -((((t-s)-tx)-ty)-z);
-
- /* return exp(y*log(x)) */
- t += exp__E(t,c); return(scalb(one+t,m));
- }
- /* end of if log(y*log(x)) > -60.0 */
-
- else
- /* exp(+- tiny) = 1 with inexact flag */
- {ln2hi+ln2lo; return(one);}
- else if(copysign(one,y)*(n+invln2*t) <zero)
- /* exp(-(big#)) underflows to zero */
- return(scalb(one,-5000));
- else
- /* exp(+(big#)) overflows to INF */
- return(scalb(one, 5000));
-
+ struct Double s, t, __log__D();
+ double __exp__D(), huge = 1e300, tiny = 1e-300;
+
+ if (x == zero)
+ if (y > zero)
+ return (zero);
+ else if (_IEEE)
+ return (huge*huge);
+ else
+ return (infnan(ERANGE));
+ if (x == one)
+ return (one);
+ if (!finite(x))
+ if (y < zero)
+ return (zero);
+ else if (_IEEE)
+ return (huge*huge);
+ else
+ return (infnan(ERANGE));
+ if (y >= 7e18) /* infinity */
+ if (x < 1)
+ return(tiny*tiny);
+ else if (_IEEE)
+ return (huge*huge);
+ else
+ return (infnan(ERANGE));
+
+ /* Return exp(y*log(x)), using simulated extended */
+ /* precision for the log and the multiply. */
+
+ s = __log__D(x);
+ t.a = y;
+ TRUNC(t.a);
+ t.b = y - t.a;
+ t.b = s.b*y + t.b*s.a;
+ t.a *= s.a;
+ s.a = t.a + t.b;
+ s.b = (t.a - s.a) + t.b;
+ return (__exp__D(s.a, s.b));