Move all files into ports/ subdirectory in preparation for merge with glibc
[glibc.git] / ports / sysdeps / mips / ieee754.h
blob87dbf658eb0ed885d13ea4890759c667b94534f4
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, see
17 <http://www.gnu.org/licenses/>. */
19 #ifndef _IEEE754_H
21 #define _IEEE754_H 1
22 #include <features.h>
24 #include <endian.h>
26 #include <float.h>
28 __BEGIN_DECLS
30 union ieee754_float
32 float f;
34 /* This is the IEEE 754 single-precision format. */
35 struct
37 #if __BYTE_ORDER == __BIG_ENDIAN
38 unsigned int negative:1;
39 unsigned int exponent:8;
40 unsigned int mantissa:23;
41 #endif /* Big endian. */
42 #if __BYTE_ORDER == __LITTLE_ENDIAN
43 unsigned int mantissa:23;
44 unsigned int exponent:8;
45 unsigned int negative:1;
46 #endif /* Little endian. */
47 } ieee;
49 /* This format makes it easier to see if a NaN is a signalling NaN. */
50 struct
52 #if __BYTE_ORDER == __BIG_ENDIAN
53 unsigned int negative:1;
54 unsigned int exponent:8;
55 unsigned int quiet_nan:1;
56 unsigned int mantissa:22;
57 #endif /* Big endian. */
58 #if __BYTE_ORDER == __LITTLE_ENDIAN
59 unsigned int mantissa:22;
60 unsigned int quiet_nan:1;
61 unsigned int exponent:8;
62 unsigned int negative:1;
63 #endif /* Little endian. */
64 } ieee_nan;
67 #define IEEE754_FLOAT_BIAS 0x7f /* Added to exponent. */
70 union ieee754_double
72 double d;
74 /* This is the IEEE 754 double-precision format. */
75 struct
77 #if __BYTE_ORDER == __BIG_ENDIAN
78 unsigned int negative:1;
79 unsigned int exponent:11;
80 /* Together these comprise the mantissa. */
81 unsigned int mantissa0:20;
82 unsigned int mantissa1:32;
83 #endif /* Big endian. */
84 #if __BYTE_ORDER == __LITTLE_ENDIAN
85 # if __FLOAT_WORD_ORDER == __BIG_ENDIAN
86 unsigned int mantissa0:20;
87 unsigned int exponent:11;
88 unsigned int negative:1;
89 unsigned int mantissa1:32;
90 # else
91 /* Together these comprise the mantissa. */
92 unsigned int mantissa1:32;
93 unsigned int mantissa0:20;
94 unsigned int exponent:11;
95 unsigned int negative:1;
96 # endif
97 #endif /* Little endian. */
98 } ieee;
100 /* This format makes it easier to see if a NaN is a signalling NaN. */
101 struct
103 #if __BYTE_ORDER == __BIG_ENDIAN
104 unsigned int negative:1;
105 unsigned int exponent:11;
106 unsigned int quiet_nan:1;
107 /* Together these comprise the mantissa. */
108 unsigned int mantissa0:19;
109 unsigned int mantissa1:32;
110 #else
111 # if __FLOAT_WORD_ORDER == __BIG_ENDIAN
112 unsigned int mantissa0:19;
113 unsigned int quiet_nan:1;
114 unsigned int exponent:11;
115 unsigned int negative:1;
116 unsigned int mantissa1:32;
117 # else
118 /* Together these comprise the mantissa. */
119 unsigned int mantissa1:32;
120 unsigned int mantissa0:19;
121 unsigned int quiet_nan:1;
122 unsigned int exponent:11;
123 unsigned int negative:1;
124 # endif
125 #endif
126 } ieee_nan;
129 #define IEEE754_DOUBLE_BIAS 0x3ff /* Added to exponent. */
131 #if LDBL_MANT_DIG == 113
133 union ieee854_long_double
135 long double d;
137 /* This is the IEEE 854 quad-precision format. */
138 struct
140 #if __BYTE_ORDER == __BIG_ENDIAN
141 unsigned int negative:1;
142 unsigned int exponent:15;
143 /* Together these comprise the mantissa. */
144 unsigned int mantissa0:16;
145 unsigned int mantissa1:32;
146 unsigned int mantissa2:32;
147 unsigned int mantissa3:32;
148 #endif /* Big endian. */
149 #if __BYTE_ORDER == __LITTLE_ENDIAN
150 /* Together these comprise the mantissa. */
151 unsigned int mantissa3:32;
152 unsigned int mantissa2:32;
153 unsigned int mantissa1:32;
154 unsigned int mantissa0:16;
155 unsigned int exponent:15;
156 unsigned int negative:1;
157 #endif /* Little endian. */
158 } ieee;
160 /* This format makes it easier to see if a NaN is a signalling NaN. */
161 struct
163 #if __BYTE_ORDER == __BIG_ENDIAN
164 unsigned int negative:1;
165 unsigned int exponent:15;
166 unsigned int quiet_nan:1;
167 /* Together these comprise the mantissa. */
168 unsigned int mantissa0:15;
169 unsigned int mantissa1:32;
170 unsigned int mantissa2:32;
171 unsigned int mantissa3:32;
172 #endif /* Big endian. */
173 #if __BYTE_ORDER == __LITTLE_ENDIAN
174 /* Together these comprise the mantissa. */
175 unsigned int mantissa3:32;
176 unsigned int mantissa2:32;
177 unsigned int mantissa1:32;
178 unsigned int mantissa0:15;
179 unsigned int quiet_nan:1;
180 unsigned int exponent:15;
181 unsigned int negative:1;
182 #endif /* Little endian. */
183 } ieee_nan;
186 #define IEEE854_LONG_DOUBLE_BIAS 0x3fff /* Added to exponent. */
188 #elif LDBL_MANT_DIG == 64
190 union ieee854_long_double
192 long double d;
194 /* This is the IEEE 854 double-extended-precision format. */
195 struct
197 #if __BYTE_ORDER == __BIG_ENDIAN
198 unsigned int negative:1;
199 unsigned int exponent:15;
200 unsigned int empty:16;
201 unsigned int mantissa0:32;
202 unsigned int mantissa1:32;
203 #endif
204 #if __BYTE_ORDER == __LITTLE_ENDIAN
205 # if __FLOAT_WORD_ORDER == __BIG_ENDIAN
206 unsigned int exponent:15;
207 unsigned int negative:1;
208 unsigned int empty:16;
209 unsigned int mantissa0:32;
210 unsigned int mantissa1:32;
211 # else
212 unsigned int mantissa1:32;
213 unsigned int mantissa0:32;
214 unsigned int exponent:15;
215 unsigned int negative:1;
216 unsigned int empty:16;
217 # endif
218 #endif
219 } ieee;
221 /* This is for NaNs in the IEEE 854 double-extended-precision format. */
222 struct
224 #if __BYTE_ORDER == __BIG_ENDIAN
225 unsigned int negative:1;
226 unsigned int exponent:15;
227 unsigned int empty:16;
228 unsigned int one:1;
229 unsigned int quiet_nan:1;
230 unsigned int mantissa0:30;
231 unsigned int mantissa1:32;
232 #endif
233 #if __BYTE_ORDER == __LITTLE_ENDIAN
234 # if __FLOAT_WORD_ORDER == __BIG_ENDIAN
235 unsigned int exponent:15;
236 unsigned int negative:1;
237 unsigned int empty:16;
238 unsigned int mantissa0:30;
239 unsigned int quiet_nan:1;
240 unsigned int one:1;
241 unsigned int mantissa1:32;
242 # else
243 unsigned int mantissa1:32;
244 unsigned int mantissa0:30;
245 unsigned int quiet_nan:1;
246 unsigned int one:1;
247 unsigned int exponent:15;
248 unsigned int negative:1;
249 unsigned int empty:16;
250 # endif
251 #endif
252 } ieee_nan;
255 #define IEEE854_LONG_DOUBLE_BIAS 0x3fff
257 #elif LDBL_MANT_DIG == 53
259 union ieee854_long_double
261 long double d;
263 /* This is the IEEE 754 double-precision format. */
264 struct
266 #if __BYTE_ORDER == __BIG_ENDIAN
267 unsigned int negative:1;
268 unsigned int exponent:11;
269 /* Together these comprise the mantissa. */
270 unsigned int mantissa0:20;
271 unsigned int mantissa1:32;
272 #endif /* Big endian. */
273 #if __BYTE_ORDER == __LITTLE_ENDIAN
274 # if __FLOAT_WORD_ORDER == __BIG_ENDIAN
275 unsigned int mantissa0:20;
276 unsigned int exponent:11;
277 unsigned int negative:1;
278 unsigned int mantissa1:32;
279 # else
280 /* Together these comprise the mantissa. */
281 unsigned int mantissa1:32;
282 unsigned int mantissa0:20;
283 unsigned int exponent:11;
284 unsigned int negative:1;
285 # endif
286 #endif /* Little endian. */
287 } ieee;
289 /* This format makes it easier to see if a NaN is a signalling NaN. */
290 struct
292 #if __BYTE_ORDER == __BIG_ENDIAN
293 unsigned int negative:1;
294 unsigned int exponent:11;
295 unsigned int quiet_nan:1;
296 /* Together these comprise the mantissa. */
297 unsigned int mantissa0:19;
298 unsigned int mantissa1:32;
299 #else
300 # if __FLOAT_WORD_ORDER == __BIG_ENDIAN
301 unsigned int mantissa0:19;
302 unsigned int quiet_nan:1;
303 unsigned int exponent:11;
304 unsigned int negative:1;
305 unsigned int mantissa1:32;
306 # else
307 /* Together these comprise the mantissa. */
308 unsigned int mantissa1:32;
309 unsigned int mantissa0:19;
310 unsigned int quiet_nan:1;
311 unsigned int exponent:11;
312 unsigned int negative:1;
313 # endif
314 #endif
315 } ieee_nan;
318 #define IEEE854_LONG_DOUBLE_BIAS 0x3ff /* Added to exponent. */
320 #endif /* LDBL_MANT_DIG == 53 */
322 __END_DECLS
324 #endif /* ieee754.h */