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:
@@ -0,0 +1,16 @@
|
||||
// Copyright 2016 Samsung Electronics Co., Ltd.
|
||||
// Copyright 2016 University of Szeged
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
assert(isNaN(Math.pow(1, NaN)));
|
||||
@@ -330,6 +330,11 @@ check_double ("pow (1.0, 1.0)", pow (1.0, 1.0), 1.00000000000000000000E+00);
|
||||
check_double ("pow (1.0, -1.0)", pow (1.0, -1.0), 1.00000000000000000000E+00);
|
||||
check_double ("pow (-1.0, 1.0)", pow (-1.0, 1.0), -1.00000000000000000000E+00);
|
||||
check_double ("pow (-1.0, -1.0)", pow (-1.0, -1.0), -1.00000000000000000000E+00);
|
||||
check_double ("pow (1.0, INFINITY)", pow (1.0, INFINITY), 1.00000000000000000000E+00);
|
||||
check_double ("pow (1.0, -INFINITY)", pow (1.0, -INFINITY), 1.00000000000000000000E+00);
|
||||
check_double ("pow (-1.0, INFINITY)", pow (-1.0, INFINITY), 1.00000000000000000000E+00);
|
||||
check_double ("pow (-1.0, -INFINITY)", pow (-1.0, -INFINITY), 1.00000000000000000000E+00);
|
||||
check_double ("pow (1.0, NAN)", pow (1.0, NAN), 1.00000000000000000000E+00);
|
||||
check_double ("pow (-1.0, NAN)", pow (-1.0, NAN), NAN);
|
||||
check_double ("pow (INFINITY, 0.0)", pow (INFINITY, 0.0), 1.00000000000000000000E+00);
|
||||
check_double ("pow (INFINITY, -0.0)", pow (INFINITY, -0.0), 1.00000000000000000000E+00);
|
||||
|
||||
Reference in New Issue
Block a user