[444] | 1 | #ifndef _IEEE_FP_H_ |
---|
| 2 | #define _IEEE_FP_H_ |
---|
| 3 | |
---|
| 4 | #include "_ansi.h" |
---|
| 5 | |
---|
| 6 | #include <machine/ieeefp.h> |
---|
| 7 | #include <float.h> |
---|
| 8 | |
---|
| 9 | _BEGIN_STD_C |
---|
| 10 | |
---|
| 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. */ |
---|
| 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 | |
---|
| 50 | #elif defined __IEEE_LITTLE_ENDIAN |
---|
| 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 | |
---|
| 94 | #endif /* __IEEE_LITTLE_ENDIAN */ |
---|
| 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 | |
---|
| 120 | #elif defined __IEEE_LITTLE_ENDIAN |
---|
| 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 | |
---|
| 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 |
---|
| 187 | #endif |
---|
| 188 | |
---|
| 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) |
---|
| 192 | |
---|
| 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; |
---|
| 200 | |
---|
| 201 | typedef union ieee_ext_u |
---|
| 202 | { |
---|
| 203 | long double extu_ld; |
---|
| 204 | struct ieee_ext extu_ext; |
---|
| 205 | } ieee_ext_u; |
---|
| 206 | |
---|
| 207 | #endif /* ! _LDBL_EQ_DBL */ |
---|
| 208 | |
---|
| 209 | |
---|
| 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 fpgetround (void); |
---|
| 219 | fp_rnd 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 fpgetmask (void); |
---|
| 231 | fp_except fpsetmask (fp_except); |
---|
| 232 | fp_except fpgetsticky (void); |
---|
| 233 | fp_except 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 fpgetroundtoi (void); |
---|
| 242 | fp_rdi fpsetroundtoi (fp_rdi); |
---|
| 243 | |
---|
| 244 | #define __IEEE_DBL_EXPBIAS 1023 |
---|
| 245 | #define __IEEE_FLT_EXPBIAS 127 |
---|
| 246 | |
---|
| 247 | #define __IEEE_DBL_EXPLEN 11 |
---|
| 248 | #define __IEEE_FLT_EXPLEN 8 |
---|
| 249 | |
---|
| 250 | |
---|
| 251 | #define __IEEE_DBL_FRACLEN (64 - (__IEEE_DBL_EXPLEN + 1)) |
---|
| 252 | #define __IEEE_FLT_FRACLEN (32 - (__IEEE_FLT_EXPLEN + 1)) |
---|
| 253 | |
---|
| 254 | #define __IEEE_DBL_MAXPOWTWO ((double)(1L << 32 - 2) * (1L << (32-11) - 32 + 1)) |
---|
| 255 | #define __IEEE_FLT_MAXPOWTWO ((float)(1L << (32-8) - 1)) |
---|
| 256 | |
---|
| 257 | #define __IEEE_DBL_NAN_EXP 0x7ff |
---|
| 258 | #define __IEEE_FLT_NAN_EXP 0xff |
---|
| 259 | |
---|
| 260 | #ifdef __ieeefp_isnanf |
---|
| 261 | #define isnanf(x) __ieeefp_isnanf(x) |
---|
| 262 | #endif |
---|
| 263 | |
---|
| 264 | #ifdef __ieeefp_isinff |
---|
| 265 | #define isinff(x) __ieeefp_isinff(x) |
---|
| 266 | #endif |
---|
| 267 | |
---|
| 268 | #ifdef __ieeefp_finitef |
---|
| 269 | #define finitef(x) __ieeefp_finitef(x) |
---|
| 270 | #endif |
---|
| 271 | |
---|
| 272 | #ifdef _DOUBLE_IS_32BITS |
---|
| 273 | #undef __IEEE_DBL_EXPBIAS |
---|
| 274 | #define __IEEE_DBL_EXPBIAS __IEEE_FLT_EXPBIAS |
---|
| 275 | |
---|
| 276 | #undef __IEEE_DBL_EXPLEN |
---|
| 277 | #define __IEEE_DBL_EXPLEN __IEEE_FLT_EXPLEN |
---|
| 278 | |
---|
| 279 | #undef __IEEE_DBL_FRACLEN |
---|
| 280 | #define __IEEE_DBL_FRACLEN __IEEE_FLT_FRACLEN |
---|
| 281 | |
---|
| 282 | #undef __IEEE_DBL_MAXPOWTWO |
---|
| 283 | #define __IEEE_DBL_MAXPOWTWO __IEEE_FLT_MAXPOWTWO |
---|
| 284 | |
---|
| 285 | #undef __IEEE_DBL_NAN_EXP |
---|
| 286 | #define __IEEE_DBL_NAN_EXP __IEEE_FLT_NAN_EXP |
---|
| 287 | |
---|
| 288 | #undef __ieee_double_shape_type |
---|
| 289 | #define __ieee_double_shape_type __ieee_float_shape_type |
---|
| 290 | |
---|
| 291 | #endif /* _DOUBLE_IS_32BITS */ |
---|
| 292 | |
---|
| 293 | _END_STD_C |
---|
| 294 | |
---|
| 295 | #endif /* _IEEE_FP_H_ */ |
---|