1 #pragma once 2 #include <sys/types.h> 3 4 #if defined(__cplusplus) 5 extern "C" { 6 #endif 7 8 // ===== 描述long double 的数据比特结构 9 #if __LDBL_MANT_DIG__ == 53 && __LDBL_MAX_EXP__ == 1024 10 #elif __LDBL_MANT_DIG__ == 64 && __LDBL_MAX_EXP__ == 16384 && __BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__ 11 union ldshape 12 { 13 long double f; 14 struct 15 { 16 uint64_t m; 17 uint16_t se; 18 } i; 19 }; 20 #elif __LDBL_MANT_DIG__ == 113 && __LDBL_MAX_EXP__ == 16384 && __BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__ 21 union ldshape 22 { 23 long double f; 24 struct 25 { 26 uint64_t lo; 27 uint32_t mid; 28 uint16_t top; 29 uint16_t se; 30 } i; 31 struct 32 { 33 uint64_t lo; 34 uint64_t hi; 35 } i2; 36 }; 37 #elif __LDBL_MANT_DIG__ == 113 && __LDBL_MAX_EXP__ == 16384 && __BYTE_ORDER__ == __BIG_ENDIAN 38 union ldshape 39 { 40 long double f; 41 struct 42 { 43 uint16_t se; 44 uint16_t top; 45 uint32_t mid; 46 uint64_t lo; 47 } i; 48 struct 49 { 50 uint64_t hi; 51 uint64_t lo; 52 } i2; 53 }; 54 #else 55 #error Unsupported long double representation 56 #endif 57 58 #define FORCE_EVAL(x) \ 59 do \ 60 { \ 61 if (sizeof(x) == sizeof(float)) \ 62 { \ 63 volatile float __x; \ 64 __x = (x); \ 65 (void)__x; \ 66 } \ 67 else if (sizeof(x) == sizeof(double)) \ 68 { \ 69 volatile double __x; \ 70 __x = (x); \ 71 (void)__x; \ 72 } \ 73 else \ 74 { \ 75 volatile long double __x; \ 76 __x = (x); \ 77 (void)__x; \ 78 } \ 79 } while (0) 80 81 #if defined(__cplusplus) 82 } /* extern "C" */ 83 #endif