From 141cbefe963e86e4d8dea2566ac27fb1c383c85b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Csaba=20Osztrogon=C3=A1c?= Date: Wed, 24 Jul 2019 07:22:19 -0700 Subject: [PATCH] Fix Math.pow MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The Math.pow implementation calls libm's pow. The ISO C and ES5.1 standards differ on some special cases of pow. jerry-libm is already ES5.1 conform, but system libm libraries on Linux and Windows aren't. Math.pow(NaN, +/-0.0) is NaN on Windows and Linux with system libm, but should be 1.0 according to ES5.1 / 15.8.2.13. This patch handles this special case in Math.pow instead of calling pow of libm. JerryScript-DCO-1.0-Signed-off-by: Csaba Osztrogonác oszi@inf.u-szeged.hu --- jerry-core/ecma/builtin-objects/ecma-builtin-math.c | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/jerry-core/ecma/builtin-objects/ecma-builtin-math.c b/jerry-core/ecma/builtin-objects/ecma-builtin-math.c index 602ffd4cf2..ebc10b1c8e 100644 --- a/jerry-core/ecma/builtin-objects/ecma-builtin-math.c +++ b/jerry-core/ecma/builtin-objects/ecma-builtin-math.c @@ -412,6 +412,11 @@ ecma_builtin_math_dispatch_routine (uint16_t builtin_routine_id, /**< built-in w /* Handle differences between ES5.1 and ISO C standards for pow. */ x = ecma_number_make_nan (); } + else if (ecma_number_is_zero (y)) + { + /* Handle differences between ES5.1 and ISO C standards for pow. */ + x = (ecma_number_t) 1.0; + } else { x = DOUBLE_TO_ECMA_NUMBER_T (pow (x, y));