diff --git a/jerry-math/CMakeLists.txt b/jerry-math/CMakeLists.txt index 0a1b4748a..5e6b8a5f0 100644 --- a/jerry-math/CMakeLists.txt +++ b/jerry-math/CMakeLists.txt @@ -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) diff --git a/jerry-math/expm1.c b/jerry-math/expm1.c index f82841550..127817c0c 100644 --- a/jerry-math/expm1.c +++ b/jerry-math/expm1.c @@ -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 { diff --git a/jerry-math/include/math.h b/jerry-math/include/math.h index f3c23a882..f639734bf 100644 --- a/jerry-math/include/math.h +++ b/jerry-math/include/math.h @@ -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) diff --git a/jerry-math/jerry-math-internal.h b/jerry-math/jerry-math-internal.h index 9ced0a881..767c490f3 100644 --- a/jerry-math/jerry-math-internal.h +++ b/jerry-math/jerry-math-internal.h @@ -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 diff --git a/jerry-math/log.c b/jerry-math/log.c index fb2053f6d..2e7fa4cd8 100644 --- a/jerry-math/log.c +++ b/jerry-math/log.c @@ -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 */ diff --git a/jerry-math/log10.c b/jerry-math/log10.c index 435c00cc9..1ea2a54bf 100644 --- a/jerry-math/log10.c +++ b/jerry-math/log10.c @@ -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 */ diff --git a/jerry-math/log1p.c b/jerry-math/log1p.c index 6d723b224..cd3da6212 100644 --- a/jerry-math/log1p.c +++ b/jerry-math/log1p.c @@ -122,7 +122,7 @@ log1p (double x) if (x == -1.0) { /* log1p(-1) = -inf */ - return -two54 / zero; + return -INFINITY; } else { diff --git a/jerry-math/log2.c b/jerry-math/log2.c index 19860fa29..0db7d1dff 100644 --- a/jerry-math/log2.c +++ b/jerry-math/log2.c @@ -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 */