math_private.h 6.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228
  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. #define _IEEE_LIBM
  20. #define attribute_hidden
  21. #define libm_hidden_proto(x)
  22. #define libm_hidden_def(x)
  23. #define strong_alias(x, y)
  24. #if !defined(__HAIKU__) && !defined(__PSP__) && !defined(__3DS__) && !defined(__PS2__) /* already defined in a system header. */
  25. typedef unsigned int u_int32_t;
  26. #endif
  27. #define atan SDL_uclibc_atan
  28. #define __ieee754_atan2 SDL_uclibc_atan2
  29. #define copysign SDL_uclibc_copysign
  30. #define cos SDL_uclibc_cos
  31. #define __ieee754_exp SDL_uclibc_exp
  32. #define fabs SDL_uclibc_fabs
  33. #define floor SDL_uclibc_floor
  34. #define __ieee754_fmod SDL_uclibc_fmod
  35. #define __ieee754_log SDL_uclibc_log
  36. #define __ieee754_log10 SDL_uclibc_log10
  37. #define modf SDL_uclibc_modf
  38. #define __ieee754_pow SDL_uclibc_pow
  39. #define scalbln SDL_uclibc_scalbln
  40. #define scalbn SDL_uclibc_scalbn
  41. #define sin SDL_uclibc_sin
  42. #define __ieee754_sqrt SDL_uclibc_sqrt
  43. #define tan SDL_uclibc_tan
  44. /* The original fdlibm code used statements like:
  45. n0 = ((*(int*)&one)>>29)^1; * index of high word *
  46. ix0 = *(n0+(int*)&x); * high word of x *
  47. ix1 = *((1-n0)+(int*)&x); * low word of x *
  48. to dig two 32 bit words out of the 64 bit IEEE floating point
  49. value. That is non-ANSI, and, moreover, the gcc instruction
  50. scheduler gets it wrong. We instead use the following macros.
  51. Unlike the original code, we determine the endianness at compile
  52. time, not at run time; I don't see much benefit to selecting
  53. endianness at run time. */
  54. /* A union which permits us to convert between a double and two 32 bit
  55. ints. */
  56. /*
  57. * Math on arm is special:
  58. * For FPA, float words are always big-endian.
  59. * For VFP, floats words follow the memory system mode.
  60. * For Maverick, float words are always little-endian.
  61. */
  62. #if (SDL_FLOATWORDORDER == SDL_BIG_ENDIAN)
  63. typedef union
  64. {
  65. double value;
  66. struct
  67. {
  68. u_int32_t msw;
  69. u_int32_t lsw;
  70. } parts;
  71. } ieee_double_shape_type;
  72. #else
  73. typedef union
  74. {
  75. double value;
  76. struct
  77. {
  78. u_int32_t lsw;
  79. u_int32_t msw;
  80. } parts;
  81. } ieee_double_shape_type;
  82. #endif
  83. /* Get two 32 bit ints from a double. */
  84. #define EXTRACT_WORDS(ix0,ix1,d) \
  85. do { \
  86. ieee_double_shape_type ew_u; \
  87. ew_u.value = (d); \
  88. (ix0) = ew_u.parts.msw; \
  89. (ix1) = ew_u.parts.lsw; \
  90. } while (0)
  91. /* Get the more significant 32 bit int from a double. */
  92. #define GET_HIGH_WORD(i,d) \
  93. do { \
  94. ieee_double_shape_type gh_u; \
  95. gh_u.value = (d); \
  96. (i) = gh_u.parts.msw; \
  97. } while (0)
  98. /* Get the less significant 32 bit int from a double. */
  99. #define GET_LOW_WORD(i,d) \
  100. do { \
  101. ieee_double_shape_type gl_u; \
  102. gl_u.value = (d); \
  103. (i) = gl_u.parts.lsw; \
  104. } while (0)
  105. /* Set a double from two 32 bit ints. */
  106. #define INSERT_WORDS(d,ix0,ix1) \
  107. do { \
  108. ieee_double_shape_type iw_u; \
  109. iw_u.parts.msw = (ix0); \
  110. iw_u.parts.lsw = (ix1); \
  111. (d) = iw_u.value; \
  112. } while (0)
  113. /* Set the more significant 32 bits of a double from an int. */
  114. #define SET_HIGH_WORD(d,v) \
  115. do { \
  116. ieee_double_shape_type sh_u; \
  117. sh_u.value = (d); \
  118. sh_u.parts.msw = (v); \
  119. (d) = sh_u.value; \
  120. } while (0)
  121. /* Set the less significant 32 bits of a double from an int. */
  122. #define SET_LOW_WORD(d,v) \
  123. do { \
  124. ieee_double_shape_type sl_u; \
  125. sl_u.value = (d); \
  126. sl_u.parts.lsw = (v); \
  127. (d) = sl_u.value; \
  128. } while (0)
  129. /* A union which permits us to convert between a float and a 32 bit
  130. int. */
  131. typedef union
  132. {
  133. float value;
  134. u_int32_t word;
  135. } ieee_float_shape_type;
  136. /* Get a 32 bit int from a float. */
  137. #define GET_FLOAT_WORD(i,d) \
  138. do { \
  139. ieee_float_shape_type gf_u; \
  140. gf_u.value = (d); \
  141. (i) = gf_u.word; \
  142. } while (0)
  143. /* Set a float from a 32 bit int. */
  144. #define SET_FLOAT_WORD(d,i) \
  145. do { \
  146. ieee_float_shape_type sf_u; \
  147. sf_u.word = (i); \
  148. (d) = sf_u.value; \
  149. } while (0)
  150. /* ieee style elementary functions */
  151. extern double
  152. __ieee754_sqrt(double)
  153. attribute_hidden;
  154. extern double __ieee754_acos(double) attribute_hidden;
  155. extern double __ieee754_acosh(double) attribute_hidden;
  156. extern double __ieee754_log(double) attribute_hidden;
  157. extern double __ieee754_atanh(double) attribute_hidden;
  158. extern double __ieee754_asin(double) attribute_hidden;
  159. extern double __ieee754_atan2(double, double) attribute_hidden;
  160. extern double __ieee754_exp(double) attribute_hidden;
  161. extern double __ieee754_cosh(double) attribute_hidden;
  162. extern double __ieee754_fmod(double, double) attribute_hidden;
  163. extern double __ieee754_pow(double, double) attribute_hidden;
  164. extern double __ieee754_lgamma_r(double, int *) attribute_hidden;
  165. extern double __ieee754_gamma_r(double, int *) attribute_hidden;
  166. extern double __ieee754_lgamma(double) attribute_hidden;
  167. extern double __ieee754_gamma(double) attribute_hidden;
  168. extern double __ieee754_log10(double) attribute_hidden;
  169. extern double __ieee754_sinh(double) attribute_hidden;
  170. extern double __ieee754_hypot(double, double) attribute_hidden;
  171. extern double __ieee754_j0(double) attribute_hidden;
  172. extern double __ieee754_j1(double) attribute_hidden;
  173. extern double __ieee754_y0(double) attribute_hidden;
  174. extern double __ieee754_y1(double) attribute_hidden;
  175. extern double __ieee754_jn(int, double) attribute_hidden;
  176. extern double __ieee754_yn(int, double) attribute_hidden;
  177. extern double __ieee754_remainder(double, double) attribute_hidden;
  178. extern int32_t __ieee754_rem_pio2(double, double *) attribute_hidden;
  179. #if defined(_SCALB_INT)
  180. extern double __ieee754_scalb(double, int) attribute_hidden;
  181. #else
  182. extern double __ieee754_scalb(double, double) attribute_hidden;
  183. #endif
  184. /* fdlibm kernel function */
  185. #ifndef _IEEE_LIBM
  186. extern double __kernel_standard(double, double, int) attribute_hidden;
  187. #endif
  188. extern double __kernel_sin(double, double, int) attribute_hidden;
  189. extern double __kernel_cos(double, double) attribute_hidden;
  190. extern double __kernel_tan(double, double, int) attribute_hidden;
  191. extern int32_t __kernel_rem_pio2(const double *, double *, int, int, const unsigned int,
  192. const int32_t *) attribute_hidden;
  193. #endif /* _MATH_PRIVATE_H_ */