Rev 6099 | Details | Compare with Previous | Last modification | View Log | RSS feed
Rev | Author | Line No. | Line |
---|---|---|---|
4349 | Serge | 1 | #ifndef _IEEE_FP_H_ |
2 | #define _IEEE_FP_H_ |
||
3 | |||
4 | #include "_ansi.h" |
||
5 | |||
6 | #include |
||
6099 | serge | 7 | #include |
4349 | Serge | 8 | |
9 | _BEGIN_STD_C |
||
10 | |||
11 | /* FIXME FIXME FIXME: |
||
6099 | serge | 12 | Neither of __ieee_{float,double}_shape_type seem to be used anywhere |
4349 | Serge | 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. */ |
||
16 | |||
17 | #ifdef __IEEE_BIG_ENDIAN |
||
18 | |||
19 | typedef union |
||
20 | { |
||
21 | double value; |
||
22 | struct |
||
23 | { |
||
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; |
||
30 | |||
31 | } number; |
||
32 | struct |
||
33 | { |
||
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 |
||
43 | { |
||
44 | unsigned long msw; |
||
45 | unsigned long lsw; |
||
46 | } parts; |
||
47 | long aslong[2]; |
||
48 | } __ieee_double_shape_type; |
||
49 | |||
6099 | serge | 50 | #elif defined __IEEE_LITTLE_ENDIAN |
4349 | Serge | 51 | |
52 | typedef union |
||
53 | { |
||
54 | double value; |
||
55 | struct |
||
56 | { |
||
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 |
||
70 | { |
||
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 |
||
85 | { |
||
86 | unsigned long lsw; |
||
87 | unsigned long msw; |
||
88 | } parts; |
||
89 | |||
90 | long aslong[2]; |
||
91 | |||
92 | } __ieee_double_shape_type; |
||
93 | |||
6099 | serge | 94 | #endif /* __IEEE_LITTLE_ENDIAN */ |
4349 | Serge | 95 | |
96 | #ifdef __IEEE_BIG_ENDIAN |
||
97 | |||
98 | typedef union |
||
99 | { |
||
100 | float value; |
||
101 | struct |
||
102 | { |
||
103 | unsigned int sign : 1; |
||
104 | unsigned int exponent: 8; |
||
105 | unsigned int fraction0: 7; |
||
106 | unsigned int fraction1: 16; |
||
107 | } number; |
||
108 | struct |
||
109 | { |
||
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; |
||
117 | |||
118 | } __ieee_float_shape_type; |
||
119 | |||
6099 | serge | 120 | #elif defined __IEEE_LITTLE_ENDIAN |
4349 | Serge | 121 | |
122 | typedef union |
||
123 | { |
||
124 | float value; |
||
125 | struct |
||
126 | { |
||
127 | unsigned int fraction0: 7; |
||
128 | unsigned int fraction1: 16; |
||
129 | unsigned int exponent: 8; |
||
130 | unsigned int sign : 1; |
||
131 | } number; |
||
132 | struct |
||
133 | { |
||
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; |
||
141 | |||
142 | } __ieee_float_shape_type; |
||
143 | |||
6099 | serge | 144 | #endif /* __IEEE_LITTLE_ENDIAN */ |
145 | |||
146 | #ifndef _LDBL_EQ_DBL |
||
147 | |||
148 | #ifndef LDBL_MANT_DIG |
||
149 | #error "LDBL_MANT_DIG not defined - should be found in float.h" |
||
150 | |||
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" |
||
153 | |||
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 |
||
160 | |||
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 |
||
166 | |||
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 |
||
172 | |||
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 |
||
178 | |||
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 |
||
184 | |||
185 | #else |
||
186 | #error Unsupported value for LDBL_MANT_DIG |
||
4349 | Serge | 187 | #endif |
188 | |||
6099 | serge | 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) |
||
4349 | Serge | 192 | |
6099 | serge | 193 | typedef struct ieee_ext |
194 | { |
||
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; |
||
4349 | Serge | 200 | |
6099 | serge | 201 | typedef union ieee_ext_u |
202 | { |
||
203 | long double extu_ld; |
||
204 | struct ieee_ext extu_ext; |
||
205 | } ieee_ext_u; |
||
4349 | Serge | 206 | |
6099 | serge | 207 | #endif /* ! _LDBL_EQ_DBL */ |
4349 | Serge | 208 | |
6099 | serge | 209 | |
4349 | Serge | 210 | /* FLOATING ROUNDING */ |
211 | |||
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) */ |
||
217 | |||
218 | fp_rnd _EXFUN(fpgetround,(void)); |
||
219 | fp_rnd _EXFUN(fpsetround, (fp_rnd)); |
||
220 | |||
221 | /* EXCEPTIONS */ |
||
222 | |||
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 */ |
||
229 | |||
230 | fp_except _EXFUN(fpgetmask,(void)); |
||
231 | fp_except _EXFUN(fpsetmask,(fp_except)); |
||
232 | fp_except _EXFUN(fpgetsticky,(void)); |
||
233 | fp_except _EXFUN(fpsetsticky, (fp_except)); |
||
234 | |||
235 | /* INTEGER ROUNDING */ |
||
236 | |||
237 | typedef int fp_rdi; |
||
238 | #define FP_RDI_TOZ 0 /* Round to Zero */ |
||
239 | #define FP_RDI_RD 1 /* Follow float mode */ |
||
240 | |||
241 | fp_rdi _EXFUN(fpgetroundtoi,(void)); |
||
242 | fp_rdi _EXFUN(fpsetroundtoi,(fp_rdi)); |
||
243 | |||
244 | #undef isnan |
||
245 | #undef isinf |
||
246 | |||
247 | int _EXFUN(isnan, (double)); |
||
248 | int _EXFUN(isinf, (double)); |
||
249 | int _EXFUN(finite, (double)); |
||
250 | |||
251 | |||
252 | |||
253 | int _EXFUN(isnanf, (float)); |
||
254 | int _EXFUN(isinff, (float)); |
||
255 | int _EXFUN(finitef, (float)); |
||
256 | |||
257 | #define __IEEE_DBL_EXPBIAS 1023 |
||
258 | #define __IEEE_FLT_EXPBIAS 127 |
||
259 | |||
260 | #define __IEEE_DBL_EXPLEN 11 |
||
261 | #define __IEEE_FLT_EXPLEN 8 |
||
262 | |||
263 | |||
264 | #define __IEEE_DBL_FRACLEN (64 - (__IEEE_DBL_EXPLEN + 1)) |
||
265 | #define __IEEE_FLT_FRACLEN (32 - (__IEEE_FLT_EXPLEN + 1)) |
||
266 | |||
267 | #define __IEEE_DBL_MAXPOWTWO ((double)(1L << 32 - 2) * (1L << (32-11) - 32 + 1)) |
||
268 | #define __IEEE_FLT_MAXPOWTWO ((float)(1L << (32-8) - 1)) |
||
269 | |||
270 | #define __IEEE_DBL_NAN_EXP 0x7ff |
||
271 | #define __IEEE_FLT_NAN_EXP 0xff |
||
272 | |||
6536 | serge | 273 | #ifdef __ieeefp_isnanf |
274 | #define isnanf(x) __ieeefp_isnanf(x) |
||
4349 | Serge | 275 | #endif |
276 | |||
6536 | serge | 277 | #ifdef __ieeefp_isinff |
278 | #define isinff(x) __ieeefp_isinff(x) |
||
4349 | Serge | 279 | #endif |
280 | |||
6536 | serge | 281 | #ifdef __ieeefp_finitef |
282 | #define finitef(x) __ieeefp_finitef(x) |
||
4349 | Serge | 283 | #endif |
284 | |||
285 | #ifdef _DOUBLE_IS_32BITS |
||
286 | #undef __IEEE_DBL_EXPBIAS |
||
287 | #define __IEEE_DBL_EXPBIAS __IEEE_FLT_EXPBIAS |
||
288 | |||
289 | #undef __IEEE_DBL_EXPLEN |
||
290 | #define __IEEE_DBL_EXPLEN __IEEE_FLT_EXPLEN |
||
291 | |||
292 | #undef __IEEE_DBL_FRACLEN |
||
293 | #define __IEEE_DBL_FRACLEN __IEEE_FLT_FRACLEN |
||
294 | |||
295 | #undef __IEEE_DBL_MAXPOWTWO |
||
296 | #define __IEEE_DBL_MAXPOWTWO __IEEE_FLT_MAXPOWTWO |
||
297 | |||
298 | #undef __IEEE_DBL_NAN_EXP |
||
299 | #define __IEEE_DBL_NAN_EXP __IEEE_FLT_NAN_EXP |
||
300 | |||
301 | #undef __ieee_double_shape_type |
||
302 | #define __ieee_double_shape_type __ieee_float_shape_type |
||
303 | |||
304 | #endif /* _DOUBLE_IS_32BITS */ |
||
305 | |||
306 | _END_STD_C |
||
307 | |||
308 | #endif /* _IEEE_FP_H_ */><>><>><>><>><> |