Repository: jerryscript-project/jerryscript
File: jerry-math/jerry-math-internal.h (C/C++)

Code before:
 * limitations under the License.
 *
 * This file is based on work under the following copyright and permission
 * notice:
 *
 *     Copyright (C) 2004 by Sun Microsystems, Inc. All rights reserved.
 *
 *     Permission to use, copy, modify, and distribute this
 *     software is freely granted, provided that this notice
 *     is preserved.
 *
 *     @(#)fdlibm.h 1.5 04/04/22
 */

#ifndef JERRY_MATH_INTERNAL_H
#define JERRY_MATH_INTERNAL_H

/* Sometimes it's necessary to define __LITTLE_ENDIAN explicitly
   but these catch some common cases. */

#ifndef __LITTLE_ENDIAN
/* Check if compiler has byte order macro. Some older versions do not.
 * If byte order is supported and set to little or target is among common
 * cases checked define __LITTLE_ENDIAN.
 */
#if (defined (_MSC_VER) || defined (i386) || defined (__i386) || defined (__i386__) || \
     defined (i486) || defined (__i486) || defined (__i486__) || \
     defined (intel) || defined (x86) || defined (i86pc) || \
     defined (__alpha) || defined (__osf__) || \
     defined (__x86_64__) || defined (__arm__) || defined (__aarch64__) || \
     defined (__xtensa__) || defined (__MIPSEL)) || \
(defined (__BYTE_ORDER__) && (__BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__))
#define __LITTLE_ENDIAN
#endif
#endif /* !__LITTLE_ENDIAN */

#ifdef __LITTLE_ENDIAN
#define __HI(x) *(1 + (const int *) &x)
#define __LO(x) *(const int *) &x
typedef union
{
  double dbl;
  struct
  {
    int lo;
    int hi;
  } as_int;
} double_accessor;
#else /* !__LITTLE_ENDIAN */
#define __HI(x) *(const int *) &x
#define __LO(x) *(1 + (const int *) &x)

Review comment (suggestion):
This is not correct. MSVC can compile for multiple architectures, e.g., for ARM (both 32 and 64 bit). The macros to be tested for are `_M_IX86` and `_M_X64` (see: https://docs.microsoft.com/en-us/cpp/preprocessor/predefined-macros?view=msvc-160 )

Moreover, add these tests on a new line after `defined (i86pc)`.

Code after:
 * limitations under the License.
 *
 * This file is based on work under the following copyright and permission
 * notice:
 *
 *     Copyright (C) 2004 by Sun Microsystems, Inc. All rights reserved.
 *
 *     Permission to use, copy, modify, and distribute this
 *     software is freely granted, provided that this notice
 *     is preserved.
 *
 *     @(#)fdlibm.h 1.5 04/04/22
 */

#ifndef JERRY_MATH_INTERNAL_H
#define JERRY_MATH_INTERNAL_H

/* Sometimes it's necessary to define __LITTLE_ENDIAN explicitly
   but these catch some common cases. */

#ifndef __LITTLE_ENDIAN
/* Check if compiler has byte order macro. Some older versions do not.
 * If byte order is supported and set to little or target is among common
 * cases checked define __LITTLE_ENDIAN.
 */
#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
#endif
#endif /* !__LITTLE_ENDIAN */

#ifdef __LITTLE_ENDIAN
#define __HI(x) *(1 + (const int *) &x)
#define __LO(x) *(const int *) &x
typedef union
{
  double dbl;
  struct
  {
    int lo;
    int hi;
  } as_int;
} double_accessor;
#else /* !__LITTLE_ENDIAN */