libm.h 2.0 KB

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