Contiki 2.6
|
00001 /**************************************************************** 00002 * 00003 * The author of this software is David M. Gay. 00004 * 00005 * Copyright (c) 1991 by AT&T. 00006 * 00007 * Permission to use, copy, modify, and distribute this software for any 00008 * purpose without fee is hereby granted, provided that this entire notice 00009 * is included in all copies of any software which is or includes a copy 00010 * or modification of this software and in all copies of the supporting 00011 * documentation for such software. 00012 * 00013 * THIS SOFTWARE IS BEING PROVIDED "AS IS", WITHOUT ANY EXPRESS OR IMPLIED 00014 * WARRANTY. IN PARTICULAR, NEITHER THE AUTHOR NOR AT&T MAKES ANY 00015 * REPRESENTATION OR WARRANTY OF ANY KIND CONCERNING THE MERCHANTABILITY 00016 * OF THIS SOFTWARE OR ITS FITNESS FOR ANY PARTICULAR PURPOSE. 00017 * 00018 ***************************************************************/ 00019 00020 /* Please send bug reports to 00021 David M. Gay 00022 AT&T Bell Laboratories, Room 2C-463 00023 600 Mountain Avenue 00024 Murray Hill, NJ 07974-2070 00025 U.S.A. 00026 dmg@research.att.com or research!dmg 00027 */ 00028 00029 /* This header file is a modification of mprec.h that only contains floating 00030 point union code. */ 00031 00032 #include <ieeefp.h> 00033 #include <math.h> 00034 #include <float.h> 00035 #include <errno.h> 00036 #include <sys/config.h> 00037 00038 #ifdef __IEEE_LITTLE_ENDIAN 00039 #define IEEE_8087 00040 #endif 00041 00042 #ifdef __IEEE_BIG_ENDIAN 00043 #define IEEE_MC68k 00044 #endif 00045 00046 #ifdef __Z8000__ 00047 #define Just_16 00048 #endif 00049 00050 #ifdef Unsigned_Shifts 00051 #define Sign_Extend(a,b) if (b < 0) a |= (__uint32_t)0xffff0000; 00052 #else 00053 #define Sign_Extend(a,b) /*no-op*/ 00054 #endif 00055 00056 #if defined(IEEE_8087) + defined(IEEE_MC68k) + defined(VAX) + defined(IBM) != 1 00057 Exactly one of IEEE_8087, IEEE_MC68k, VAX, or IBM should be defined. 00058 #endif 00059 00060 #ifdef WANT_IO_LONG_DBL 00061 /* If we are going to examine or modify specific bits in a long double using 00062 the lword0 or lwordx macros, then we must wrap the long double inside 00063 a union. This is necessary to avoid undefined behavior according to 00064 the ANSI C spec. */ 00065 00066 #ifdef IEEE_8087 00067 #if LDBL_MANT_DIG == 24 00068 struct ldieee 00069 { 00070 unsigned manh:23; 00071 unsigned exp:8; 00072 unsigned sign:1; 00073 }; 00074 #elif LDBL_MANT_DIG == 53 00075 struct ldieee 00076 { 00077 unsigned manl:20; 00078 unsigned manh:32; 00079 unsigned exp:11; 00080 unsigned sign:1; 00081 }; 00082 #elif LDBL_MANT_DIG == 64 00083 struct ldieee 00084 { 00085 unsigned manl:32; 00086 unsigned manh:32; 00087 unsigned exp:15; 00088 unsigned sign:1; 00089 }; 00090 #elif LDBL_MANT_DIG > 64 00091 struct ldieee 00092 { 00093 unsigned manl3:16; 00094 unsigned manl2:32; 00095 unsigned manl:32; 00096 unsigned manh:32; 00097 unsigned exp:15; 00098 unsigned sign:1; 00099 }; 00100 #endif /* LDBL_MANT_DIG */ 00101 #else /* !IEEE_8087 */ 00102 #if LDBL_MANT_DIG == 24 00103 struct ldieee 00104 { 00105 unsigned sign:1; 00106 unsigned exp:8; 00107 unsigned manh:23; 00108 }; 00109 #elif LDBL_MANT_DIG == 53 00110 struct ldieee 00111 { 00112 unsigned sign:1; 00113 unsigned exp:11; 00114 unsigned manh:32; 00115 unsigned manl:20; 00116 }; 00117 #elif LDBL_MANT_DIG == 64 00118 struct ldieee 00119 { 00120 unsigned sign:1; 00121 unsigned exp:15; 00122 unsigned manh:32; 00123 unsigned manl:32; 00124 }; 00125 #elif LDBL_MANT_DIG > 64 00126 struct ldieee 00127 { 00128 unsigned sign:1; 00129 unsigned exp:15; 00130 unsigned manh:32; 00131 unsigned manl:32; 00132 unsigned manl2:32; 00133 unsigned manl3;16; 00134 }; 00135 #endif /* LDBL_MANT_DIG */ 00136 #endif /* !IEEE_8087 */ 00137 #endif /* WANT_IO_LONG_DBL */ 00138 00139 /* If we are going to examine or modify specific bits in a double using 00140 the word0 and/or word1 macros, then we must wrap the double inside 00141 a union. This is necessary to avoid undefined behavior according to 00142 the ANSI C spec. */ 00143 union double_union 00144 { 00145 double d; 00146 __uint32_t i[2]; 00147 }; 00148 00149 #ifdef IEEE_8087 00150 #define word0(x) (x.i[1]) 00151 #define word1(x) (x.i[0]) 00152 #else 00153 #define word0(x) (x.i[0]) 00154 #define word1(x) (x.i[1]) 00155 #endif 00156 00157 /* #define P DBL_MANT_DIG */ 00158 /* Ten_pmax = floor(P*log(2)/log(5)) */ 00159 /* Bletch = (highest power of 2 < DBL_MAX_10_EXP) / 16 */ 00160 /* Quick_max = floor((P-1)*log(FLT_RADIX)/log(10) - 1) */ 00161 /* Int_max = floor(P*log(FLT_RADIX)/log(10) - 1) */ 00162 00163 #if defined(IEEE_8087) + defined(IEEE_MC68k) 00164 #if defined (_DOUBLE_IS_32BITS) 00165 #define Exp_shift 23 00166 #define Exp_shift1 23 00167 #define Exp_msk1 ((__uint32_t)0x00800000L) 00168 #define Exp_msk11 ((__uint32_t)0x00800000L) 00169 #define Exp_mask ((__uint32_t)0x7f800000L) 00170 #define P 24 00171 #define Bias 127 00172 #if 0 00173 #define IEEE_Arith /* it is, but the code doesn't handle IEEE singles yet */ 00174 #endif 00175 #define Emin (-126) 00176 #define Exp_1 ((__uint32_t)0x3f800000L) 00177 #define Exp_11 ((__uint32_t)0x3f800000L) 00178 #define Ebits 8 00179 #define Frac_mask ((__uint32_t)0x007fffffL) 00180 #define Frac_mask1 ((__uint32_t)0x007fffffL) 00181 #define Ten_pmax 10 00182 #define Sign_bit ((__uint32_t)0x80000000L) 00183 #define Ten_pmax 10 00184 #define Bletch 2 00185 #define Bndry_mask ((__uint32_t)0x007fffffL) 00186 #define Bndry_mask1 ((__uint32_t)0x007fffffL) 00187 #define LSB 1 00188 #define Sign_bit ((__uint32_t)0x80000000L) 00189 #define Log2P 1 00190 #define Tiny0 0 00191 #define Tiny1 1 00192 #define Quick_max 5 00193 #define Int_max 6 00194 #define Infinite(x) (word0(x) == ((__uint32_t)0x7f800000L)) 00195 #undef word0 00196 #undef word1 00197 00198 #define word0(x) (x.i[0]) 00199 #define word1(x) 0 00200 #else 00201 00202 #define Exp_shift 20 00203 #define Exp_shift1 20 00204 #define Exp_msk1 ((__uint32_t)0x100000L) 00205 #define Exp_msk11 ((__uint32_t)0x100000L) 00206 #define Exp_mask ((__uint32_t)0x7ff00000L) 00207 #define P 53 00208 #define Bias 1023 00209 #define IEEE_Arith 00210 #define Emin (-1022) 00211 #define Exp_1 ((__uint32_t)0x3ff00000L) 00212 #define Exp_11 ((__uint32_t)0x3ff00000L) 00213 #define Ebits 11 00214 #define Frac_mask ((__uint32_t)0xfffffL) 00215 #define Frac_mask1 ((__uint32_t)0xfffffL) 00216 #define Ten_pmax 22 00217 #define Bletch 0x10 00218 #define Bndry_mask ((__uint32_t)0xfffffL) 00219 #define Bndry_mask1 ((__uint32_t)0xfffffL) 00220 #define LSB 1 00221 #define Sign_bit ((__uint32_t)0x80000000L) 00222 #define Log2P 1 00223 #define Tiny0 0 00224 #define Tiny1 1 00225 #define Quick_max 14 00226 #define Int_max 14 00227 #define Infinite(x) (word0(x) == ((__uint32_t)0x7ff00000L)) /* sufficient test for here */ 00228 #endif 00229 00230 #else 00231 #undef Sudden_Underflow 00232 #define Sudden_Underflow 00233 #ifdef IBM 00234 #define Exp_shift 24 00235 #define Exp_shift1 24 00236 #define Exp_msk1 ((__uint32_t)0x1000000L) 00237 #define Exp_msk11 ((__uint32_t)0x1000000L) 00238 #define Exp_mask ((__uint32_t)0x7f000000L) 00239 #define P 14 00240 #define Bias 65 00241 #define Exp_1 ((__uint32_t)0x41000000L) 00242 #define Exp_11 ((__uint32_t)0x41000000L) 00243 #define Ebits 8 /* exponent has 7 bits, but 8 is the right value in b2d */ 00244 #define Frac_mask ((__uint32_t)0xffffffL) 00245 #define Frac_mask1 ((__uint32_t)0xffffffL) 00246 #define Bletch 4 00247 #define Ten_pmax 22 00248 #define Bndry_mask ((__uint32_t)0xefffffL) 00249 #define Bndry_mask1 ((__uint32_t)0xffffffL) 00250 #define LSB 1 00251 #define Sign_bit ((__uint32_t)0x80000000L) 00252 #define Log2P 4 00253 #define Tiny0 ((__uint32_t)0x100000L) 00254 #define Tiny1 0 00255 #define Quick_max 14 00256 #define Int_max 15 00257 #else /* VAX */ 00258 #define Exp_shift 23 00259 #define Exp_shift1 7 00260 #define Exp_msk1 0x80 00261 #define Exp_msk11 ((__uint32_t)0x800000L) 00262 #define Exp_mask ((__uint32_t)0x7f80L) 00263 #define P 56 00264 #define Bias 129 00265 #define Exp_1 ((__uint32_t)0x40800000L) 00266 #define Exp_11 ((__uint32_t)0x4080L) 00267 #define Ebits 8 00268 #define Frac_mask ((__uint32_t)0x7fffffL) 00269 #define Frac_mask1 ((__uint32_t)0xffff007fL) 00270 #define Ten_pmax 24 00271 #define Bletch 2 00272 #define Bndry_mask ((__uint32_t)0xffff007fL) 00273 #define Bndry_mask1 ((__uint32_t)0xffff007fL) 00274 #define LSB ((__uint32_t)0x10000L) 00275 #define Sign_bit ((__uint32_t)0x8000L) 00276 #define Log2P 1 00277 #define Tiny0 0x80 00278 #define Tiny1 0 00279 #define Quick_max 15 00280 #define Int_max 15 00281 #endif 00282 #endif 00283 00284