6 #include <machine/ieeefp.h>
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
17 #ifdef __IEEE_BIG_ENDIAN
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;
34 unsigned int sign
: 1;
35 unsigned int exponent
: 11;
37 unsigned int function0
:3;
38 unsigned int function1
:16;
39 unsigned int function2
:16;
40 unsigned int function3
:16;
48 } __ieee_double_shape_type
;
50 #elif defined __IEEE_LITTLE_ENDIAN
57 #ifdef __SMALL_BITFIELDS
58 unsigned int fraction3
:16;
59 unsigned int fraction2
:16;
60 unsigned int fraction1
:16;
61 unsigned int fraction0
: 4;
63 unsigned int fraction1
:32;
64 unsigned int fraction0
:20;
66 unsigned int exponent
:11;
67 unsigned int sign
: 1;
71 #ifdef __SMALL_BITFIELDS
72 unsigned int function3
:16;
73 unsigned int function2
:16;
74 unsigned int function1
:16;
75 unsigned int function0
:3;
77 unsigned int function1
:32;
78 unsigned int function0
:19;
81 unsigned int exponent
: 11;
82 unsigned int sign
: 1;
92 } __ieee_double_shape_type
;
94 #endif /* __IEEE_LITTLE_ENDIAN */
96 #ifdef __IEEE_BIG_ENDIAN
103 unsigned int sign
: 1;
104 unsigned int exponent
: 8;
105 unsigned int fraction0
: 7;
106 unsigned int fraction1
: 16;
111 unsigned int exponent
:8;
112 unsigned int quiet
:1;
113 unsigned int function0
:6;
114 unsigned int function1
:16;
118 } __ieee_float_shape_type
;
120 #elif defined __IEEE_LITTLE_ENDIAN
127 unsigned int fraction0
: 7;
128 unsigned int fraction1
: 16;
129 unsigned int exponent
: 8;
130 unsigned int sign
: 1;
134 unsigned int function1
:16;
135 unsigned int function0
:6;
136 unsigned int quiet
:1;
137 unsigned int exponent
:8;
142 } __ieee_float_shape_type
;
144 #endif /* __IEEE_LITTLE_ENDIAN */
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
186 #error Unsupported value for LDBL_MANT_DIG
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;
201 typedef union ieee_ext_u
204 struct ieee_ext extu_ext
;
207 #endif /* ! _LDBL_EQ_DBL */
210 /* FLOATING ROUNDING */
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
);
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 */
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)
264 #ifdef __ieeefp_isinff
265 #define isinff(x) __ieeefp_isinff(x)
268 #ifdef __ieeefp_finitef
269 #define finitef(x) __ieeefp_finitef(x)
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 */
295 #endif /* _IEEE_FP_H_ */