ieee754.h 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199
  1. /* Copyright (C) 1992, 1995, 1996, 1999 Free Software Foundation, Inc.
  2. This file is part of the GNU C Library.
  3. The GNU C Library is free software; you can redistribute it and/or
  4. modify it under the terms of the GNU Lesser General Public
  5. License as published by the Free Software Foundation; either
  6. version 2.1 of the License, or (at your option) any later version.
  7. The GNU C Library is distributed in the hope that it will be useful,
  8. but WITHOUT ANY WARRANTY; without even the implied warranty of
  9. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  10. Lesser General Public License for more details.
  11. You should have received a copy of the GNU Lesser General Public
  12. License along with the GNU C Library; if not, write to the Free
  13. Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
  14. 02111-1307 USA. */
  15. #ifndef _IEEE754_H
  16. #define _IEEE754_H 1
  17. #include <features.h>
  18. #include <endian.h>
  19. __BEGIN_DECLS
  20. union ieee754_float
  21. {
  22. float f;
  23. /* This is the IEEE 754 single-precision format. */
  24. struct
  25. {
  26. #if __BYTE_ORDER == __BIG_ENDIAN
  27. unsigned int negative:1;
  28. unsigned int exponent:8;
  29. unsigned int mantissa:23;
  30. #endif /* Big endian. */
  31. #if __BYTE_ORDER == __LITTLE_ENDIAN
  32. unsigned int mantissa:23;
  33. unsigned int exponent:8;
  34. unsigned int negative:1;
  35. #endif /* Little endian. */
  36. } ieee;
  37. /* This format makes it easier to see if a NaN is a signalling NaN. */
  38. struct
  39. {
  40. #if __BYTE_ORDER == __BIG_ENDIAN
  41. unsigned int negative:1;
  42. unsigned int exponent:8;
  43. unsigned int quiet_nan:1;
  44. unsigned int mantissa:22;
  45. #endif /* Big endian. */
  46. #if __BYTE_ORDER == __LITTLE_ENDIAN
  47. unsigned int mantissa:22;
  48. unsigned int quiet_nan:1;
  49. unsigned int exponent:8;
  50. unsigned int negative:1;
  51. #endif /* Little endian. */
  52. } ieee_nan;
  53. };
  54. #define IEEE754_FLOAT_BIAS 0x7f /* Added to exponent. */
  55. union ieee754_double
  56. {
  57. double d;
  58. /* This is the IEEE 754 double-precision format. */
  59. struct
  60. {
  61. #if __BYTE_ORDER == __BIG_ENDIAN
  62. unsigned int negative:1;
  63. unsigned int exponent:11;
  64. /* Together these comprise the mantissa. */
  65. unsigned int mantissa0:20;
  66. unsigned int mantissa1:32;
  67. #endif /* Big endian. */
  68. #if __BYTE_ORDER == __LITTLE_ENDIAN
  69. # if __FLOAT_WORD_ORDER == __BIG_ENDIAN
  70. unsigned int mantissa0:20;
  71. unsigned int exponent:11;
  72. unsigned int negative:1;
  73. unsigned int mantissa1:32;
  74. # else
  75. /* Together these comprise the mantissa. */
  76. unsigned int mantissa1:32;
  77. unsigned int mantissa0:20;
  78. unsigned int exponent:11;
  79. unsigned int negative:1;
  80. # endif
  81. #endif /* Little endian. */
  82. } ieee;
  83. /* This format makes it easier to see if a NaN is a signalling NaN. */
  84. struct
  85. {
  86. #if __BYTE_ORDER == __BIG_ENDIAN
  87. unsigned int negative:1;
  88. unsigned int exponent:11;
  89. unsigned int quiet_nan:1;
  90. /* Together these comprise the mantissa. */
  91. unsigned int mantissa0:19;
  92. unsigned int mantissa1:32;
  93. #else
  94. # if __FLOAT_WORD_ORDER == __BIG_ENDIAN
  95. unsigned int mantissa0:19;
  96. unsigned int quiet_nan:1;
  97. unsigned int exponent:11;
  98. unsigned int negative:1;
  99. unsigned int mantissa1:32;
  100. # else
  101. /* Together these comprise the mantissa. */
  102. unsigned int mantissa1:32;
  103. unsigned int mantissa0:19;
  104. unsigned int quiet_nan:1;
  105. unsigned int exponent:11;
  106. unsigned int negative:1;
  107. # endif
  108. #endif
  109. } ieee_nan;
  110. };
  111. #define IEEE754_DOUBLE_BIAS 0x3ff /* Added to exponent. */
  112. union ieee854_long_double
  113. {
  114. long double d;
  115. /* This is the IEEE 854 double-extended-precision format. */
  116. struct
  117. {
  118. #if __BYTE_ORDER == __BIG_ENDIAN
  119. unsigned int negative:1;
  120. unsigned int exponent:15;
  121. unsigned int empty:16;
  122. unsigned int mantissa0:32;
  123. unsigned int mantissa1:32;
  124. #endif
  125. #if __BYTE_ORDER == __LITTLE_ENDIAN
  126. # if __FLOAT_WORD_ORDER == __BIG_ENDIAN
  127. unsigned int exponent:15;
  128. unsigned int negative:1;
  129. unsigned int empty:16;
  130. unsigned int mantissa0:32;
  131. unsigned int mantissa1:32;
  132. # else
  133. unsigned int mantissa1:32;
  134. unsigned int mantissa0:32;
  135. unsigned int exponent:15;
  136. unsigned int negative:1;
  137. unsigned int empty:16;
  138. # endif
  139. #endif
  140. } ieee;
  141. /* This is for NaNs in the IEEE 854 double-extended-precision format. */
  142. struct
  143. {
  144. #if __BYTE_ORDER == __BIG_ENDIAN
  145. unsigned int negative:1;
  146. unsigned int exponent:15;
  147. unsigned int empty:16;
  148. unsigned int one:1;
  149. unsigned int quiet_nan:1;
  150. unsigned int mantissa0:30;
  151. unsigned int mantissa1:32;
  152. #endif
  153. #if __BYTE_ORDER == __LITTLE_ENDIAN
  154. # if __FLOAT_WORD_ORDER == __BIG_ENDIAN
  155. unsigned int exponent:15;
  156. unsigned int negative:1;
  157. unsigned int empty:16;
  158. unsigned int mantissa0:30;
  159. unsigned int quiet_nan:1;
  160. unsigned int one:1;
  161. unsigned int mantissa1:32;
  162. # else
  163. unsigned int mantissa1:32;
  164. unsigned int mantissa0:30;
  165. unsigned int quiet_nan:1;
  166. unsigned int one:1;
  167. unsigned int exponent:15;
  168. unsigned int negative:1;
  169. unsigned int empty:16;
  170. # endif
  171. #endif
  172. } ieee_nan;
  173. };
  174. #define IEEE854_LONG_DOUBLE_BIAS 0x3fff
  175. __END_DECLS
  176. #endif /* ieee754.h */