Fixing Math.pow

The Math.pow implementation relies on libm's pow. However, the ISO C
and ES5.1 standards differ on pow:
  * `x ** NAN` is NAN in ES but `+1 ** y` is 1 in C
  * `+-1 ** +-INF` is NAN in ES but 1 in C

This patch:
  * Modifies the Math.pow implementation to handle the special cases
    instead calling pow.
  * Adds a test case to jerry-test-suite as it did not test
    `Math.pow(1,NaN)`.
  * Fixes jerry-libm's pow, as it was not standard conforming, which
    helped hiding the error in Math.pow.
  * Updates the unit test for libm.

JerryScript-DCO-1.0-Signed-off-by: Akos Kiss akiss@inf.u-szeged.hu
This commit is contained in:
Akos Kiss
2016-08-10 16:24:12 +02:00
parent 8f76bab92e
commit 9d4f7c917f
5 changed files with 41 additions and 6 deletions
-2
View File
@@ -465,13 +465,11 @@ main (int argc, char **args)
GEN_DBL_TEST (pow (1.0, -1.0));
GEN_DBL_TEST (pow (-1.0, 1.0));
GEN_DBL_TEST (pow (-1.0, -1.0));
/* SKIPPED: reference libm implementation seems to (incorrectly?) result 1.0 instead of NAN
GEN_DBL_TEST (pow (1.0, INFINITY));
GEN_DBL_TEST (pow (1.0, -INFINITY));
GEN_DBL_TEST (pow (-1.0, INFINITY));
GEN_DBL_TEST (pow (-1.0, -INFINITY));
GEN_DBL_TEST (pow (1.0, NAN));
*/
GEN_DBL_TEST (pow (-1.0, NAN));
GEN_DBL_TEST (pow (INFINITY, 0.0));
GEN_DBL_TEST (pow (INFINITY, -0.0));