math_private.h 6.6 KB

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