Skip to content

Commit 1ff0191

Browse files
committed
static union
1 parent 1addb52 commit 1ff0191

File tree

1 file changed

+9
-13
lines changed

1 file changed

+9
-13
lines changed

quaddtype/numpy_quaddtype/src/quaddtype_main.c

Lines changed: 9 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -30,22 +30,18 @@ py_is_longdouble_128(PyObject *self, PyObject *args)
3030
}
3131
}
3232

33-
#ifndef SLEEF_QUAD_C
33+
#ifdef SLEEF_QUAD_C
34+
// Native __float128 support
35+
static const Sleef_quad SMALLEST_SUBNORMAL_VALUE = SLEEF_QUAD_DENORM_MIN;
36+
#else
37+
// Use static union for thread-safe initialization
3438
static const union {
3539
struct {
36-
#if defined(__BYTE_ORDER__) && (__BYTE_ORDER__ == __ORDER_BIG_ENDIAN__)
37-
uint64_t h, l;
38-
#else
3940
uint64_t l, h;
40-
#endif
4141
} parts;
42-
Sleef_quad quad_value;
43-
long double alignment_dummy __attribute__((aligned(16)));
44-
} SMALLEST_SUBNORMAL_CONST = {
45-
.parts = {
46-
.h = 0x0000000000000000ULL, // exponent = 0 (subnormal), mantissa high = 0
47-
.l = 0x0000000000000001ULL // mantissa low = 1 (smallest possible)
48-
}};
42+
Sleef_quad value;
43+
} smallest_subnormal_const = {.parts = {.l = 0x0000000000000001ULL, .h = 0x0000000000000000ULL}};
44+
#define SMALLEST_SUBNORMAL_VALUE (smallest_subnormal_const.value)
4945
#endif
5046

5147
static PyObject *
@@ -93,7 +89,7 @@ get_sleef_constant(PyObject *self, PyObject *args)
9389
// On platforms with native __float128 support, use the correct literal
9490
result->value.sleef_value = SLEEF_QUAD_DENORM_MIN;
9591
#else
96-
result->value.sleef_value = SMALLEST_SUBNORMAL_CONST.quad_value;
92+
result->value.sleef_value = SMALLEST_SUBNORMAL_VALUE;
9793
#endif
9894
}
9995
else if (strcmp(constant_name, "bits") == 0) {

0 commit comments

Comments
 (0)