Fri Jan 12 13:40:01 1996 Roland McGrath <roland@churchy.gnu.ai.mit.edu>
[glibc.git] / sysdeps / ieee754 / ieee754.h
blob9cc6f1470711d793f2ac62a07536fb7367fa9b36
1 /* Copyright (C) 1992, 1995 Free Software Foundation, Inc.
2 This file is part of the GNU C Library.
4 The GNU C Library is free software; you can redistribute it and/or
5 modify it under the terms of the GNU Library General Public License as
6 published by the Free Software Foundation; either version 2 of the
7 License, or (at your option) any later version.
9 The GNU C Library is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 Library General Public License for more details.
14 You should have received a copy of the GNU Library General Public
15 License along with the GNU C Library; see the file COPYING.LIB. If
16 not, write to the Free Software Foundation, Inc., 675 Mass Ave,
17 Cambridge, MA 02139, USA. */
19 #include <endian.h>
21 union ieee754_float
23 float f;
25 /* This is the IEEE 754 single-precision format. */
26 struct
28 #if __BYTE_ORDER == __BIG_ENDIAN
29 unsigned int negative:1;
30 unsigned int exponent:8;
31 unsigned int mantissa:23;
32 #endif /* Big endian. */
33 #if __BYTE_ORDER == __LITTLE_ENDIAN
34 unsigned int mantissa:23;
35 unsigned int exponent:8;
36 unsigned int negative:1;
37 #endif /* Little endian. */
38 } ieee;
40 /* This format makes it easier to see if a NaN is a signalling NaN. */
41 struct
43 #if __BYTE_ORDER == __BIG_ENDIAN
44 unsigned int negative:1;
45 unsigned int exponent:8;
46 unsigned int quiet_nan:1;
47 unsigned int mantissa:22;
48 #endif /* Big endian. */
49 #if __BYTE_ORDER == __LITTLE_ENDIAN
50 unsigned int mantissa:22;
51 unsigned int quiet_nan:1;
52 unsigned int exponent:8;
53 unsigned int negative:1;
54 #endif /* Little endian. */
55 } ieee_nan;
58 #define IEEE754_FLOAT_BIAS 0x7f /* Added to exponent. */
61 union ieee754_double
63 double d;
65 /* This is the IEEE 754 double-precision format. */
66 struct
68 #if __BYTE_ORDER == __BIG_ENDIAN
69 unsigned int negative:1;
70 unsigned int exponent:11;
71 /* Together these comprise the mantissa. */
72 unsigned int mantissa0:20;
73 unsigned int mantissa1:32;
74 #endif /* Big endian. */
75 #if __BYTE_ORDER == __LITTLE_ENDIAN
76 /* Together these comprise the mantissa. */
77 unsigned int mantissa1:32;
78 unsigned int mantissa0:20;
79 unsigned int exponent:11;
80 unsigned int negative:1;
81 #endif /* Little endian. */
82 } ieee;
84 /* This format makes it easier to see if a NaN is a signalling NaN. */
85 struct
87 #if __BYTE_ORDER == __BIG_ENDIAN
88 unsigned int negative:1;
89 unsigned int exponent:11;
90 unsigned int quiet_nan:1;
91 /* Together these conprise the mantissa. */
92 unsigned int mantissa0:19;
93 unsigned int mantissa1:32;
94 #else
95 /* Together these conprise the mantissa. */
96 unsigned int mantissa1:32;
97 unsigned int mantissa0:19;
98 unsigned int quiet_nan:1;
99 unsigned int exponent:11;
100 unsigned int negative:1;
101 #endif
102 } ieee_nan;
105 #define IEEE754_DOUBLE_BIAS 0x3ff /* Added to exponent. */
108 union ieee854_long_double
110 long double d;
112 /* This is the IEEE 854 double-extended-precision format. */
113 struct
115 #if __BYTE_ORDER == __BIG_ENDIAN
116 unsigned int negative:1;
117 unsigned int exponent:15;
118 unsigned int empty:16;
119 unsigned int mantissa0:32;
120 unsigned int mantissa1:32;
121 #endif
122 #if __BYTE_ORDER == __LITTLE_ENDIAN
123 unsigned int mantissa1:32;
124 unsigned int mantissa0:32;
125 unsigned int exponent:15;
126 unsigned int negative:1;
127 unsigned int empty:16;
128 #endif
129 } ieee;
131 /* This is for NaNs in the IEEE 854 double-extended-precision format. */
132 struct
134 #if __BYTE_ORDER == __BIG_ENDIAN
135 unsigned int negative:1;
136 unsigned int exponent:15;
137 unsigned int empty:16;
138 unsigned int quiet_nan:1;
139 unsigned int mantissa0:31;
140 unsigned int mantissa1:32;
141 #endif
142 #if __BYTE_ORDER == __LITTLE_ENDIAN
143 unsigned int mantissa1:32;
144 unsigned int mantissa0:31;
145 unsigned int quiet_nan:1;
146 unsigned int exponent:15;
147 unsigned int negative:1;
148 unsigned int empty:16;
149 #endif
150 } ieee_nan;
153 #define IEEE854_LONG_DOUBLE_BIAS 0x3fff