Get isfinite, isinf, and isnan right in jerry-math (#4497)

- `finite` is not C99 but a BSD fp classification function, so it
  is removed.
- The standard specifies that `isnan` is a macro (just like
  `isfinite` and `isinf`), so the `isnan` function implementation
  is removed.
- `isfinite` incorrectly classified NAN as finite, which is fixed.
- `isinf` returned 1 for negative infinity. This is not a bug
  according to the standard, but is not aligned with recent glibc,
  which returns -1. This is changed to simplify testing.
- Added test cases for `isfinite` and `isinf` to the unit test of
  jerry-math.
- Added a new pass to unittests to ensure that jerry-math is
  tested.

JerryScript-DCO-1.0-Signed-off-by: Akos Kiss akiss@inf.u-szeged.hu
This commit is contained in:
Akos Kiss
2021-01-18 15:07:25 +01:00
committed by GitHub
parent c4676a21fe
commit ef8a6a9f39
8 changed files with 69 additions and 111 deletions
-2
View File
@@ -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
-41
View File
@@ -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 */
+2 -2
View File
@@ -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
-44
View File
@@ -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 */
-3
View File
@@ -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);
/*