2005-12-05 Roland McGrath <roland@redhat.com>
[glibc.git] / sysdeps / mips / ieee754.h
blobed13de27757ef562016d8085912a210b724db144
1 /* Copyright (C) 1992, 1995, 1996, 1999, 2002, 2003
2 Free Software Foundation, Inc.
3 This file is part of the GNU C Library.
5 The GNU C Library is free software; you can redistribute it and/or
6 modify it under the terms of the GNU Lesser General Public
7 License as published by the Free Software Foundation; either
8 version 2.1 of the License, or (at your option) any later version.
10 The GNU C Library is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Lesser General Public License for more details.
15 You should have received a copy of the GNU Lesser General Public
16 License along with the GNU C Library; if not, write to the Free
17 Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
18 02111-1307 USA. */
20 #ifndef _IEEE754_H
22 #define _IEEE754_H 1
23 #include <features.h>
25 #include <endian.h>
27 #include <float.h>
29 __BEGIN_DECLS
31 union ieee754_float
33 float f;
35 /* This is the IEEE 754 single-precision format. */
36 struct
38 #if __BYTE_ORDER == __BIG_ENDIAN
39 unsigned int negative:1;
40 unsigned int exponent:8;
41 unsigned int mantissa:23;
42 #endif /* Big endian. */
43 #if __BYTE_ORDER == __LITTLE_ENDIAN
44 unsigned int mantissa:23;
45 unsigned int exponent:8;
46 unsigned int negative:1;
47 #endif /* Little endian. */
48 } ieee;
50 /* This format makes it easier to see if a NaN is a signalling NaN. */
51 struct
53 #if __BYTE_ORDER == __BIG_ENDIAN
54 unsigned int negative:1;
55 unsigned int exponent:8;
56 unsigned int quiet_nan:1;
57 unsigned int mantissa:22;
58 #endif /* Big endian. */
59 #if __BYTE_ORDER == __LITTLE_ENDIAN
60 unsigned int mantissa:22;
61 unsigned int quiet_nan:1;
62 unsigned int exponent:8;
63 unsigned int negative:1;
64 #endif /* Little endian. */
65 } ieee_nan;
68 #define IEEE754_FLOAT_BIAS 0x7f /* Added to exponent. */
71 union ieee754_double
73 double d;
75 /* This is the IEEE 754 double-precision format. */
76 struct
78 #if __BYTE_ORDER == __BIG_ENDIAN
79 unsigned int negative:1;
80 unsigned int exponent:11;
81 /* Together these comprise the mantissa. */
82 unsigned int mantissa0:20;
83 unsigned int mantissa1:32;
84 #endif /* Big endian. */
85 #if __BYTE_ORDER == __LITTLE_ENDIAN
86 # if __FLOAT_WORD_ORDER == BIG_ENDIAN
87 unsigned int mantissa0:20;
88 unsigned int exponent:11;
89 unsigned int negative:1;
90 unsigned int mantissa1:32;
91 # else
92 /* Together these comprise the mantissa. */
93 unsigned int mantissa1:32;
94 unsigned int mantissa0:20;
95 unsigned int exponent:11;
96 unsigned int negative:1;
97 # endif
98 #endif /* Little endian. */
99 } ieee;
101 /* This format makes it easier to see if a NaN is a signalling NaN. */
102 struct
104 #if __BYTE_ORDER == __BIG_ENDIAN
105 unsigned int negative:1;
106 unsigned int exponent:11;
107 unsigned int quiet_nan:1;
108 /* Together these comprise the mantissa. */
109 unsigned int mantissa0:19;
110 unsigned int mantissa1:32;
111 #else
112 # if __FLOAT_WORD_ORDER == BIG_ENDIAN
113 unsigned int mantissa0:19;
114 unsigned int quiet_nan:1;
115 unsigned int exponent:11;
116 unsigned int negative:1;
117 unsigned int mantissa1:32;
118 # else
119 /* Together these comprise the mantissa. */
120 unsigned int mantissa1:32;
121 unsigned int mantissa0:19;
122 unsigned int quiet_nan:1;
123 unsigned int exponent:11;
124 unsigned int negative:1;
125 # endif
126 #endif
127 } ieee_nan;
130 #define IEEE754_DOUBLE_BIAS 0x3ff /* Added to exponent. */
132 #if LDBL_MANT_DIG == 113
134 union ieee854_long_double
136 long double d;
138 /* This is the IEEE 854 quad-precision format. */
139 struct
141 #if __BYTE_ORDER == __BIG_ENDIAN
142 unsigned int negative:1;
143 unsigned int exponent:15;
144 /* Together these comprise the mantissa. */
145 unsigned int mantissa0:16;
146 unsigned int mantissa1:32;
147 unsigned int mantissa2:32;
148 unsigned int mantissa3:32;
149 #endif /* Big endian. */
150 #if __BYTE_ORDER == __LITTLE_ENDIAN
151 /* Together these comprise the mantissa. */
152 unsigned int mantissa3:32;
153 unsigned int mantissa2:32;
154 unsigned int mantissa1:32;
155 unsigned int mantissa0:16;
156 unsigned int exponent:15;
157 unsigned int negative:1;
158 #endif /* Little endian. */
159 } ieee;
161 /* This format makes it easier to see if a NaN is a signalling NaN. */
162 struct
164 #if __BYTE_ORDER == __BIG_ENDIAN
165 unsigned int negative:1;
166 unsigned int exponent:15;
167 unsigned int quiet_nan:1;
168 /* Together these comprise the mantissa. */
169 unsigned int mantissa0:15;
170 unsigned int mantissa1:32;
171 unsigned int mantissa2:32;
172 unsigned int mantissa3:32;
173 #endif /* Big endian. */
174 #if __BYTE_ORDER == __LITTLE_ENDIAN
175 /* Together these comprise the mantissa. */
176 unsigned int mantissa3:32;
177 unsigned int mantissa2:32;
178 unsigned int mantissa1:32;
179 unsigned int mantissa0:15;
180 unsigned int quiet_nan:1;
181 unsigned int exponent:15;
182 unsigned int negative:1;
183 #endif /* Little endian. */
184 } ieee_nan;
187 #define IEEE854_LONG_DOUBLE_BIAS 0x3fff /* Added to exponent. */
189 #elif LDBL_MANT_DIG == 64
191 union ieee854_long_double
193 long double d;
195 /* This is the IEEE 854 double-extended-precision format. */
196 struct
198 #if __BYTE_ORDER == __BIG_ENDIAN
199 unsigned int negative:1;
200 unsigned int exponent:15;
201 unsigned int empty:16;
202 unsigned int mantissa0:32;
203 unsigned int mantissa1:32;
204 #endif
205 #if __BYTE_ORDER == __LITTLE_ENDIAN
206 # if __FLOAT_WORD_ORDER == BIG_ENDIAN
207 unsigned int exponent:15;
208 unsigned int negative:1;
209 unsigned int empty:16;
210 unsigned int mantissa0:32;
211 unsigned int mantissa1:32;
212 # else
213 unsigned int mantissa1:32;
214 unsigned int mantissa0:32;
215 unsigned int exponent:15;
216 unsigned int negative:1;
217 unsigned int empty:16;
218 # endif
219 #endif
220 } ieee;
222 /* This is for NaNs in the IEEE 854 double-extended-precision format. */
223 struct
225 #if __BYTE_ORDER == __BIG_ENDIAN
226 unsigned int negative:1;
227 unsigned int exponent:15;
228 unsigned int empty:16;
229 unsigned int one:1;
230 unsigned int quiet_nan:1;
231 unsigned int mantissa0:30;
232 unsigned int mantissa1:32;
233 #endif
234 #if __BYTE_ORDER == __LITTLE_ENDIAN
235 # if __FLOAT_WORD_ORDER == BIG_ENDIAN
236 unsigned int exponent:15;
237 unsigned int negative:1;
238 unsigned int empty:16;
239 unsigned int mantissa0:30;
240 unsigned int quiet_nan:1;
241 unsigned int one:1;
242 unsigned int mantissa1:32;
243 # else
244 unsigned int mantissa1:32;
245 unsigned int mantissa0:30;
246 unsigned int quiet_nan:1;
247 unsigned int one:1;
248 unsigned int exponent:15;
249 unsigned int negative:1;
250 unsigned int empty:16;
251 # endif
252 #endif
253 } ieee_nan;
256 #define IEEE854_LONG_DOUBLE_BIAS 0x3fff
258 #elif LDBL_MANT_DIG == 53
260 union ieee854_long_double
262 long double d;
264 /* This is the IEEE 754 double-precision format. */
265 struct
267 #if __BYTE_ORDER == __BIG_ENDIAN
268 unsigned int negative:1;
269 unsigned int exponent:11;
270 /* Together these comprise the mantissa. */
271 unsigned int mantissa0:20;
272 unsigned int mantissa1:32;
273 #endif /* Big endian. */
274 #if __BYTE_ORDER == __LITTLE_ENDIAN
275 # if __FLOAT_WORD_ORDER == BIG_ENDIAN
276 unsigned int mantissa0:20;
277 unsigned int exponent:11;
278 unsigned int negative:1;
279 unsigned int mantissa1:32;
280 # else
281 /* Together these comprise the mantissa. */
282 unsigned int mantissa1:32;
283 unsigned int mantissa0:20;
284 unsigned int exponent:11;
285 unsigned int negative:1;
286 # endif
287 #endif /* Little endian. */
288 } ieee;
290 /* This format makes it easier to see if a NaN is a signalling NaN. */
291 struct
293 #if __BYTE_ORDER == __BIG_ENDIAN
294 unsigned int negative:1;
295 unsigned int exponent:11;
296 unsigned int quiet_nan:1;
297 /* Together these comprise the mantissa. */
298 unsigned int mantissa0:19;
299 unsigned int mantissa1:32;
300 #else
301 # if __FLOAT_WORD_ORDER == BIG_ENDIAN
302 unsigned int mantissa0:19;
303 unsigned int quiet_nan:1;
304 unsigned int exponent:11;
305 unsigned int negative:1;
306 unsigned int mantissa1:32;
307 # else
308 /* Together these comprise the mantissa. */
309 unsigned int mantissa1:32;
310 unsigned int mantissa0:19;
311 unsigned int quiet_nan:1;
312 unsigned int exponent:11;
313 unsigned int negative:1;
314 # endif
315 #endif
316 } ieee_nan;
319 #define IEEE854_LONG_DOUBLE_BIAS 0x3ff /* Added to exponent. */
321 #endif /* LDBL_MANT_DIG == 53 */
323 __END_DECLS
325 #endif /* ieee754.h */