changed pow() a little
authoreck <none@none>
Tue, 28 Aug 1990 13:59:36 +0000 (13:59 +0000)
committereck <none@none>
Tue, 28 Aug 1990 13:59:36 +0000 (13:59 +0000)
lang/cem/libcc.ansi/math/pow.c

index b9b7106..b4a9006 100644 (file)
@@ -38,17 +38,15 @@ pow(double x, double y)
                x = -x;
        }
        x = log(x);
+
        if (x < 0) {
                x = -x;
                y = -y;
        }
-       if (y > M_LN_MAX_D/x) {
+       /* Beware of overflow in the multiplication */
+       if (x > 1.0 && y > DBL_MAX/x) {
                errno = ERANGE;
-               return 0;
-       }
-       if (y < M_LN_MIN_D/x) {
-               errno = ERANGE;
-               return 0;
+               return result_neg ? -HUGE_VAL : HUGE_VAL;
        }
 
        x = exp(x * y);