libm.h 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  1. // Portions of this file are extracted from musl-1.1.16 src/internal/libm.h
  2. /* origin: FreeBSD /usr/src/lib/msun/src/math_private.h */
  3. /*
  4. * ====================================================
  5. * Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved.
  6. *
  7. * Developed at SunPro, a Sun Microsystems, Inc. business.
  8. * Permission to use, copy, modify, and distribute this
  9. * software is freely granted, provided that this notice
  10. * is preserved.
  11. * ====================================================
  12. */
  13. #include <stdint.h>
  14. #include <math.h>
  15. #define FLT_EVAL_METHOD 0
  16. #define FORCE_EVAL(x) do { \
  17. if (sizeof(x) == sizeof(float)) { \
  18. volatile float __x; \
  19. __x = (x); \
  20. (void)__x; \
  21. } else if (sizeof(x) == sizeof(double)) { \
  22. volatile double __x; \
  23. __x = (x); \
  24. (void)__x; \
  25. } else { \
  26. volatile long double __x; \
  27. __x = (x); \
  28. (void)__x; \
  29. } \
  30. } while(0)
  31. /* Get two 32 bit ints from a double. */
  32. #define EXTRACT_WORDS(hi,lo,d) \
  33. do { \
  34. union {double f; uint64_t i;} __u; \
  35. __u.f = (d); \
  36. (hi) = __u.i >> 32; \
  37. (lo) = (uint32_t)__u.i; \
  38. } while (0)
  39. /* Get the more significant 32 bit int from a double. */
  40. #define GET_HIGH_WORD(hi,d) \
  41. do { \
  42. union {double f; uint64_t i;} __u; \
  43. __u.f = (d); \
  44. (hi) = __u.i >> 32; \
  45. } while (0)
  46. /* Get the less significant 32 bit int from a double. */
  47. #define GET_LOW_WORD(lo,d) \
  48. do { \
  49. union {double f; uint64_t i;} __u; \
  50. __u.f = (d); \
  51. (lo) = (uint32_t)__u.i; \
  52. } while (0)
  53. /* Set a double from two 32 bit ints. */
  54. #define INSERT_WORDS(d,hi,lo) \
  55. do { \
  56. union {double f; uint64_t i;} __u; \
  57. __u.i = ((uint64_t)(hi)<<32) | (uint32_t)(lo); \
  58. (d) = __u.f; \
  59. } while (0)
  60. /* Set the more significant 32 bits of a double from an int. */
  61. #define SET_HIGH_WORD(d,hi) \
  62. do { \
  63. union {double f; uint64_t i;} __u; \
  64. __u.f = (d); \
  65. __u.i &= 0xffffffff; \
  66. __u.i |= (uint64_t)(hi) << 32; \
  67. (d) = __u.f; \
  68. } while (0)
  69. /* Set the less significant 32 bits of a double from an int. */
  70. #define SET_LOW_WORD(d,lo) \
  71. do { \
  72. union {double f; uint64_t i;} __u; \
  73. __u.f = (d); \
  74. __u.i &= 0xffffffff00000000ull; \
  75. __u.i |= (uint32_t)(lo); \
  76. (d) = __u.f; \
  77. } while (0)
  78. #define DBL_EPSILON 2.22044604925031308085e-16
  79. int __rem_pio2(double, double*);
  80. int __rem_pio2_large(double*, double*, int, int, int);
  81. double __sin(double, double, int);
  82. double __cos(double, double);
  83. double __tan(double, double, int);
  84. double __expo2(double);