mingw-w64/mingw-w64-crt/math/signbitl.c
Martin Storsjö e33afcd864 math: Don't do pointer type punning via a union
Don't converting from one pointer type to another via a union;
that is still a strict aliasing violation as far as I know.

Use unions for actually reinterpreting the values instead, which
is not an aliasing violation, and is defined according to the C99
standard (which also was relied on before).

Signed-off-by: Martin Storsjö <martin@martin.st>
2019-04-24 11:05:44 +03:00

28 lines
720 B
C

/**
* This file is part of the mingw-w64 runtime package.
* No warranty is given; refer to the file DISCLAIMER within this package.
*/
#include <math.h>
#define __FP_SIGNBIT 0x0200
int __signbitl (long double x) {
#if defined(__x86_64__) || defined(_AMD64_)
__mingw_ldbl_type_t ld;
ld.x = x;
return ((ld.lh.sign_exponent & 0x8000) != 0);
#elif defined(__arm__) || defined(_ARM_) || defined(__aarch64__) || defined(_ARM64_)
return __signbit(x);
#elif defined(__i386__) || defined(_X86_)
unsigned short sw;
__asm__ __volatile__ ("fxam; fstsw %%ax;"
: "=a" (sw)
: "t" (x) );
return (sw & __FP_SIGNBIT) != 0;
#endif
}
int __attribute__ ((alias ("__signbitl"))) signbitl (long double);