From cac8501966fbc8f5b862fbeb38ed0222c3038a28 Mon Sep 17 00:00:00 2001 From: Benjamin Bouvier Date: Wed, 29 Jan 2014 12:12:03 +0100 Subject: [PATCH] Bug 942550: Take care of all particular cases in ecmaPow instead of js_math_pow; r=jandem --- js/src/jit-test/tests/ion/bug942550.js | 6 +++++ js/src/jsmath.cpp | 34 +++++++++----------------- 2 files changed, 18 insertions(+), 22 deletions(-) create mode 100644 js/src/jit-test/tests/ion/bug942550.js diff --git a/js/src/jit-test/tests/ion/bug942550.js b/js/src/jit-test/tests/ion/bug942550.js new file mode 100644 index 00000000000..16344f08482 --- /dev/null +++ b/js/src/jit-test/tests/ion/bug942550.js @@ -0,0 +1,6 @@ +function pow(x,y) { + return Math.pow(x,y); +} +var x = pow(3, -.5); +var y = pow(3, -.5); +assertEq(x, y); diff --git a/js/src/jsmath.cpp b/js/src/jsmath.cpp index 10169094b64..e6a1d42eec8 100644 --- a/js/src/jsmath.cpp +++ b/js/src/jsmath.cpp @@ -625,9 +625,21 @@ js::ecmaPow(double x, double y) */ if (!IsFinite(y) && (x == 1.0 || x == -1.0)) return GenericNaN(); + /* pow(x, +-0) is always 1, even for x = NaN (MSVC gets this wrong). */ if (y == 0) return 1; + + /* + * Special case for square roots. Note that pow(x, 0.5) != sqrt(x) + * when x = -0.0, so we have to guard for this. + */ + if (IsFinite(x) && x != 0.0) { + if (y == 0.5) + return sqrt(x); + if (y == -0.5) + return 1.0 / sqrt(x); + } return pow(x, y); } #if defined(_MSC_VER) @@ -651,29 +663,7 @@ js_math_pow(JSContext *cx, unsigned argc, Value *vp) if (!ToNumber(cx, args.get(1), &y)) return false; - /* - * Special case for square roots. Note that pow(x, 0.5) != sqrt(x) - * when x = -0.0, so we have to guard for this. - */ - if (IsFinite(x) && x != 0.0) { - if (y == 0.5) { - args.rval().setNumber(sqrt(x)); - return true; - } - if (y == -0.5) { - args.rval().setNumber(1.0/sqrt(x)); - return true; - } - } - - /* pow(x, +-0) is always 1, even for x = NaN. */ - if (y == 0) { - args.rval().setInt32(1); - return true; - } - double z = ecmaPow(x, y); - args.rval().setNumber(z); return true; }