Skip to content

Commit 814fafb

Browse files
committed
fixing endianes detection
1 parent 68793e6 commit 814fafb

File tree

1 file changed

+17
-13
lines changed

1 file changed

+17
-13
lines changed

quaddtype/numpy_quaddtype/src/quaddtype_main.c

Lines changed: 17 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
#include "numpy/arrayobject.h"
1212
#include "numpy/dtype_api.h"
1313
#include "numpy/ufuncobject.h"
14+
#include "numpy/npy_endian.h"
1415

1516
#include "scalar.h"
1617
#include "dtype.h"
@@ -33,23 +34,26 @@ py_is_longdouble_128(PyObject *self, PyObject *args)
3334
#ifdef SLEEF_QUAD_C
3435
static const Sleef_quad SMALLEST_SUBNORMAL_VALUE = SLEEF_QUAD_DENORM_MIN;
3536
#else
36-
// Use the exact same struct layout as the original buggy code
3737
static const union {
3838
struct {
39-
#if defined(__BYTE_ORDER__) && (__BYTE_ORDER__ == __ORDER_BIG_ENDIAN__)
40-
uint64_t h, l;
41-
#else
42-
uint64_t l, h;
43-
#endif
39+
#if NPY_BYTE_ORDER == NPY_BIG_ENDIAN
40+
uint64_t high;
41+
uint64_t low;
42+
#elif NPY_BYTE_ORDER == NPY_LITTLE_ENDIAN
43+
uint64_t low;
44+
uint64_t high;
45+
#else
46+
#error "Unknown endianness - NPY_BYTE_ORDER not properly defined"
47+
#endif
4448
} parts;
4549
Sleef_quad value;
46-
} smallest_subnormal_const = {.parts = {
47-
#if defined(__BYTE_ORDER__) && (__BYTE_ORDER__ == __ORDER_BIG_ENDIAN__)
48-
.h = 0x0000000000000000ULL, .l = 0x0000000000000001ULL
49-
#else
50-
.l = 0x0000000000000001ULL, .h = 0x0000000000000000ULL
51-
#endif
52-
}};
50+
} smallest_subnormal_const = {
51+
.parts = {
52+
.low = 0x0000000000000001ULL,
53+
.high = 0x0000000000000000ULL
54+
}
55+
};
56+
5357
#define SMALLEST_SUBNORMAL_VALUE (smallest_subnormal_const.value)
5458
#endif
5559

0 commit comments

Comments
 (0)