Fixes math library compiling on msvc (#4511)

JerryScript-DCO-1.0-Signed-off-by: Yonggang Luo luoyonggang@gmail.com
This commit is contained in:
Yonggang Luo 2021-02-04 20:19:13 +08:00 committed by GitHub
parent 9dbb594170
commit aa941ed58e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
8 changed files with 40 additions and 21 deletions

View File

@ -18,11 +18,11 @@ project (${JERRY_MATH_NAME} C)
# Compiler / linker flags
# TODO: Reduce the below list of warning/error disablings as much as possible
set(COMPILE_FLAGS_MATH "${COMPILE_FLAGS_MATH} -Wno-error=sign-compare")
set(COMPILE_FLAGS_MATH "${COMPILE_FLAGS_MATH} -Wno-error=sign-conversion")
set(COMPILE_FLAGS_MATH "${COMPILE_FLAGS_MATH} -Wno-sign-conversion")
set(COMPILE_FLAGS_MATH "${COMPILE_FLAGS_MATH} -Wno-sign-compare")
set(COMPILE_FLAGS_MATH "${COMPILE_FLAGS_MATH} -Wno-strict-aliasing")
set(COMPILE_FLAGS_MATH_GCC_CLANG "${COMPILE_FLAGS_MATH_GCC_CLANG} -Wno-error=sign-compare")
set(COMPILE_FLAGS_MATH_GCC_CLANG "${COMPILE_FLAGS_MATH_GCC_CLANG} -Wno-error=sign-conversion")
set(COMPILE_FLAGS_MATH_GCC_CLANG "${COMPILE_FLAGS_MATH_GCC_CLANG} -Wno-sign-conversion")
set(COMPILE_FLAGS_MATH_GCC_CLANG "${COMPILE_FLAGS_MATH_GCC_CLANG} -Wno-sign-compare")
set(COMPILE_FLAGS_MATH_GCC_CLANG "${COMPILE_FLAGS_MATH_GCC_CLANG} -Wno-strict-aliasing")
# Include directories
set(INCLUDE_MATH "${CMAKE_CURRENT_SOURCE_DIR}/include")
@ -85,9 +85,10 @@ if(ENABLE_AMALGAM)
endif()
add_library(${JERRY_MATH_NAME} ${SOURCE_MATH})
set_property(TARGET ${JERRY_MATH_NAME}
PROPERTY COMPILE_FLAGS "${COMPILE_FLAGS_MATH}")
if(USING_GCC OR USING_CLANG)
set_property(TARGET ${JERRY_MATH_NAME}
PROPERTY COMPILE_FLAGS "${COMPILE_FLAGS_MATH_GCC_CLANG}")
endif()
target_include_directories(${JERRY_MATH_NAME} PUBLIC ${INCLUDE_MATH})
configure_file(libjerry-math.pc.in libjerry-math.pc @ONLY)

View File

@ -265,7 +265,12 @@ expm1 (double x)
y = one - (e - x);
if (k == 1024)
{
y = y * 2.0 * 0x1p1023;
const double twop1023 = ((double_accessor)
{
.as_int = { .hi = 0x7fe00000, .lo = 0 }
}
).dbl; /* 0x1p1023 */
y = y * 2.0 * twop1023;
}
else
{

View File

@ -22,9 +22,14 @@ extern "C"
#endif /* __cplusplus */
/* General Constants. */
#define INFINITY (1.0/0.0)
#define NAN (0.0/0.0)
#define HUGE_VAL INFINITY
#ifdef _MSC_VER
#define INFINITY ((float) (1e+300 * 1e+300)) /* 1e+300*1e+300 must overflow */
#define NAN ((float) (INFINITY * 0.0f))
#else /* !_MSC_VER */
#define INFINITY ((float) (1.0 / 0.0))
#define NAN ((float) (0.0 / 0.0))
#endif /* _MSC_VER */
#define HUGE_VAL ((double) INFINITY)
#define isnan(x) ((x) != (x))
#define isinf(x) ((x) == INFINITY ? 1 : (x) == -INFINITY ? -1 : 0)

View File

@ -38,8 +38,10 @@
#if (defined (i386) || defined (__i386) || defined (__i386__) || \
defined (i486) || defined (__i486) || defined (__i486__) || \
defined (intel) || defined (x86) || defined (i86pc) || \
defined (_M_IX86) || defined (_M_AMD64) || defined (_M_X64) || \
defined (__alpha) || defined (__osf__) || \
defined (__x86_64__) || defined (__arm__) || defined (__aarch64__) || \
defined (_M_ARM) || defined (_M_ARM64) || \
defined (__xtensa__) || defined (__MIPSEL)) || \
(defined (__BYTE_ORDER__) && (__BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__))
#define __LITTLE_ENDIAN
@ -74,8 +76,14 @@ typedef union
#endif /* __LITTLE_ENDIAN */
#ifndef NAN
#define NAN (0.0/0.0)
#endif
#ifdef _MSC_VER
#define INFINITY ((float) (1e+300 * 1e+300)) /* 1e+300*1e+300 must overflow */
#define NAN ((float) (INFINITY * 0.0f))
#else /* !_MSC_VER */
#define INFINITY ((float) (1.0 / 0.0))
#define NAN ((float) (0.0 / 0.0))
#endif /* _MSC_VER */
#endif /* !NAN */
/*
* ANSI/POSIX

View File

@ -105,11 +105,11 @@ log (double x)
{
if (((hx & 0x7fffffff) | lx) == 0) /* log(+-0) = -inf */
{
return -two54 / zero;
return -INFINITY;
}
if (hx < 0) /* log(-#) = NaN */
{
return (x - x) / zero;
return NAN;
}
k -= 54;
x *= two54; /* subnormal number, scale up x */

View File

@ -84,12 +84,12 @@ log10 (double x)
if (((hx & 0x7fffffff) | lx) == 0)
{
/* log(+-0)=-inf */
return -two54 / zero;
return -INFINITY;
}
if (hx < 0)
{
/* log(-#) = NaN */
return (x - x) / zero;
return NAN;
}
k -= 54;
x *= two54; /* subnormal number, scale up x */

View File

@ -122,7 +122,7 @@ log1p (double x)
if (x == -1.0)
{
/* log1p(-1) = -inf */
return -two54 / zero;
return -INFINITY;
}
else
{

View File

@ -65,11 +65,11 @@ log2 (double x)
{ /* x < 2**-1022 */
if (((hx & 0x7fffffff) | lx) == 0)
{
return -two54 / zero; /* log(+-0)=-inf */
return -INFINITY; /* log(+-0)=-inf */
}
if (hx < 0)
{
return (x - x) / zero; /* log(-#) = NaN */
return NAN; /* log(-#) = NaN */
}
k -= 54;
x *= two54; /* subnormal number, scale up x */