math_private.h 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197
  1. /*
  2. * ====================================================
  3. * Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved.
  4. *
  5. * Developed at SunPro, a Sun Microsystems, Inc. business.
  6. * Permission to use, copy, modify, and distribute this
  7. * software is freely granted, provided that this notice
  8. * is preserved.
  9. * ====================================================
  10. */
  11. /*
  12. * from: @(#)fdlibm.h 5.1 93/09/24
  13. * $Id: math_private.h,v 1.3 2004/02/09 07:10:38 andersen Exp $
  14. */
  15. #ifndef _MATH_PRIVATE_H_
  16. #define _MATH_PRIVATE_H_
  17. #include <endian.h>
  18. #include <sys/types.h>
  19. /* The original fdlibm code used statements like:
  20. n0 = ((*(int*)&one)>>29)^1; * index of high word *
  21. ix0 = *(n0+(int*)&x); * high word of x *
  22. ix1 = *((1-n0)+(int*)&x); * low word of x *
  23. to dig two 32 bit words out of the 64 bit IEEE floating point
  24. value. That is non-ANSI, and, moreover, the gcc instruction
  25. scheduler gets it wrong. We instead use the following macros.
  26. Unlike the original code, we determine the endianness at compile
  27. time, not at run time; I don't see much benefit to selecting
  28. endianness at run time. */
  29. /* A union which permits us to convert between a double and two 32 bit
  30. ints. */
  31. /*
  32. * Math on arm is special:
  33. * For FPA, float words are always big-endian.
  34. * For VFP, floats words follow the memory system mode.
  35. */
  36. #if (__BYTE_ORDER == __BIG_ENDIAN) || \
  37. (!defined(__VFP_FP__) && (defined(__arm__) || defined(__thumb__)))
  38. typedef union
  39. {
  40. double value;
  41. struct
  42. {
  43. u_int32_t msw;
  44. u_int32_t lsw;
  45. } parts;
  46. } ieee_double_shape_type;
  47. #else
  48. typedef union
  49. {
  50. double value;
  51. struct
  52. {
  53. u_int32_t lsw;
  54. u_int32_t msw;
  55. } parts;
  56. } ieee_double_shape_type;
  57. #endif
  58. /* Get two 32 bit ints from a double. */
  59. #define EXTRACT_WORDS(ix0,ix1,d) \
  60. do { \
  61. ieee_double_shape_type ew_u; \
  62. ew_u.value = (d); \
  63. (ix0) = ew_u.parts.msw; \
  64. (ix1) = ew_u.parts.lsw; \
  65. } while (0)
  66. /* Get the more significant 32 bit int from a double. */
  67. #define GET_HIGH_WORD(i,d) \
  68. do { \
  69. ieee_double_shape_type gh_u; \
  70. gh_u.value = (d); \
  71. (i) = gh_u.parts.msw; \
  72. } while (0)
  73. /* Get the less significant 32 bit int from a double. */
  74. #define GET_LOW_WORD(i,d) \
  75. do { \
  76. ieee_double_shape_type gl_u; \
  77. gl_u.value = (d); \
  78. (i) = gl_u.parts.lsw; \
  79. } while (0)
  80. /* Set a double from two 32 bit ints. */
  81. #define INSERT_WORDS(d,ix0,ix1) \
  82. do { \
  83. ieee_double_shape_type iw_u; \
  84. iw_u.parts.msw = (ix0); \
  85. iw_u.parts.lsw = (ix1); \
  86. (d) = iw_u.value; \
  87. } while (0)
  88. /* Set the more significant 32 bits of a double from an int. */
  89. #define SET_HIGH_WORD(d,v) \
  90. do { \
  91. ieee_double_shape_type sh_u; \
  92. sh_u.value = (d); \
  93. sh_u.parts.msw = (v); \
  94. (d) = sh_u.value; \
  95. } while (0)
  96. /* Set the less significant 32 bits of a double from an int. */
  97. #define SET_LOW_WORD(d,v) \
  98. do { \
  99. ieee_double_shape_type sl_u; \
  100. sl_u.value = (d); \
  101. sl_u.parts.lsw = (v); \
  102. (d) = sl_u.value; \
  103. } while (0)
  104. /* A union which permits us to convert between a float and a 32 bit
  105. int. */
  106. typedef union
  107. {
  108. float value;
  109. u_int32_t word;
  110. } ieee_float_shape_type;
  111. /* Get a 32 bit int from a float. */
  112. #define GET_FLOAT_WORD(i,d) \
  113. do { \
  114. ieee_float_shape_type gf_u; \
  115. gf_u.value = (d); \
  116. (i) = gf_u.word; \
  117. } while (0)
  118. /* Set a float from a 32 bit int. */
  119. #define SET_FLOAT_WORD(d,i) \
  120. do { \
  121. ieee_float_shape_type sf_u; \
  122. sf_u.word = (i); \
  123. (d) = sf_u.value; \
  124. } while (0)
  125. /* ieee style elementary functions */
  126. extern double __ieee754_sqrt (double) attribute_hidden;
  127. extern double __ieee754_acos (double) attribute_hidden;
  128. extern double __ieee754_acosh (double) attribute_hidden;
  129. extern double __ieee754_log (double) attribute_hidden;
  130. extern double __ieee754_atanh (double) attribute_hidden;
  131. extern double __ieee754_asin (double) attribute_hidden;
  132. extern double __ieee754_atan2 (double,double) attribute_hidden;
  133. extern double __ieee754_exp (double) attribute_hidden;
  134. extern double __ieee754_cosh (double) attribute_hidden;
  135. extern double __ieee754_fmod (double,double) attribute_hidden;
  136. extern double __ieee754_pow (double,double) attribute_hidden;
  137. extern double __ieee754_lgamma_r (double,int *) attribute_hidden;
  138. extern double __ieee754_gamma_r (double,int *) attribute_hidden;
  139. extern double __ieee754_lgamma (double) attribute_hidden;
  140. extern double __ieee754_gamma (double) attribute_hidden;
  141. extern double __ieee754_log10 (double) attribute_hidden;
  142. extern double __ieee754_sinh (double) attribute_hidden;
  143. extern double __ieee754_hypot (double,double) attribute_hidden;
  144. extern double __ieee754_j0 (double) attribute_hidden;
  145. extern double __ieee754_j1 (double) attribute_hidden;
  146. extern double __ieee754_y0 (double) attribute_hidden;
  147. extern double __ieee754_y1 (double) attribute_hidden;
  148. extern double __ieee754_jn (int,double) attribute_hidden;
  149. extern double __ieee754_yn (int,double) attribute_hidden;
  150. extern double __ieee754_remainder (double,double) attribute_hidden;
  151. extern int __ieee754_rem_pio2 (double,double*) attribute_hidden;
  152. #if defined(_SCALB_INT)
  153. extern double __ieee754_scalb (double,int) attribute_hidden;
  154. #else
  155. extern double __ieee754_scalb (double,double) attribute_hidden;
  156. #endif
  157. /* fdlibm kernel function */
  158. #ifndef _IEEE_LIBM
  159. extern double __kernel_standard (double,double,int) attribute_hidden;
  160. #endif
  161. extern double __kernel_sin (double,double,int) attribute_hidden;
  162. extern double __kernel_cos (double,double) attribute_hidden;
  163. extern double __kernel_tan (double,double,int) attribute_hidden;
  164. extern int __kernel_rem_pio2 (double*,double*,int,int,int,const int*) attribute_hidden;
  165. #endif /* _MATH_PRIVATE_H_ */