Bug 864265 - Move integer exponent check from js_math_pow to ecmaPow. r=h4writer
authorJan de Mooij <jdemooij@mozilla.com>
Mon, 22 Apr 2013 12:19:19 +0200
changeset 129470 ebb2d369bad2044b742fc54251fb985efbbc5e46
parent 129469 58fa28d2b7bbd5f37135478962952fab2512057b
child 129471 e2f4b1c75ff6da7d390a278418177c692e2c68f9
push idunknown
push userunknown
push dateunknown
reviewersh4writer
bugs864265
milestone23.0a1
Bug 864265 - Move integer exponent check from js_math_pow to ecmaPow. r=h4writer
js/src/jsmath.cpp
--- a/js/src/jsmath.cpp
+++ b/js/src/jsmath.cpp
@@ -465,16 +465,23 @@ js::powi(double x, int y)
 // Disable PGO for Math.pow() and related functions (see bug 791214).
 #if defined(_MSC_VER)
 # pragma optimize("g", off)
 #endif
 double
 js::ecmaPow(double x, double y)
 {
     /*
+     * Use powi if the exponent is an integer-valued double. We don't have to
+     * check for NaN since a comparison with NaN is always false.
+     */
+    if (int32_t(y) == y)
+        return powi(x, int32_t(y));
+
+    /*
      * Because C99 and ECMA specify different behavior for pow(),
      * we need to wrap the libm call to make it ECMA compliant.
      */
     if (!MOZ_DOUBLE_IS_FINITE(y) && (x == 1.0 || x == -1.0))
         return js_NaN;
     /* pow(x, +-0) is always 1, even for x = NaN (MSVC gets this wrong). */
     if (y == 0)
         return 1;
@@ -486,17 +493,17 @@ js::ecmaPow(double x, double y)
 
 // Disable PGO for Math.pow() and related functions (see bug 791214).
 #if defined(_MSC_VER)
 # pragma optimize("g", off)
 #endif
 JSBool
 js_math_pow(JSContext *cx, unsigned argc, Value *vp)
 {
-    double x, y, z;
+    double x, y;
 
     if (argc <= 1) {
         vp->setDouble(js_NaN);
         return JS_TRUE;
     }
     if (!ToNumber(cx, vp[2], &x) || !ToNumber(cx, vp[3], &y))
         return JS_FALSE;
     /*
@@ -514,25 +521,17 @@ js_math_pow(JSContext *cx, unsigned argc
         }
     }
     /* pow(x, +-0) is always 1, even for x = NaN. */
     if (y == 0) {
         vp->setInt32(1);
         return JS_TRUE;
     }
 
-    /*
-     * Use powi if the exponent is an integer or an integer-valued double.
-     * We don't have to check for NaN since a comparison with NaN is always
-     * false.
-     */
-    if (int32_t(y) == y)
-        z = powi(x, int32_t(y));
-    else
-        z = ecmaPow(x, y);
+    double z = ecmaPow(x, y);
 
     vp->setNumber(z);
     return JS_TRUE;
 }
 #if defined(_MSC_VER)
 # pragma optimize("", on)
 #endif