math_private.h 6.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232
  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) || defined(__arm__) && !defined(__VFP_FP__)
  37. typedef union
  38. {
  39. double value;
  40. struct
  41. {
  42. u_int32_t msw;
  43. u_int32_t lsw;
  44. } parts;
  45. } ieee_double_shape_type;
  46. #endif
  47. #if (__BYTE_ORDER == __LITTLE_ENDIAN) && (!defined(__arm__) || defined(__VFP_FP__))
  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 __P((double));
  127. extern double __ieee754_acos __P((double));
  128. extern double __ieee754_acosh __P((double));
  129. extern double __ieee754_log __P((double));
  130. extern double __ieee754_atanh __P((double));
  131. extern double __ieee754_asin __P((double));
  132. extern double __ieee754_atan2 __P((double,double));
  133. extern double __ieee754_exp __P((double));
  134. extern double __ieee754_cosh __P((double));
  135. extern double __ieee754_fmod __P((double,double));
  136. extern double __ieee754_pow __P((double,double));
  137. extern double __ieee754_lgamma_r __P((double,int *));
  138. extern double __ieee754_gamma_r __P((double,int *));
  139. extern double __ieee754_lgamma __P((double));
  140. extern double __ieee754_gamma __P((double));
  141. extern double __ieee754_log10 __P((double));
  142. extern double __ieee754_sinh __P((double));
  143. extern double __ieee754_hypot __P((double,double));
  144. extern double __ieee754_j0 __P((double));
  145. extern double __ieee754_j1 __P((double));
  146. extern double __ieee754_y0 __P((double));
  147. extern double __ieee754_y1 __P((double));
  148. extern double __ieee754_jn __P((int,double));
  149. extern double __ieee754_yn __P((int,double));
  150. extern double __ieee754_remainder __P((double,double));
  151. extern int __ieee754_rem_pio2 __P((double,double*));
  152. #if defined(_SCALB_INT)
  153. extern double __ieee754_scalb __P((double,int));
  154. #else
  155. extern double __ieee754_scalb __P((double,double));
  156. #endif
  157. /* fdlibm kernel function */
  158. extern double __kernel_standard __P((double,double,int));
  159. extern double __kernel_sin __P((double,double,int));
  160. extern double __kernel_cos __P((double,double));
  161. extern double __kernel_tan __P((double,double,int));
  162. extern int __kernel_rem_pio2 __P((double*,double*,int,int,int,const int*));
  163. /* ieee style elementary float functions */
  164. extern float __ieee754_sqrtf __P((float));
  165. extern float __ieee754_acosf __P((float));
  166. extern float __ieee754_acoshf __P((float));
  167. extern float __ieee754_logf __P((float));
  168. extern float __ieee754_atanhf __P((float));
  169. extern float __ieee754_asinf __P((float));
  170. extern float __ieee754_atan2f __P((float,float));
  171. extern float __ieee754_expf __P((float));
  172. extern float __ieee754_coshf __P((float));
  173. extern float __ieee754_fmodf __P((float,float));
  174. extern float __ieee754_powf __P((float,float));
  175. extern float __ieee754_lgammaf_r __P((float,int *));
  176. extern float __ieee754_gammaf_r __P((float,int *));
  177. extern float __ieee754_lgammaf __P((float));
  178. extern float __ieee754_gammaf __P((float));
  179. extern float __ieee754_log10f __P((float));
  180. extern float __ieee754_sinhf __P((float));
  181. extern float __ieee754_hypotf __P((float,float));
  182. extern float __ieee754_j0f __P((float));
  183. extern float __ieee754_j1f __P((float));
  184. extern float __ieee754_y0f __P((float));
  185. extern float __ieee754_y1f __P((float));
  186. extern float __ieee754_jnf __P((int,float));
  187. extern float __ieee754_ynf __P((int,float));
  188. extern float __ieee754_remainderf __P((float,float));
  189. extern int __ieee754_rem_pio2f __P((float,float*));
  190. extern float __ieee754_scalbf __P((float,float));
  191. /* float versions of fdlibm kernel functions */
  192. extern float __kernel_sinf __P((float,float,int));
  193. extern float __kernel_cosf __P((float,float));
  194. extern float __kernel_tanf __P((float,float,int));
  195. extern int __kernel_rem_pio2f __P((float*,float*,int,int,int,const int*));
  196. #endif /* _MATH_PRIVATE_H_ */