math_private_openbsd.h 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218
  1. /* $OpenBSD: math_private.h,v 1.17 2014/06/02 19:31:17 kettenis Exp $ */
  2. /*
  3. * ====================================================
  4. * Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved.
  5. *
  6. * Developed at SunPro, a Sun Microsystems, Inc. business.
  7. * Permission to use, copy, modify, and distribute this
  8. * software is freely granted, provided that this notice
  9. * is preserved.
  10. * ====================================================
  11. */
  12. /*
  13. * from: @(#)fdlibm.h 5.1 93/09/24
  14. */
  15. #ifndef _MATH_PRIVATE_OPENBSD_H_
  16. #define _MATH_PRIVATE_OPENBSD_H_
  17. #if _IEEE_WORD_ORDER == _BIG_ENDIAN
  18. typedef union
  19. {
  20. long double value;
  21. struct {
  22. u_int32_t mswhi;
  23. u_int32_t mswlo;
  24. u_int32_t lswhi;
  25. u_int32_t lswlo;
  26. } parts32;
  27. struct {
  28. u_int64_t msw;
  29. u_int64_t lsw;
  30. } parts64;
  31. } ieee_quad_shape_type;
  32. #endif
  33. #if _IEEE_WORD_ORDER == _LITTLE_ENDIAN
  34. typedef union
  35. {
  36. long double value;
  37. struct {
  38. u_int32_t lswlo;
  39. u_int32_t lswhi;
  40. u_int32_t mswlo;
  41. u_int32_t mswhi;
  42. } parts32;
  43. struct {
  44. u_int64_t lsw;
  45. u_int64_t msw;
  46. } parts64;
  47. } ieee_quad_shape_type;
  48. #endif
  49. /* Get two 64 bit ints from a long double. */
  50. #define GET_LDOUBLE_WORDS64(ix0,ix1,d) \
  51. do { \
  52. ieee_quad_shape_type qw_u; \
  53. qw_u.value = (d); \
  54. (ix0) = qw_u.parts64.msw; \
  55. (ix1) = qw_u.parts64.lsw; \
  56. } while (0)
  57. /* Set a long double from two 64 bit ints. */
  58. #define SET_LDOUBLE_WORDS64(d,ix0,ix1) \
  59. do { \
  60. ieee_quad_shape_type qw_u; \
  61. qw_u.parts64.msw = (ix0); \
  62. qw_u.parts64.lsw = (ix1); \
  63. (d) = qw_u.value; \
  64. } while (0)
  65. /* Get the more significant 64 bits of a long double mantissa. */
  66. #define GET_LDOUBLE_MSW64(v,d) \
  67. do { \
  68. ieee_quad_shape_type sh_u; \
  69. sh_u.value = (d); \
  70. (v) = sh_u.parts64.msw; \
  71. } while (0)
  72. /* Set the more significant 64 bits of a long double mantissa from an int. */
  73. #define SET_LDOUBLE_MSW64(d,v) \
  74. do { \
  75. ieee_quad_shape_type sh_u; \
  76. sh_u.value = (d); \
  77. sh_u.parts64.msw = (v); \
  78. (d) = sh_u.value; \
  79. } while (0)
  80. /* Get the least significant 64 bits of a long double mantissa. */
  81. #define GET_LDOUBLE_LSW64(v,d) \
  82. do { \
  83. ieee_quad_shape_type sh_u; \
  84. sh_u.value = (d); \
  85. (v) = sh_u.parts64.lsw; \
  86. } while (0)
  87. /* A union which permits us to convert between a long double and
  88. three 32 bit ints. */
  89. #if _IEEE_WORD_ORDER == _BIG_ENDIAN
  90. typedef union
  91. {
  92. long double value;
  93. struct {
  94. #ifdef __LP64__
  95. int padh:32;
  96. #endif
  97. int exp:16;
  98. int padl:16;
  99. u_int32_t msw;
  100. u_int32_t lsw;
  101. } parts;
  102. } ieee_extended_shape_type;
  103. #endif
  104. #if _IEEE_WORD_ORDER == _LITTLE_ENDIAN
  105. typedef union
  106. {
  107. long double value;
  108. struct {
  109. u_int32_t lsw;
  110. u_int32_t msw;
  111. int exp:16;
  112. int padl:16;
  113. #ifdef __LP64__
  114. int padh:32;
  115. #endif
  116. } parts;
  117. } ieee_extended_shape_type;
  118. #endif
  119. /* Get three 32 bit ints from a double. */
  120. #define GET_LDOUBLE_WORDS(se,ix0,ix1,d) \
  121. do { \
  122. ieee_extended_shape_type ew_u; \
  123. ew_u.value = (d); \
  124. (se) = ew_u.parts.exp; \
  125. (ix0) = ew_u.parts.msw; \
  126. (ix1) = ew_u.parts.lsw; \
  127. } while (0)
  128. /* Set a double from two 32 bit ints. */
  129. #define SET_LDOUBLE_WORDS(d,se,ix0,ix1) \
  130. do { \
  131. ieee_extended_shape_type iw_u; \
  132. iw_u.parts.exp = (se); \
  133. iw_u.parts.msw = (ix0); \
  134. iw_u.parts.lsw = (ix1); \
  135. (d) = iw_u.value; \
  136. } while (0)
  137. /* Get the more significant 32 bits of a long double mantissa. */
  138. #define GET_LDOUBLE_MSW(v,d) \
  139. do { \
  140. ieee_extended_shape_type sh_u; \
  141. sh_u.value = (d); \
  142. (v) = sh_u.parts.msw; \
  143. } while (0)
  144. /* Set the more significant 32 bits of a long double mantissa from an int. */
  145. #define SET_LDOUBLE_MSW(d,v) \
  146. do { \
  147. ieee_extended_shape_type sh_u; \
  148. sh_u.value = (d); \
  149. sh_u.parts.msw = (v); \
  150. (d) = sh_u.value; \
  151. } while (0)
  152. /* Get int from the exponent of a long double. */
  153. #define GET_LDOUBLE_EXP(se,d) \
  154. do { \
  155. ieee_extended_shape_type ge_u; \
  156. ge_u.value = (d); \
  157. (se) = ge_u.parts.exp; \
  158. } while (0)
  159. /* Set exponent of a long double from an int. */
  160. #define SET_LDOUBLE_EXP(d,se) \
  161. do { \
  162. ieee_extended_shape_type se_u; \
  163. se_u.value = (d); \
  164. se_u.parts.exp = (se); \
  165. (d) = se_u.value; \
  166. } while (0)
  167. /*
  168. * Common routine to process the arguments to nan(), nanf(), and nanl().
  169. */
  170. void _scan_nan(uint32_t *__words, int __num_words, const char *__s);
  171. /*
  172. * Functions internal to the math package, yet not static.
  173. */
  174. double __exp__D(double, double);
  175. struct Double __log__D(double);
  176. long double __p1evll(long double, void *, int);
  177. long double __polevll(long double, void *, int);
  178. #endif /* _MATH_PRIVATE_OPENBSD_H_ */