Cygwin: mmap: allow remapping part of an existing anonymous mapping
[newlib-cygwin.git] / newlib / libc / include / ieeefp.h
blob2d6421a4c18e5aa027c31024b30e2d162031feee
1 #ifndef _IEEE_FP_H_
2 #define _IEEE_FP_H_
4 #include "_ansi.h"
6 #include <machine/ieeefp.h>
7 #include <float.h>
9 _BEGIN_STD_C
11 /* FIXME FIXME FIXME:
12 Neither of __ieee_{float,double}_shape_type seem to be used anywhere
13 except in libm/test. If that is the case, please delete these from here.
14 If that is not the case, please insert documentation here describing why
15 they're needed. */
17 #ifdef __IEEE_BIG_ENDIAN
19 typedef union
21 double value;
22 struct
24 unsigned int sign : 1;
25 unsigned int exponent: 11;
26 unsigned int fraction0:4;
27 unsigned int fraction1:16;
28 unsigned int fraction2:16;
29 unsigned int fraction3:16;
31 } number;
32 struct
34 unsigned int sign : 1;
35 unsigned int exponent: 11;
36 unsigned int quiet:1;
37 unsigned int function0:3;
38 unsigned int function1:16;
39 unsigned int function2:16;
40 unsigned int function3:16;
41 } nan;
42 struct
44 unsigned long msw;
45 unsigned long lsw;
46 } parts;
47 long aslong[2];
48 } __ieee_double_shape_type;
50 #elif defined __IEEE_LITTLE_ENDIAN
52 typedef union
54 double value;
55 struct
57 #ifdef __SMALL_BITFIELDS
58 unsigned int fraction3:16;
59 unsigned int fraction2:16;
60 unsigned int fraction1:16;
61 unsigned int fraction0: 4;
62 #else
63 unsigned int fraction1:32;
64 unsigned int fraction0:20;
65 #endif
66 unsigned int exponent :11;
67 unsigned int sign : 1;
68 } number;
69 struct
71 #ifdef __SMALL_BITFIELDS
72 unsigned int function3:16;
73 unsigned int function2:16;
74 unsigned int function1:16;
75 unsigned int function0:3;
76 #else
77 unsigned int function1:32;
78 unsigned int function0:19;
79 #endif
80 unsigned int quiet:1;
81 unsigned int exponent: 11;
82 unsigned int sign : 1;
83 } nan;
84 struct
86 unsigned long lsw;
87 unsigned long msw;
88 } parts;
90 long aslong[2];
92 } __ieee_double_shape_type;
94 #endif /* __IEEE_LITTLE_ENDIAN */
96 #ifdef __IEEE_BIG_ENDIAN
98 typedef union
100 float value;
101 struct
103 unsigned int sign : 1;
104 unsigned int exponent: 8;
105 unsigned int fraction0: 7;
106 unsigned int fraction1: 16;
107 } number;
108 struct
110 unsigned int sign:1;
111 unsigned int exponent:8;
112 unsigned int quiet:1;
113 unsigned int function0:6;
114 unsigned int function1:16;
115 } nan;
116 long p1;
118 } __ieee_float_shape_type;
120 #elif defined __IEEE_LITTLE_ENDIAN
122 typedef union
124 float value;
125 struct
127 unsigned int fraction0: 7;
128 unsigned int fraction1: 16;
129 unsigned int exponent: 8;
130 unsigned int sign : 1;
131 } number;
132 struct
134 unsigned int function1:16;
135 unsigned int function0:6;
136 unsigned int quiet:1;
137 unsigned int exponent:8;
138 unsigned int sign:1;
139 } nan;
140 long p1;
142 } __ieee_float_shape_type;
144 #endif /* __IEEE_LITTLE_ENDIAN */
146 #ifndef _LDBL_EQ_DBL
148 #ifndef LDBL_MANT_DIG
149 #error "LDBL_MANT_DIG not defined - should be found in float.h"
151 #elif LDBL_MANT_DIG == DBL_MANT_DIG
152 #error "double and long double are the same size but LDBL_EQ_DBL is not defined"
154 #elif LDBL_MANT_DIG == 53
155 /* This happens when doubles are 32-bits and long doubles are 64-bits. */
156 #define EXT_EXPBITS 11
157 #define EXT_FRACHBITS 20
158 #define EXT_FRACLBITS 32
159 #define __ieee_ext_field_type unsigned long
161 #elif LDBL_MANT_DIG == 64
162 #define EXT_EXPBITS 15
163 #define EXT_FRACHBITS 32
164 #define EXT_FRACLBITS 32
165 #define __ieee_ext_field_type unsigned int
167 #elif LDBL_MANT_DIG == 65
168 #define EXT_EXPBITS 15
169 #define EXT_FRACHBITS 32
170 #define EXT_FRACLBITS 32
171 #define __ieee_ext_field_type unsigned int
173 #elif LDBL_MANT_DIG == 112
174 #define EXT_EXPBITS 15
175 #define EXT_FRACHBITS 48
176 #define EXT_FRACLBITS 64
177 #define __ieee_ext_field_type unsigned long long
179 #elif LDBL_MANT_DIG == 113
180 #define EXT_EXPBITS 15
181 #define EXT_FRACHBITS 48
182 #define EXT_FRACLBITS 64
183 #define __ieee_ext_field_type unsigned long long
185 #else
186 #error Unsupported value for LDBL_MANT_DIG
187 #endif
189 #define EXT_EXP_INFNAN ((1 << EXT_EXPBITS) - 1) /* 32767 */
190 #define EXT_EXP_BIAS ((1 << (EXT_EXPBITS - 1)) - 1) /* 16383 */
191 #define EXT_FRACBITS (EXT_FRACLBITS + EXT_FRACHBITS)
193 typedef struct ieee_ext
195 __ieee_ext_field_type ext_fracl : EXT_FRACLBITS;
196 __ieee_ext_field_type ext_frach : EXT_FRACHBITS;
197 __ieee_ext_field_type ext_exp : EXT_EXPBITS;
198 __ieee_ext_field_type ext_sign : 1;
199 } ieee_ext;
201 typedef union ieee_ext_u
203 long double extu_ld;
204 struct ieee_ext extu_ext;
205 } ieee_ext_u;
207 #endif /* ! _LDBL_EQ_DBL */
210 /* FLOATING ROUNDING */
212 typedef int fp_rnd;
213 #define FP_RN 0 /* Round to nearest */
214 #define FP_RM 1 /* Round down */
215 #define FP_RP 2 /* Round up */
216 #define FP_RZ 3 /* Round to zero (trunate) */
218 fp_rnd fpgetround (void);
219 fp_rnd fpsetround (fp_rnd);
221 /* EXCEPTIONS */
223 typedef int fp_except;
224 #define FP_X_INV 0x10 /* Invalid operation */
225 #define FP_X_DX 0x80 /* Divide by zero */
226 #define FP_X_OFL 0x04 /* Overflow exception */
227 #define FP_X_UFL 0x02 /* Underflow exception */
228 #define FP_X_IMP 0x01 /* imprecise exception */
230 fp_except fpgetmask (void);
231 fp_except fpsetmask (fp_except);
232 fp_except fpgetsticky (void);
233 fp_except fpsetsticky (fp_except);
235 /* INTEGER ROUNDING */
237 typedef int fp_rdi;
238 #define FP_RDI_TOZ 0 /* Round to Zero */
239 #define FP_RDI_RD 1 /* Follow float mode */
241 fp_rdi fpgetroundtoi (void);
242 fp_rdi fpsetroundtoi (fp_rdi);
244 #define __IEEE_DBL_EXPBIAS 1023
245 #define __IEEE_FLT_EXPBIAS 127
247 #define __IEEE_DBL_EXPLEN 11
248 #define __IEEE_FLT_EXPLEN 8
251 #define __IEEE_DBL_FRACLEN (64 - (__IEEE_DBL_EXPLEN + 1))
252 #define __IEEE_FLT_FRACLEN (32 - (__IEEE_FLT_EXPLEN + 1))
254 #define __IEEE_DBL_MAXPOWTWO ((double)(1L << 32 - 2) * (1L << (32-11) - 32 + 1))
255 #define __IEEE_FLT_MAXPOWTWO ((float)(1L << (32-8) - 1))
257 #define __IEEE_DBL_NAN_EXP 0x7ff
258 #define __IEEE_FLT_NAN_EXP 0xff
260 #ifdef __ieeefp_isnanf
261 #define isnanf(x) __ieeefp_isnanf(x)
262 #endif
264 #ifdef __ieeefp_isinff
265 #define isinff(x) __ieeefp_isinff(x)
266 #endif
268 #ifdef __ieeefp_finitef
269 #define finitef(x) __ieeefp_finitef(x)
270 #endif
272 #ifdef _DOUBLE_IS_32BITS
273 #undef __IEEE_DBL_EXPBIAS
274 #define __IEEE_DBL_EXPBIAS __IEEE_FLT_EXPBIAS
276 #undef __IEEE_DBL_EXPLEN
277 #define __IEEE_DBL_EXPLEN __IEEE_FLT_EXPLEN
279 #undef __IEEE_DBL_FRACLEN
280 #define __IEEE_DBL_FRACLEN __IEEE_FLT_FRACLEN
282 #undef __IEEE_DBL_MAXPOWTWO
283 #define __IEEE_DBL_MAXPOWTWO __IEEE_FLT_MAXPOWTWO
285 #undef __IEEE_DBL_NAN_EXP
286 #define __IEEE_DBL_NAN_EXP __IEEE_FLT_NAN_EXP
288 #undef __ieee_double_shape_type
289 #define __ieee_double_shape_type __ieee_float_shape_type
291 #endif /* _DOUBLE_IS_32BITS */
293 _END_STD_C
295 #endif /* _IEEE_FP_H_ */