diff --git a/jerry-math/CMakeLists.txt b/jerry-math/CMakeLists.txt index b75bf93b8..0a1b4748a 100644 --- a/jerry-math/CMakeLists.txt +++ b/jerry-math/CMakeLists.txt @@ -43,10 +43,8 @@ set(SOURCE_MATH exp.c expm1.c fabs.c - finite.c floor.c fmod.c - isnan.c log.c log10.c log1p.c diff --git a/jerry-math/finite.c b/jerry-math/finite.c deleted file mode 100644 index f1a8dad2e..000000000 --- a/jerry-math/finite.c +++ /dev/null @@ -1,41 +0,0 @@ -/* Copyright JS Foundation and other contributors, http://js.foundation - * - * 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. - * - * This file is based on work under the following copyright and permission - * notice: - * - * Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved. - * - * Developed at SunSoft, a Sun Microsystems, Inc. business. - * Permission to use, copy, modify, and distribute this - * software is freely granted, provided that this notice - * is preserved. - * - * @(#)s_finite.c 1.3 95/01/18 - */ - -#include "jerry-math-internal.h" - -/* finite(x) returns 1 is x is finite, else 0; - * no branching! - */ - -int -finite (double x) -{ - int hx; - - hx = __HI (x); - return (unsigned) ((hx & 0x7fffffff) - 0x7ff00000) >> 31; -} /* finite */ diff --git a/jerry-math/include/math.h b/jerry-math/include/math.h index f6aaab927..f3c23a882 100644 --- a/jerry-math/include/math.h +++ b/jerry-math/include/math.h @@ -27,8 +27,8 @@ extern "C" #define HUGE_VAL INFINITY #define isnan(x) ((x) != (x)) -#define isinf(x) (((x) == INFINITY) || ((x) == -INFINITY)) -#define isfinite(x) (!(isinf(x)) && (x != NAN)) +#define isinf(x) ((x) == INFINITY ? 1 : (x) == -INFINITY ? -1 : 0) +#define isfinite(x) (!isinf(x) && !isnan(x)) /* Exponential and Logarithmic constants. */ #define M_E 2.7182818284590452353602874713526625 diff --git a/jerry-math/isnan.c b/jerry-math/isnan.c deleted file mode 100644 index 723653c12..000000000 --- a/jerry-math/isnan.c +++ /dev/null @@ -1,44 +0,0 @@ -/* Copyright JS Foundation and other contributors, http://js.foundation - * - * 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. - * - * This file is based on work under the following copyright and permission - * notice: - * - * Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved. - * - * Developed at SunSoft, a Sun Microsystems, Inc. business. - * Permission to use, copy, modify, and distribute this - * software is freely granted, provided that this notice - * is preserved. - * - * @(#)s_isnan.c 1.3 95/01/18 - */ - -#include "jerry-math-internal.h" - -/* isnan(x) returns 1 is x is nan, else 0; - * no branching! - */ - -int -isnan (double x) -{ - int hx, lx; - - hx = (__HI (x) & 0x7fffffff); - lx = __LO (x); - hx |= (unsigned) (lx | (-lx)) >> 31; - hx = 0x7ff00000 - hx; - return ((unsigned) (hx)) >> 31; -} /* isnan */ diff --git a/jerry-math/jerry-math-internal.h b/jerry-math/jerry-math-internal.h index f22a66dab..9ced0a881 100644 --- a/jerry-math/jerry-math-internal.h +++ b/jerry-math/jerry-math-internal.h @@ -112,9 +112,6 @@ double fabs (double x); double floor (double x); double fmod (double x, double y); -int isnan (double x); -int finite (double x); - double nextafter (double x, double y); /* diff --git a/tests/unit-math/test-math.inc.h b/tests/unit-math/test-math.inc.h index d102ddf39..213367ad0 100644 --- a/tests/unit-math/test-math.inc.h +++ b/tests/unit-math/test-math.inc.h @@ -396,6 +396,36 @@ check_double ("fmod (6.5, 2.3)", fmod (6.5, 2.3), 1.90000000000000035527E+00); check_double ("fmod (6.5, -2.3)", fmod (6.5, -2.3), 1.90000000000000035527E+00); check_double ("fmod (-6.5, 2.3)", fmod (-6.5, 2.3), -1.90000000000000035527E+00); check_double ("fmod (-6.5, -2.3)", fmod (-6.5, -2.3), -1.90000000000000035527E+00); +check_int ("isfinite (0.0)", isfinite (0.0), 1); +check_int ("isfinite (-0.0)", isfinite (-0.0), 1); +check_int ("isfinite (1.0)", isfinite (1.0), 1); +check_int ("isfinite (-1.0)", isfinite (-1.0), 1); +check_int ("isfinite (INFINITY)", isfinite (INFINITY), 0); +check_int ("isfinite (-INFINITY)", isfinite (-INFINITY), 0); +check_int ("isfinite (NAN)", isfinite (NAN), 0); +check_int ("isfinite (3.14)", isfinite (3.14), 1); +check_int ("isfinite (-3.14)", isfinite (-3.14), 1); +check_int ("isfinite (0.7)", isfinite (0.7), 1); +check_int ("isfinite (-0.7)", isfinite (-0.7), 1); +check_int ("isfinite (3.72e-09)", isfinite (3.72e-09), 1); +check_int ("isfinite (-3.72e-09)", isfinite (-3.72e-09), 1); +check_int ("isfinite (7.37e+19)", isfinite (7.37e+19), 1); +check_int ("isfinite (-7.37e+19)", isfinite (-7.37e+19), 1); +check_int ("isinf (0.0)", isinf (0.0), 0); +check_int ("isinf (-0.0)", isinf (-0.0), 0); +check_int ("isinf (1.0)", isinf (1.0), 0); +check_int ("isinf (-1.0)", isinf (-1.0), 0); +check_int ("isinf (INFINITY)", isinf (INFINITY), 1); +check_int ("isinf (-INFINITY)", isinf (-INFINITY), -1); +check_int ("isinf (NAN)", isinf (NAN), 0); +check_int ("isinf (3.14)", isinf (3.14), 0); +check_int ("isinf (-3.14)", isinf (-3.14), 0); +check_int ("isinf (0.7)", isinf (0.7), 0); +check_int ("isinf (-0.7)", isinf (-0.7), 0); +check_int ("isinf (3.72e-09)", isinf (3.72e-09), 0); +check_int ("isinf (-3.72e-09)", isinf (-3.72e-09), 0); +check_int ("isinf (7.37e+19)", isinf (7.37e+19), 0); +check_int ("isinf (-7.37e+19)", isinf (-7.37e+19), 0); check_int ("isnan (0.0)", isnan (0.0), 0); check_int ("isnan (-0.0)", isnan (-0.0), 0); check_int ("isnan (1.0)", isnan (1.0), 0); diff --git a/tools/run-tests.py b/tools/run-tests.py index 1d664906d..255e616e0 100755 --- a/tools/run-tests.py +++ b/tools/run-tests.py @@ -72,6 +72,9 @@ JERRY_UNITTESTS_OPTIONS = [ skip=skip_if((sys.platform == 'win32'), 'FEATURE_INIT_FINI build flag isn\'t supported on Windows,' + ' because Microsoft Visual C/C++ Compiler doesn\'t support' + ' library constructors and destructors.')), + Options('unittests-es5.1-debug-math', + OPTIONS_COMMON + OPTIONS_UNITTESTS + OPTIONS_PROFILE_ES51 + OPTIONS_DEBUG + + ['--jerry-math=on']), ] # Test options for jerry-tests diff --git a/tools/unit-tests/gen-test-math.c b/tools/unit-tests/gen-test-math.c index 650f0ac65..165b1a3a6 100644 --- a/tools/unit-tests/gen-test-math.c +++ b/tools/unit-tests/gen-test-math.c @@ -442,25 +442,6 @@ main (int argc, char **args) GEN_DBL_TEST (fabs (7.37e+19)); GEN_DBL_TEST (fabs (-7.37e+19)); - /* finite tests */ - /* SKIPPED: not publicly declared in jerry-math - GEN_INT_TEST (finite (0.0)); - GEN_INT_TEST (finite (-0.0)); - GEN_INT_TEST (finite (1.0)); - GEN_INT_TEST (finite (-1.0)); - GEN_INT_TEST (finite (INFINITY)); - GEN_INT_TEST (finite (-INFINITY)); - GEN_INT_TEST (finite (NAN)); - GEN_INT_TEST (finite (3.14)); - GEN_INT_TEST (finite (-3.14)); - GEN_INT_TEST (finite (0.7)); - GEN_INT_TEST (finite (-0.7)); - GEN_INT_TEST (finite (3.72e-09)); - GEN_INT_TEST (finite (-3.72e-09)); - GEN_INT_TEST (finite (7.37e+19)); - GEN_INT_TEST (finite (-7.37e+19)); - */ - /* floor tests */ GEN_DBL_TEST (floor (0.0)); GEN_DBL_TEST (floor (-0.0)); @@ -533,6 +514,40 @@ main (int argc, char **args) GEN_DBL_TEST (fmod (-6.5, 2.3)); GEN_DBL_TEST (fmod (-6.5, -2.3)); + /* isfinite tests */ + GEN_INT_TEST (isfinite (0.0)); + GEN_INT_TEST (isfinite (-0.0)); + GEN_INT_TEST (isfinite (1.0)); + GEN_INT_TEST (isfinite (-1.0)); + GEN_INT_TEST (isfinite (INFINITY)); + GEN_INT_TEST (isfinite (-INFINITY)); + GEN_INT_TEST (isfinite (NAN)); + GEN_INT_TEST (isfinite (3.14)); + GEN_INT_TEST (isfinite (-3.14)); + GEN_INT_TEST (isfinite (0.7)); + GEN_INT_TEST (isfinite (-0.7)); + GEN_INT_TEST (isfinite (3.72e-09)); + GEN_INT_TEST (isfinite (-3.72e-09)); + GEN_INT_TEST (isfinite (7.37e+19)); + GEN_INT_TEST (isfinite (-7.37e+19)); + + /* isinf tests */ + GEN_INT_TEST (isinf (0.0)); + GEN_INT_TEST (isinf (-0.0)); + GEN_INT_TEST (isinf (1.0)); + GEN_INT_TEST (isinf (-1.0)); + GEN_INT_TEST (isinf (INFINITY)); + GEN_INT_TEST (isinf (-INFINITY)); + GEN_INT_TEST (isinf (NAN)); + GEN_INT_TEST (isinf (3.14)); + GEN_INT_TEST (isinf (-3.14)); + GEN_INT_TEST (isinf (0.7)); + GEN_INT_TEST (isinf (-0.7)); + GEN_INT_TEST (isinf (3.72e-09)); + GEN_INT_TEST (isinf (-3.72e-09)); + GEN_INT_TEST (isinf (7.37e+19)); + GEN_INT_TEST (isinf (-7.37e+19)); + /* isnan tests */ GEN_INT_TEST (isnan (0.0)); GEN_INT_TEST (isnan (-0.0));