From ba908b4d16bd35a7f0fcc300c766c0ef6c4d1583 Mon Sep 17 00:00:00 2001 From: Jan de Mooij Date: Thu, 19 Jul 2012 20:43:32 +0200 Subject: [PATCH] Bug 775680 - Math.pow should use powi if the exponent is an integer-valued double. r=dvander --- js/src/jsmath.cpp | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/js/src/jsmath.cpp b/js/src/jsmath.cpp index 2b61496bff50..e0db8dd48b36 100644 --- a/js/src/jsmath.cpp +++ b/js/src/jsmath.cpp @@ -475,8 +475,13 @@ js_math_pow(JSContext *cx, unsigned argc, Value *vp) return JS_TRUE; } - if (vp[3].isInt32()) - z = powi(x, vp[3].toInt32()); + /* + * 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 = pow(x, y);