1 #ifndef _IEEE_FP_H_ 2 #define _IEEE_FP_H_ 3 4 #include "_ansi.h" 5 6 #include <machine/ieeefp.h> 7 8 /* FIXME FIXME FIXME: 9 Neither of __ieee_{float,double}_shape_tape seem to be used anywhere 10 except in libm/test. If that is the case, please delete these from here. 11 If that is not the case, please insert documentation here describing why 12 they're needed. */ 13 14 #ifdef __IEEE_BIG_ENDIAN 15 16 typedef union 17 { 18 double value; 19 struct 20 { 21 unsigned int sign : 1; 22 unsigned int exponent: 11; 23 unsigned int fraction0:4; 24 unsigned int fraction1:16; 25 unsigned int fraction2:16; 26 unsigned int fraction3:16; 27 28 } number; 29 struct 30 { 31 unsigned int sign : 1; 32 unsigned int exponent: 11; 33 unsigned int quiet:1; 34 unsigned int function0:3; 35 unsigned int function1:16; 36 unsigned int function2:16; 37 unsigned int function3:16; 38 } nan; 39 struct 40 { 41 unsigned long msw; 42 unsigned long lsw; 43 } parts; 44 long aslong[2]; 45 } __ieee_double_shape_type; 46 47 #endif 48 49 #ifdef __IEEE_LITTLE_ENDIAN 50 51 typedef union 52 { 53 double value; 54 struct 55 { 56 #ifdef __SMALL_BITFIELDS 57 unsigned int fraction3:16; 58 unsigned int fraction2:16; 59 unsigned int fraction1:16; 60 unsigned int fraction0: 4; 61 #else 62 unsigned int fraction1:32; 63 unsigned int fraction0:20; 64 #endif 65 unsigned int exponent :11; 66 unsigned int sign : 1; 67 } number; 68 struct 69 { 70 #ifdef __SMALL_BITFIELDS 71 unsigned int function3:16; 72 unsigned int function2:16; 73 unsigned int function1:16; 74 unsigned int function0:3; 75 #else 76 unsigned int function1:32; 77 unsigned int function0:19; 78 #endif 79 unsigned int quiet:1; 80 unsigned int exponent: 11; 81 unsigned int sign : 1; 82 } nan; 83 struct 84 { 85 unsigned long lsw; 86 unsigned long msw; 87 } parts; 88 89 long aslong[2]; 90 91 } __ieee_double_shape_type; 92 93 #endif 94 95 #ifdef __IEEE_BIG_ENDIAN 96 97 typedef union 98 { 99 float value; 100 struct 101 { 102 unsigned int sign : 1; 103 unsigned int exponent: 8; 104 unsigned int fraction0: 7; 105 unsigned int fraction1: 16; 106 } number; 107 struct 108 { 109 unsigned int sign:1; 110 unsigned int exponent:8; 111 unsigned int quiet:1; 112 unsigned int function0:6; 113 unsigned int function1:16; 114 } nan; 115 long p1; 116 117 } __ieee_float_shape_type; 118 119 #endif 120 121 #ifdef __IEEE_LITTLE_ENDIAN 122 123 typedef union 124 { 125 float value; 126 struct 127 { 128 unsigned int fraction0: 7; 129 unsigned int fraction1: 16; 130 unsigned int exponent: 8; 131 unsigned int sign : 1; 132 } number; 133 struct 134 { 135 unsigned int function1:16; 136 unsigned int function0:6; 137 unsigned int quiet:1; 138 unsigned int exponent:8; 139 unsigned int sign:1; 140 } nan; 141 long p1; 142 143 } __ieee_float_shape_type; 144 145 #endif 146 147 148 149 150 151 /* FLOATING ROUNDING */ 152 153 typedef int fp_rnd; 154 #define FP_RN 0 /* Round to nearest */ 155 #define FP_RM 1 /* Round down */ 156 #define FP_RP 2 /* Round up */ 157 #define FP_RZ 3 /* Round to zero (trunate) */ 158 159 fp_rnd _EXFUN(fpgetround,(void)); 160 fp_rnd _EXFUN(fpsetround, (fp_rnd)); 161 162 /* EXCEPTIONS */ 163 164 typedef int fp_except; 165 #define FP_X_INV 0x10 /* Invalid operation */ 166 #define FP_X_DX 0x80 /* Divide by zero */ 167 #define FP_X_OFL 0x04 /* Overflow exception */ 168 #define FP_X_UFL 0x02 /* Underflow exception */ 169 #define FP_X_IMP 0x01 /* imprecise exception */ 170 171 fp_except _EXFUN(fpgetmask,(void)); 172 fp_except _EXFUN(fpsetmask,(fp_except)); 173 fp_except _EXFUN(fpgetsticky,(void)); 174 fp_except _EXFUN(fpsetsticky, (fp_except)); 175 176 /* INTEGER ROUNDING */ 177 178 typedef int fp_rdi; 179 #define FP_RDI_TOZ 0 /* Round to Zero */ 180 #define FP_RDI_RD 1 /* Follow float mode */ 181 182 fp_rdi _EXFUN(fpgetroundtoi,(void)); 183 fp_rdi _EXFUN(fpsetroundtoi,(fp_rdi)); 184 185 int _EXFUN(isnan, (double)); 186 int _EXFUN(isinf, (double)); 187 int _EXFUN(finite, (double)); 188 189 190 191 int _EXFUN(isnanf, (float)); 192 int _EXFUN(isinff, (float)); 193 int _EXFUN(finitef, (float)); 194 195 #define __IEEE_DBL_EXPBIAS 1023 196 #define __IEEE_FLT_EXPBIAS 127 197 198 #define __IEEE_DBL_EXPLEN 11 199 #define __IEEE_FLT_EXPLEN 8 200 201 202 #define __IEEE_DBL_FRACLEN (64 - (__IEEE_DBL_EXPLEN + 1)) 203 #define __IEEE_FLT_FRACLEN (32 - (__IEEE_FLT_EXPLEN + 1)) 204 205 #define __IEEE_DBL_MAXPOWTWO ((double)(1L << 32 - 2) * (1L << (32-11) - 32 + 1)) 206 #define __IEEE_FLT_MAXPOWTWO ((float)(1L << (32-8) - 1)) 207 208 #define __IEEE_DBL_NAN_EXP 0x7ff 209 #define __IEEE_FLT_NAN_EXP 0xff 210 211 212 #define isnanf(x) (((*(long *)&(x) & 0x7f800000L)==0x7f800000L) && \ 213 ((*(long *)&(x) & 0x007fffffL)!=0000000000L)) 214 215 #define isinff(x) (((*(long *)&(x) & 0x7f800000L)==0x7f800000L) && \ 216 ((*(long *)&(x) & 0x007fffffL)==0000000000L)) 217 218 #define finitef(x) (((*(long *)&(x) & 0x7f800000L)!=0x7f800000L)) 219 220 #ifdef _DOUBLE_IS_32BITS 221 #undef __IEEE_DBL_EXPBIAS 222 #define __IEEE_DBL_EXPBIAS __IEEE_FLT_EXPBIAS 223 224 #undef __IEEE_DBL_EXPLEN 225 #define __IEEE_DBL_EXPLEN __IEEE_FLT_EXPLEN 226 227 #undef __IEEE_DBL_FRACLEN 228 #define __IEEE_DBL_FRACLEN __IEEE_FLT_FRACLEN 229 230 #undef __IEEE_DBL_MAXPOWTWO 231 #define __IEEE_DBL_MAXPOWTWO __IEEE_FLT_MAXPOWTWO 232 233 #undef __IEEE_DBL_NAN_EXP 234 #define __IEEE_DBL_NAN_EXP __IEEE_FLT_NAN_EXP 235 236 #undef __ieee_double_shape_type 237 #define __ieee_double_shape_type __ieee_float_shape_type 238 239 #endif /* _DOUBLE_IS_32BITS */ 240 241 #endif /* _IEEE_FP_H_ */ |