ieeefp.h 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256
  1. #ifndef _IEEE_FP_H_
  2. #define _IEEE_FP_H_
  3. #include "_ansi.h"
  4. #include <machine/ieeefp.h>
  5. _BEGIN_STD_C
  6. /* FIXME FIXME FIXME:
  7. Neither of __ieee_{float,double}_shape_tape seem to be used anywhere
  8. except in libm/test. If that is the case, please delete these from here.
  9. If that is not the case, please insert documentation here describing why
  10. they're needed. */
  11. #ifdef __IEEE_BIG_ENDIAN
  12. typedef union
  13. {
  14. double value;
  15. struct
  16. {
  17. unsigned int sign : 1;
  18. unsigned int exponent: 11;
  19. unsigned int fraction0:4;
  20. unsigned int fraction1:16;
  21. unsigned int fraction2:16;
  22. unsigned int fraction3:16;
  23. } number;
  24. struct
  25. {
  26. unsigned int sign : 1;
  27. unsigned int exponent: 11;
  28. unsigned int quiet:1;
  29. unsigned int function0:3;
  30. unsigned int function1:16;
  31. unsigned int function2:16;
  32. unsigned int function3:16;
  33. } nan;
  34. struct
  35. {
  36. unsigned long msw;
  37. unsigned long lsw;
  38. } parts;
  39. long aslong[2];
  40. } __ieee_double_shape_type;
  41. #endif
  42. #ifdef __IEEE_LITTLE_ENDIAN
  43. typedef union
  44. {
  45. double value;
  46. struct
  47. {
  48. #ifdef __SMALL_BITFIELDS
  49. unsigned int fraction3:16;
  50. unsigned int fraction2:16;
  51. unsigned int fraction1:16;
  52. unsigned int fraction0: 4;
  53. #else
  54. unsigned int fraction1:32;
  55. unsigned int fraction0:20;
  56. #endif
  57. unsigned int exponent :11;
  58. unsigned int sign : 1;
  59. } number;
  60. struct
  61. {
  62. #ifdef __SMALL_BITFIELDS
  63. unsigned int function3:16;
  64. unsigned int function2:16;
  65. unsigned int function1:16;
  66. unsigned int function0:3;
  67. #else
  68. unsigned int function1:32;
  69. unsigned int function0:19;
  70. #endif
  71. unsigned int quiet:1;
  72. unsigned int exponent: 11;
  73. unsigned int sign : 1;
  74. } nan;
  75. struct
  76. {
  77. unsigned long lsw;
  78. unsigned long msw;
  79. } parts;
  80. long aslong[2];
  81. } __ieee_double_shape_type;
  82. #endif
  83. #ifdef __IEEE_BIG_ENDIAN
  84. typedef union
  85. {
  86. float value;
  87. struct
  88. {
  89. unsigned int sign : 1;
  90. unsigned int exponent: 8;
  91. unsigned int fraction0: 7;
  92. unsigned int fraction1: 16;
  93. } number;
  94. struct
  95. {
  96. unsigned int sign:1;
  97. unsigned int exponent:8;
  98. unsigned int quiet:1;
  99. unsigned int function0:6;
  100. unsigned int function1:16;
  101. } nan;
  102. long p1;
  103. } __ieee_float_shape_type;
  104. #endif
  105. #ifdef __IEEE_LITTLE_ENDIAN
  106. typedef union
  107. {
  108. float value;
  109. struct
  110. {
  111. unsigned int fraction0: 7;
  112. unsigned int fraction1: 16;
  113. unsigned int exponent: 8;
  114. unsigned int sign : 1;
  115. } number;
  116. struct
  117. {
  118. unsigned int function1:16;
  119. unsigned int function0:6;
  120. unsigned int quiet:1;
  121. unsigned int exponent:8;
  122. unsigned int sign:1;
  123. } nan;
  124. long p1;
  125. } __ieee_float_shape_type;
  126. #endif
  127. /* FLOATING ROUNDING */
  128. typedef int fp_rnd;
  129. #define FP_RN 0 /* Round to nearest */
  130. #define FP_RM 1 /* Round down */
  131. #define FP_RP 2 /* Round up */
  132. #define FP_RZ 3 /* Round to zero (trunate) */
  133. fp_rnd _EXFUN(fpgetround,(void));
  134. fp_rnd _EXFUN(fpsetround, (fp_rnd));
  135. /* EXCEPTIONS */
  136. typedef int fp_except;
  137. #define FP_X_INV 0x10 /* Invalid operation */
  138. #define FP_X_DX 0x80 /* Divide by zero */
  139. #define FP_X_OFL 0x04 /* Overflow exception */
  140. #define FP_X_UFL 0x02 /* Underflow exception */
  141. #define FP_X_IMP 0x01 /* imprecise exception */
  142. fp_except _EXFUN(fpgetmask,(void));
  143. fp_except _EXFUN(fpsetmask,(fp_except));
  144. fp_except _EXFUN(fpgetsticky,(void));
  145. fp_except _EXFUN(fpsetsticky, (fp_except));
  146. /* INTEGER ROUNDING */
  147. typedef int fp_rdi;
  148. #define FP_RDI_TOZ 0 /* Round to Zero */
  149. #define FP_RDI_RD 1 /* Follow float mode */
  150. fp_rdi _EXFUN(fpgetroundtoi,(void));
  151. fp_rdi _EXFUN(fpsetroundtoi,(fp_rdi));
  152. #undef isnan
  153. #undef isinf
  154. int _EXFUN(isnan, (double));
  155. int _EXFUN(isinf, (double));
  156. int _EXFUN(finite, (double));
  157. int _EXFUN(isnanf, (float));
  158. int _EXFUN(isinff, (float));
  159. int _EXFUN(finitef, (float));
  160. #define __IEEE_DBL_EXPBIAS 1023
  161. #define __IEEE_FLT_EXPBIAS 127
  162. #define __IEEE_DBL_EXPLEN 11
  163. #define __IEEE_FLT_EXPLEN 8
  164. #define __IEEE_DBL_FRACLEN (64 - (__IEEE_DBL_EXPLEN + 1))
  165. #define __IEEE_FLT_FRACLEN (32 - (__IEEE_FLT_EXPLEN + 1))
  166. #define __IEEE_DBL_MAXPOWTWO ((double)(1L << 32 - 2) * (1L << (32-11) - 32 + 1))
  167. #define __IEEE_FLT_MAXPOWTWO ((float)(1L << (32-8) - 1))
  168. #define __IEEE_DBL_NAN_EXP 0x7ff
  169. #define __IEEE_FLT_NAN_EXP 0xff
  170. #ifndef __ieeefp_isnanf
  171. #define __ieeefp_isnanf(x) (((*(long *)&(x) & 0x7f800000L)==0x7f800000L) && \
  172. ((*(long *)&(x) & 0x007fffffL)!=0000000000L))
  173. #endif
  174. #define isnanf(x) __ieeefp_isnanf(x)
  175. #ifndef __ieeefp_isinff
  176. #define __ieeefp_isinff(x) (((*(long *)&(x) & 0x7f800000L)==0x7f800000L) && \
  177. ((*(long *)&(x) & 0x007fffffL)==0000000000L))
  178. #endif
  179. #define isinff(x) __ieeefp_isinff(x)
  180. #ifndef __ieeefp_finitef
  181. #define __ieeefp_finitef(x) (((*(long *)&(x) & 0x7f800000L)!=0x7f800000L))
  182. #endif
  183. #define finitef(x) __ieeefp_finitef(x)
  184. #ifdef _DOUBLE_IS_32BITS
  185. #undef __IEEE_DBL_EXPBIAS
  186. #define __IEEE_DBL_EXPBIAS __IEEE_FLT_EXPBIAS
  187. #undef __IEEE_DBL_EXPLEN
  188. #define __IEEE_DBL_EXPLEN __IEEE_FLT_EXPLEN
  189. #undef __IEEE_DBL_FRACLEN
  190. #define __IEEE_DBL_FRACLEN __IEEE_FLT_FRACLEN
  191. #undef __IEEE_DBL_MAXPOWTWO
  192. #define __IEEE_DBL_MAXPOWTWO __IEEE_FLT_MAXPOWTWO
  193. #undef __IEEE_DBL_NAN_EXP
  194. #define __IEEE_DBL_NAN_EXP __IEEE_FLT_NAN_EXP
  195. #undef __ieee_double_shape_type
  196. #define __ieee_double_shape_type __ieee_float_shape_type
  197. #endif /* _DOUBLE_IS_32BITS */
  198. _END_STD_C
  199. #endif /* _IEEE_FP_H_ */