math_private.h 7.0 KB

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