libm.h 6.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181
  1. /* origin: FreeBSD /usr/src/lib/msun/src/math_private.h */
  2. /*
  3. * ====================================================
  4. * Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved.
  5. *
  6. * Developed at SunPro, a Sun Microsystems, Inc. business.
  7. * Permission to use, copy, modify, and distribute this
  8. * software is freely granted, provided that this notice
  9. * is preserved.
  10. * ====================================================
  11. */
  12. #ifndef _LIBM_H
  13. #define _LIBM_H
  14. #include <stdint.h>
  15. #include <float.h>
  16. #include <math.h>
  17. #include <complex.h>
  18. #include "longdbl.h"
  19. #include "libc.h"
  20. union fshape {
  21. float value;
  22. uint32_t bits;
  23. };
  24. union dshape {
  25. double value;
  26. uint64_t bits;
  27. };
  28. #define FORCE_EVAL(x) do { \
  29. if (sizeof(x) == sizeof(float)) { \
  30. volatile float __x; \
  31. __x = (x); \
  32. } else if (sizeof(x) == sizeof(double)) { \
  33. volatile double __x; \
  34. __x = (x); \
  35. } else { \
  36. volatile long double __x; \
  37. __x = (x); \
  38. } \
  39. } while(0)
  40. /* Get two 32 bit ints from a double. */
  41. #define EXTRACT_WORDS(hi,lo,d) \
  42. do { \
  43. union dshape __u; \
  44. __u.value = (d); \
  45. (hi) = __u.bits >> 32; \
  46. (lo) = (uint32_t)__u.bits; \
  47. } while (0)
  48. /* Get a 64 bit int from a double. */
  49. #define EXTRACT_WORD64(i,d) \
  50. do { \
  51. union dshape __u; \
  52. __u.value = (d); \
  53. (i) = __u.bits; \
  54. } while (0)
  55. /* Get the more significant 32 bit int from a double. */
  56. #define GET_HIGH_WORD(i,d) \
  57. do { \
  58. union dshape __u; \
  59. __u.value = (d); \
  60. (i) = __u.bits >> 32; \
  61. } while (0)
  62. /* Get the less significant 32 bit int from a double. */
  63. #define GET_LOW_WORD(i,d) \
  64. do { \
  65. union dshape __u; \
  66. __u.value = (d); \
  67. (i) = (uint32_t)__u.bits; \
  68. } while (0)
  69. /* Set a double from two 32 bit ints. */
  70. #define INSERT_WORDS(d,hi,lo) \
  71. do { \
  72. union dshape __u; \
  73. __u.bits = ((uint64_t)(hi) << 32) | (uint32_t)(lo); \
  74. (d) = __u.value; \
  75. } while (0)
  76. /* Set a double from a 64 bit int. */
  77. #define INSERT_WORD64(d,i) \
  78. do { \
  79. union dshape __u; \
  80. __u.bits = (i); \
  81. (d) = __u.value; \
  82. } while (0)
  83. /* Set the more significant 32 bits of a double from an int. */
  84. #define SET_HIGH_WORD(d,hi) \
  85. do { \
  86. union dshape __u; \
  87. __u.value = (d); \
  88. __u.bits &= 0xffffffff; \
  89. __u.bits |= (uint64_t)(hi) << 32; \
  90. (d) = __u.value; \
  91. } while (0)
  92. /* Set the less significant 32 bits of a double from an int. */
  93. #define SET_LOW_WORD(d,lo) \
  94. do { \
  95. union dshape __u; \
  96. __u.value = (d); \
  97. __u.bits &= 0xffffffff00000000ull; \
  98. __u.bits |= (uint32_t)(lo); \
  99. (d) = __u.value; \
  100. } while (0)
  101. /* Get a 32 bit int from a float. */
  102. #define GET_FLOAT_WORD(i,d) \
  103. do { \
  104. union fshape __u; \
  105. __u.value = (d); \
  106. (i) = __u.bits; \
  107. } while (0)
  108. /* Set a float from a 32 bit int. */
  109. #define SET_FLOAT_WORD(d,i) \
  110. do { \
  111. union fshape __u; \
  112. __u.bits = (i); \
  113. (d) = __u.value; \
  114. } while (0)
  115. /* fdlibm kernel functions */
  116. int __rem_pio2_large(double*,double*,int,int,int);
  117. int __rem_pio2(double,double*);
  118. double __sin(double,double,int);
  119. double __cos(double,double);
  120. double __tan(double,double,int);
  121. double __expo2(double);
  122. double complex __ldexp_cexp(double complex,int);
  123. int __rem_pio2f(float,double*);
  124. float __sindf(double);
  125. float __cosdf(double);
  126. float __tandf(double,int);
  127. float __expo2f(float);
  128. float complex __ldexp_cexpf(float complex,int);
  129. int __rem_pio2l(long double, long double *);
  130. long double __sinl(long double, long double, int);
  131. long double __cosl(long double, long double);
  132. long double __tanl(long double, long double, int);
  133. /* polynomial evaluation */
  134. long double __polevll(long double, const long double *, int);
  135. long double __p1evll(long double, const long double *, int);
  136. // FIXME: not needed when -fexcess-precision=standard is supported (>=gcc4.5)
  137. /*
  138. * Attempt to get strict C99 semantics for assignment with non-C99 compilers.
  139. */
  140. #if 1
  141. #define STRICT_ASSIGN(type, lval, rval) do { \
  142. volatile type __v = (rval); \
  143. (lval) = __v; \
  144. } while (0)
  145. #else
  146. #define STRICT_ASSIGN(type, lval, rval) ((lval) = (type)(rval))
  147. #endif
  148. /* complex */
  149. #ifndef CMPLX
  150. #define CMPLX(x, y) __CMPLX(x, y, double)
  151. #define CMPLXF(x, y) __CMPLX(x, y, float)
  152. #define CMPLXL(x, y) __CMPLX(x, y, long double)
  153. #endif
  154. #endif