OLD | NEW |
1 /**************************************************************** | 1 /**************************************************************** |
2 * | 2 * |
3 * The author of this software is David M. Gay. | 3 * The author of this software is David M. Gay. |
4 * | 4 * |
5 * Copyright (c) 1991, 2000, 2001 by Lucent Technologies. | 5 * Copyright (c) 1991, 2000, 2001 by Lucent Technologies. |
6 * | 6 * |
7 * Permission to use, copy, modify, and distribute this software for any | 7 * Permission to use, copy, modify, and distribute this software for any |
8 * purpose without fee is hereby granted, provided that this entire notice | 8 * purpose without fee is hereby granted, provided that this entire notice |
9 * is included in all copies of any software which is or includes a copy | 9 * is included in all copies of any software which is or includes a copy |
10 * or modification of this software and in all copies of the supporting | 10 * or modification of this software and in all copies of the supporting |
(...skipping 252 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
263 #define CONST const | 263 #define CONST const |
264 #endif | 264 #endif |
265 #endif | 265 #endif |
266 | 266 |
267 #if defined(IEEE_8087) + defined(IEEE_MC68k) + defined(VAX) + defined(IBM) != 1 | 267 #if defined(IEEE_8087) + defined(IEEE_MC68k) + defined(VAX) + defined(IBM) != 1 |
268 Exactly one of IEEE_8087, IEEE_MC68k, VAX, or IBM should be defined. | 268 Exactly one of IEEE_8087, IEEE_MC68k, VAX, or IBM should be defined. |
269 #endif | 269 #endif |
270 | 270 |
271 typedef union { double d; ULong L[2]; } U; | 271 typedef union { double d; ULong L[2]; } U; |
272 | 272 |
273 #ifdef YES_ALIAS | |
274 #define dval(x) x | |
275 #ifdef IEEE_8087 | 273 #ifdef IEEE_8087 |
276 #define word0(x) ((ULong *)&x)[1] | 274 #define word0(x) (x).L[1] |
277 #define word1(x) ((ULong *)&x)[0] | 275 #define word1(x) (x).L[0] |
278 #else | 276 #else |
279 #define word0(x) ((ULong *)&x)[0] | 277 #define word0(x) (x).L[0] |
280 #define word1(x) ((ULong *)&x)[1] | 278 #define word1(x) (x).L[1] |
281 #endif | 279 #endif |
282 #else | 280 #define dval(x) (x).d |
283 #ifdef IEEE_8087 | |
284 #define word0(x) ((U*)&x)->L[1] | |
285 #define word1(x) ((U*)&x)->L[0] | |
286 #else | |
287 #define word0(x) ((U*)&x)->L[0] | |
288 #define word1(x) ((U*)&x)->L[1] | |
289 #endif | |
290 #define dval(x) ((U*)&x)->d | |
291 #endif | |
292 | 281 |
293 /* The following definition of Storeinc is appropriate for MIPS processors. | 282 /* The following definition of Storeinc is appropriate for MIPS processors. |
294 * An alternative that might be better on some machines is | 283 * An alternative that might be better on some machines is |
295 * #define Storeinc(a,b,c) (*a++ = b << 16 | c & 0xffff) | 284 * #define Storeinc(a,b,c) (*a++ = b << 16 | c & 0xffff) |
296 */ | 285 */ |
297 #if defined(IEEE_8087) + defined(VAX) | 286 #if defined(IEEE_8087) + defined(VAX) |
298 #define Storeinc(a,b,c) (((unsigned short *)a)[1] = (unsigned short)b, \ | 287 #define Storeinc(a,b,c) (((unsigned short *)a)[1] = (unsigned short)b, \ |
299 ((unsigned short *)a)[0] = (unsigned short)c, a++) | 288 ((unsigned short *)a)[0] = (unsigned short)c, a++) |
300 #else | 289 #else |
301 #define Storeinc(a,b,c) (((unsigned short *)a)[0] = (unsigned short)b, \ | 290 #define Storeinc(a,b,c) (((unsigned short *)a)[0] = (unsigned short)b, \ |
(...skipping 799 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1101 #endif | 1090 #endif |
1102 while(!*--xc) | 1091 while(!*--xc) |
1103 wa--; | 1092 wa--; |
1104 c->wds = wa; | 1093 c->wds = wa; |
1105 return c; | 1094 return c; |
1106 } | 1095 } |
1107 | 1096 |
1108 static double | 1097 static double |
1109 ulp | 1098 ulp |
1110 #ifdef KR_headers | 1099 #ifdef KR_headers |
1111 » (x) double x; | 1100 » (dx) double dx; |
1112 #else | 1101 #else |
1113 » (double x) | 1102 » (double dx) |
1114 #endif | 1103 #endif |
1115 { | 1104 { |
1116 register Long L; | 1105 register Long L; |
1117 » double a; | 1106 U x, a; |
| 1107 |
| 1108 dval(x) = dx; |
1118 | 1109 |
1119 L = (word0(x) & Exp_mask) - (P-1)*Exp_msk1; | 1110 L = (word0(x) & Exp_mask) - (P-1)*Exp_msk1; |
1120 #ifndef Avoid_Underflow | 1111 #ifndef Avoid_Underflow |
1121 #ifndef Sudden_Underflow | 1112 #ifndef Sudden_Underflow |
1122 if (L > 0) { | 1113 if (L > 0) { |
1123 #endif | 1114 #endif |
1124 #endif | 1115 #endif |
1125 #ifdef IBM | 1116 #ifdef IBM |
1126 L |= Exp_msk1 >> 4; | 1117 L |= Exp_msk1 >> 4; |
1127 #endif | 1118 #endif |
(...skipping 22 matching lines...) Expand all Loading... |
1150 static double | 1141 static double |
1151 b2d | 1142 b2d |
1152 #ifdef KR_headers | 1143 #ifdef KR_headers |
1153 (a, e) Bigint *a; int *e; | 1144 (a, e) Bigint *a; int *e; |
1154 #else | 1145 #else |
1155 (Bigint *a, int *e) | 1146 (Bigint *a, int *e) |
1156 #endif | 1147 #endif |
1157 { | 1148 { |
1158 ULong *xa, *xa0, w, y, z; | 1149 ULong *xa, *xa0, w, y, z; |
1159 int k; | 1150 int k; |
1160 » double d; | 1151 » U d; |
1161 #ifdef VAX | 1152 #ifdef VAX |
1162 ULong d0, d1; | 1153 ULong d0, d1; |
1163 #else | 1154 #else |
1164 #define d0 word0(d) | 1155 #define d0 word0(d) |
1165 #define d1 word1(d) | 1156 #define d1 word1(d) |
1166 #endif | 1157 #endif |
1167 | 1158 |
1168 xa0 = a->x; | 1159 xa0 = a->x; |
1169 xa = xa0 + a->wds; | 1160 xa = xa0 + a->wds; |
1170 y = *--xa; | 1161 y = *--xa; |
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1213 #else | 1204 #else |
1214 #undef d0 | 1205 #undef d0 |
1215 #undef d1 | 1206 #undef d1 |
1216 #endif | 1207 #endif |
1217 return dval(d); | 1208 return dval(d); |
1218 } | 1209 } |
1219 | 1210 |
1220 static Bigint * | 1211 static Bigint * |
1221 d2b | 1212 d2b |
1222 #ifdef KR_headers | 1213 #ifdef KR_headers |
1223 » (d, e, bits) double d; int *e, *bits; | 1214 » (dd, e, bits) double dd; int *e, *bits; |
1224 #else | 1215 #else |
1225 » (double d, int *e, int *bits) | 1216 » (double dd, int *e, int *bits) |
1226 #endif | 1217 #endif |
1227 { | 1218 { |
1228 Bigint *b; | 1219 Bigint *b; |
1229 int de, k; | 1220 int de, k; |
1230 ULong *x, y, z; | 1221 ULong *x, y, z; |
1231 #ifndef Sudden_Underflow | 1222 #ifndef Sudden_Underflow |
1232 int i; | 1223 int i; |
1233 #endif | 1224 #endif |
1234 #ifdef VAX | 1225 #ifdef VAX |
1235 ULong d0, d1; | 1226 ULong d0, d1; |
1236 d0 = word0(d) >> 16 | word0(d) << 16; | 1227 d0 = word0(d) >> 16 | word0(d) << 16; |
1237 d1 = word1(d) >> 16 | word1(d) << 16; | 1228 d1 = word1(d) >> 16 | word1(d) << 16; |
1238 #else | 1229 #else |
| 1230 U d; |
| 1231 dval(d) = dd; |
1239 #define d0 word0(d) | 1232 #define d0 word0(d) |
1240 #define d1 word1(d) | 1233 #define d1 word1(d) |
1241 #endif | 1234 #endif |
1242 | 1235 |
1243 #ifdef Pack_32 | 1236 #ifdef Pack_32 |
1244 b = Balloc(1); | 1237 b = Balloc(1); |
1245 #else | 1238 #else |
1246 b = Balloc(2); | 1239 b = Balloc(2); |
1247 #endif | 1240 #endif |
1248 x = b->x; | 1241 x = b->x; |
(...skipping 112 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1361 #undef d1 | 1354 #undef d1 |
1362 | 1355 |
1363 static double | 1356 static double |
1364 ratio | 1357 ratio |
1365 #ifdef KR_headers | 1358 #ifdef KR_headers |
1366 (a, b) Bigint *a, *b; | 1359 (a, b) Bigint *a, *b; |
1367 #else | 1360 #else |
1368 (Bigint *a, Bigint *b) | 1361 (Bigint *a, Bigint *b) |
1369 #endif | 1362 #endif |
1370 { | 1363 { |
1371 » double da, db; | 1364 » U da, db; |
1372 int k, ka, kb; | 1365 int k, ka, kb; |
1373 | 1366 |
1374 dval(da) = b2d(a, &ka); | 1367 dval(da) = b2d(a, &ka); |
1375 dval(db) = b2d(b, &kb); | 1368 dval(db) = b2d(b, &kb); |
1376 #ifdef Pack_32 | 1369 #ifdef Pack_32 |
1377 k = ka - kb + 32*(a->wds - b->wds); | 1370 k = ka - kb + 32*(a->wds - b->wds); |
1378 #else | 1371 #else |
1379 k = ka - kb + 16*(a->wds - b->wds); | 1372 k = ka - kb + 16*(a->wds - b->wds); |
1380 #endif | 1373 #endif |
1381 #ifdef IBM | 1374 #ifdef IBM |
(...skipping 153 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1535 #else | 1528 #else |
1536 (CONST char *s00, char **se) | 1529 (CONST char *s00, char **se) |
1537 #endif | 1530 #endif |
1538 { | 1531 { |
1539 #ifdef Avoid_Underflow | 1532 #ifdef Avoid_Underflow |
1540 int scale; | 1533 int scale; |
1541 #endif | 1534 #endif |
1542 int bb2, bb5, bbe, bd2, bd5, bbbits, bs2, c, dsign, | 1535 int bb2, bb5, bbe, bd2, bd5, bbbits, bs2, c, dsign, |
1543 e, e1, esign, i, j, k, nd, nd0, nf, nz, nz0, sign; | 1536 e, e1, esign, i, j, k, nd, nd0, nf, nz, nz0, sign; |
1544 CONST char *s, *s0, *s1; | 1537 CONST char *s, *s0, *s1; |
1545 » double aadj, aadj1, adj, rv, rv0; | 1538 double aadj; |
| 1539 » U aadj1, adj, rv, rv0; |
1546 Long L; | 1540 Long L; |
1547 ULong y, z; | 1541 ULong y, z; |
1548 Bigint *bb = NULL, *bb1, *bd = NULL, *bd0, *bs = NULL, *delta = NULL; | 1542 Bigint *bb = NULL, *bb1, *bd = NULL, *bd0, *bs = NULL, *delta = NULL; |
1549 #ifdef SET_INEXACT | 1543 #ifdef SET_INEXACT |
1550 int inexact, oldinexact; | 1544 int inexact, oldinexact; |
1551 #endif | 1545 #endif |
1552 #ifdef Honor_FLT_ROUNDS | 1546 #ifdef Honor_FLT_ROUNDS |
1553 int rounding; | 1547 int rounding; |
1554 #endif | 1548 #endif |
1555 #ifdef USE_LOCALE | 1549 #ifdef USE_LOCALE |
(...skipping 479 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2035 /* Error is less than an ulp */ | 2029 /* Error is less than an ulp */ |
2036 if (!delta->x[0] && delta->wds <= 1) { | 2030 if (!delta->x[0] && delta->wds <= 1) { |
2037 /* exact */ | 2031 /* exact */ |
2038 #ifdef SET_INEXACT | 2032 #ifdef SET_INEXACT |
2039 inexact = 0; | 2033 inexact = 0; |
2040 #endif | 2034 #endif |
2041 break; | 2035 break; |
2042 } | 2036 } |
2043 if (rounding) { | 2037 if (rounding) { |
2044 if (dsign) { | 2038 if (dsign) { |
2045 » » » » » » adj = 1.; | 2039 » » » » » » dval(adj) = 1.; |
2046 goto apply_adj; | 2040 goto apply_adj; |
2047 } | 2041 } |
2048 } | 2042 } |
2049 else if (!dsign) { | 2043 else if (!dsign) { |
2050 » » » » » adj = -1.; | 2044 » » » » » dval(adj) = -1.; |
2051 if (!word1(rv) | 2045 if (!word1(rv) |
2052 && !(word0(rv) & Frac_mask)) { | 2046 && !(word0(rv) & Frac_mask)) { |
2053 y = word0(rv) & Exp_mask; | 2047 y = word0(rv) & Exp_mask; |
2054 #ifdef Avoid_Underflow | 2048 #ifdef Avoid_Underflow |
2055 if (!scale || y > 2*P*Exp_msk1) | 2049 if (!scale || y > 2*P*Exp_msk1) |
2056 #else | 2050 #else |
2057 if (y) | 2051 if (y) |
2058 #endif | 2052 #endif |
2059 { | 2053 { |
2060 delta = lshift(delta,Log2P); | 2054 delta = lshift(delta,Log2P); |
2061 if (cmp(delta, bs) <= 0) | 2055 if (cmp(delta, bs) <= 0) |
2062 » » » » » » » adj = -0.5; | 2056 » » » » » » » dval(adj) = -0.5; |
2063 } | 2057 } |
2064 } | 2058 } |
2065 apply_adj: | 2059 apply_adj: |
2066 #ifdef Avoid_Underflow | 2060 #ifdef Avoid_Underflow |
2067 if (scale && (y = word0(rv) & Exp_mask) | 2061 if (scale && (y = word0(rv) & Exp_mask) |
2068 <= 2*P*Exp_msk1) | 2062 <= 2*P*Exp_msk1) |
2069 word0(adj) += (2*P+1)*Exp_msk1 - y; | 2063 word0(adj) += (2*P+1)*Exp_msk1 - y; |
2070 #else | 2064 #else |
2071 #ifdef Sudden_Underflow | 2065 #ifdef Sudden_Underflow |
2072 if ((word0(rv) & Exp_mask) <= | 2066 if ((word0(rv) & Exp_mask) <= |
2073 P*Exp_msk1) { | 2067 P*Exp_msk1) { |
2074 word0(rv) += P*Exp_msk1; | 2068 word0(rv) += P*Exp_msk1; |
2075 » » » » » » dval(rv) += adj*ulp(dval(rv)); | 2069 » » » » » » dval(rv) += dval(adj)*ulp(dval(r
v)); |
2076 word0(rv) -= P*Exp_msk1; | 2070 word0(rv) -= P*Exp_msk1; |
2077 } | 2071 } |
2078 else | 2072 else |
2079 #endif /*Sudden_Underflow*/ | 2073 #endif /*Sudden_Underflow*/ |
2080 #endif /*Avoid_Underflow*/ | 2074 #endif /*Avoid_Underflow*/ |
2081 » » » » » dval(rv) += adj*ulp(dval(rv)); | 2075 » » » » » dval(rv) += dval(adj)*ulp(dval(rv)); |
2082 } | 2076 } |
2083 break; | 2077 break; |
2084 } | 2078 } |
2085 » » » adj = ratio(delta, bs); | 2079 » » » dval(adj) = ratio(delta, bs); |
2086 » » » if (adj < 1.) | 2080 » » » if (dval(adj) < 1.) |
2087 » » » » adj = 1.; | 2081 » » » » dval(adj) = 1.; |
2088 » » » if (adj <= 0x7ffffffe) { | 2082 » » » if (dval(adj) <= 0x7ffffffe) { |
2089 /* adj = rounding ? ceil(adj) : floor(adj); */ | 2083 /* adj = rounding ? ceil(adj) : floor(adj); */ |
2090 » » » » y = adj; | 2084 » » » » y = dval(adj); |
2091 » » » » if (y != adj) { | 2085 » » » » if (y != dval(adj)) { |
2092 if (!((rounding>>1) ^ dsign)) | 2086 if (!((rounding>>1) ^ dsign)) |
2093 y++; | 2087 y++; |
2094 » » » » » adj = y; | 2088 » » » » » dval(adj) = y; |
2095 } | 2089 } |
2096 } | 2090 } |
2097 #ifdef Avoid_Underflow | 2091 #ifdef Avoid_Underflow |
2098 if (scale && (y = word0(rv) & Exp_mask) <= 2*P*Exp_msk1) | 2092 if (scale && (y = word0(rv) & Exp_mask) <= 2*P*Exp_msk1) |
2099 word0(adj) += (2*P+1)*Exp_msk1 - y; | 2093 word0(adj) += (2*P+1)*Exp_msk1 - y; |
2100 #else | 2094 #else |
2101 #ifdef Sudden_Underflow | 2095 #ifdef Sudden_Underflow |
2102 if ((word0(rv) & Exp_mask) <= P*Exp_msk1) { | 2096 if ((word0(rv) & Exp_mask) <= P*Exp_msk1) { |
2103 word0(rv) += P*Exp_msk1; | 2097 word0(rv) += P*Exp_msk1; |
2104 » » » » adj *= ulp(dval(rv)); | 2098 » » » » dval(adj) *= ulp(dval(rv)); |
2105 if (dsign) | 2099 if (dsign) |
2106 » » » » » dval(rv) += adj; | 2100 » » » » » dval(rv) += dval(adj); |
2107 else | 2101 else |
2108 » » » » » dval(rv) -= adj; | 2102 » » » » » dval(rv) -= dval(adj); |
2109 word0(rv) -= P*Exp_msk1; | 2103 word0(rv) -= P*Exp_msk1; |
2110 goto cont; | 2104 goto cont; |
2111 } | 2105 } |
2112 #endif /*Sudden_Underflow*/ | 2106 #endif /*Sudden_Underflow*/ |
2113 #endif /*Avoid_Underflow*/ | 2107 #endif /*Avoid_Underflow*/ |
2114 » » » adj *= ulp(dval(rv)); | 2108 » » » dval(adj) *= ulp(dval(rv)); |
2115 if (dsign) | 2109 if (dsign) |
2116 » » » » dval(rv) += adj; | 2110 » » » » dval(rv) += dval(adj); |
2117 else | 2111 else |
2118 » » » » dval(rv) -= adj; | 2112 » » » » dval(rv) -= dval(adj); |
2119 goto cont; | 2113 goto cont; |
2120 } | 2114 } |
2121 #endif /*Honor_FLT_ROUNDS*/ | 2115 #endif /*Honor_FLT_ROUNDS*/ |
2122 | 2116 |
2123 if (i < 0) { | 2117 if (i < 0) { |
2124 /* Error is less than half an ulp -- check for | 2118 /* Error is less than half an ulp -- check for |
2125 * special case of mantissa a power of two. | 2119 * special case of mantissa a power of two. |
2126 */ | 2120 */ |
2127 if (dsign || word1(rv) || word0(rv) & Bndry_mask | 2121 if (dsign || word1(rv) || word0(rv) & Bndry_mask |
2128 #ifdef IEEE_Arith | 2122 #ifdef IEEE_Arith |
(...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2230 #endif | 2224 #endif |
2231 } | 2225 } |
2232 #ifdef Avoid_Underflow | 2226 #ifdef Avoid_Underflow |
2233 dsign = 1 - dsign; | 2227 dsign = 1 - dsign; |
2234 #endif | 2228 #endif |
2235 #endif | 2229 #endif |
2236 break; | 2230 break; |
2237 } | 2231 } |
2238 if ((aadj = ratio(delta, bs)) <= 2.) { | 2232 if ((aadj = ratio(delta, bs)) <= 2.) { |
2239 if (dsign) | 2233 if (dsign) |
2240 » » » » aadj = aadj1 = 1.; | 2234 aadj = dval(aadj1) = 1.; |
2241 else if (word1(rv) || word0(rv) & Bndry_mask) { | 2235 else if (word1(rv) || word0(rv) & Bndry_mask) { |
2242 #ifndef Sudden_Underflow | 2236 #ifndef Sudden_Underflow |
2243 if (word1(rv) == Tiny1 && !word0(rv)) | 2237 if (word1(rv) == Tiny1 && !word0(rv)) |
2244 goto undfl; | 2238 goto undfl; |
2245 #endif | 2239 #endif |
2246 aadj = 1.; | 2240 aadj = 1.; |
2247 » » » » aadj1 = -1.; | 2241 » » » » dval(aadj1) = -1.; |
2248 } | 2242 } |
2249 else { | 2243 else { |
2250 /* special case -- power of FLT_RADIX to be */ | 2244 /* special case -- power of FLT_RADIX to be */ |
2251 /* rounded down... */ | 2245 /* rounded down... */ |
2252 | 2246 |
2253 if (aadj < 2./FLT_RADIX) | 2247 if (aadj < 2./FLT_RADIX) |
2254 aadj = 1./FLT_RADIX; | 2248 aadj = 1./FLT_RADIX; |
2255 else | 2249 else |
2256 aadj *= 0.5; | 2250 aadj *= 0.5; |
2257 » » » » aadj1 = -aadj; | 2251 » » » » dval(aadj1) = -aadj; |
2258 } | 2252 } |
2259 } | 2253 } |
2260 else { | 2254 else { |
2261 aadj *= 0.5; | 2255 aadj *= 0.5; |
2262 » » » aadj1 = dsign ? aadj : -aadj; | 2256 » » » dval(aadj1) = dsign ? aadj : -aadj; |
2263 #ifdef Check_FLT_ROUNDS | 2257 #ifdef Check_FLT_ROUNDS |
2264 switch(Rounding) { | 2258 switch(Rounding) { |
2265 case 2: /* towards +infinity */ | 2259 case 2: /* towards +infinity */ |
2266 » » » » » aadj1 -= 0.5; | 2260 » » » » » dval(aadj1) -= 0.5; |
2267 break; | 2261 break; |
2268 case 0: /* towards 0 */ | 2262 case 0: /* towards 0 */ |
2269 case 3: /* towards -infinity */ | 2263 case 3: /* towards -infinity */ |
2270 » » » » » aadj1 += 0.5; | 2264 » » » » » dval(aadj1) += 0.5; |
2271 } | 2265 } |
2272 #else | 2266 #else |
2273 if (Flt_Rounds == 0) | 2267 if (Flt_Rounds == 0) |
2274 » » » » aadj1 += 0.5; | 2268 » » » » dval(aadj1) += 0.5; |
2275 #endif /*Check_FLT_ROUNDS*/ | 2269 #endif /*Check_FLT_ROUNDS*/ |
2276 } | 2270 } |
2277 y = word0(rv) & Exp_mask; | 2271 y = word0(rv) & Exp_mask; |
2278 | 2272 |
2279 /* Check for overflow */ | 2273 /* Check for overflow */ |
2280 | 2274 |
2281 if (y == Exp_msk1*(DBL_MAX_EXP+Bias-1)) { | 2275 if (y == Exp_msk1*(DBL_MAX_EXP+Bias-1)) { |
2282 dval(rv0) = dval(rv); | 2276 dval(rv0) = dval(rv); |
2283 word0(rv) -= P*Exp_msk1; | 2277 word0(rv) -= P*Exp_msk1; |
2284 » » » adj = aadj1 * ulp(dval(rv)); | 2278 » » » dval(adj) = dval(aadj1) * ulp(dval(rv)); |
2285 » » » dval(rv) += adj; | 2279 » » » dval(rv) += dval(adj); |
2286 if ((word0(rv) & Exp_mask) >= | 2280 if ((word0(rv) & Exp_mask) >= |
2287 Exp_msk1*(DBL_MAX_EXP+Bias-P)) { | 2281 Exp_msk1*(DBL_MAX_EXP+Bias-P)) { |
2288 if (word0(rv0) == Big0 && word1(rv0) == Big1) | 2282 if (word0(rv0) == Big0 && word1(rv0) == Big1) |
2289 goto ovfl; | 2283 goto ovfl; |
2290 word0(rv) = Big0; | 2284 word0(rv) = Big0; |
2291 word1(rv) = Big1; | 2285 word1(rv) = Big1; |
2292 goto cont; | 2286 goto cont; |
2293 } | 2287 } |
2294 else | 2288 else |
2295 word0(rv) += P*Exp_msk1; | 2289 word0(rv) += P*Exp_msk1; |
2296 } | 2290 } |
2297 else { | 2291 else { |
2298 #ifdef Avoid_Underflow | 2292 #ifdef Avoid_Underflow |
2299 if (scale && y <= 2*P*Exp_msk1) { | 2293 if (scale && y <= 2*P*Exp_msk1) { |
2300 if (aadj <= 0x7fffffff) { | 2294 if (aadj <= 0x7fffffff) { |
2301 if ((z = aadj) <= 0) | 2295 if ((z = aadj) <= 0) |
2302 z = 1; | 2296 z = 1; |
2303 aadj = z; | 2297 aadj = z; |
2304 » » » » » aadj1 = dsign ? aadj : -aadj; | 2298 » » » » » dval(aadj1) = dsign ? aadj : -aadj; |
2305 } | 2299 } |
2306 word0(aadj1) += (2*P+1)*Exp_msk1 - y; | 2300 word0(aadj1) += (2*P+1)*Exp_msk1 - y; |
2307 } | 2301 } |
2308 » » » adj = aadj1 * ulp(dval(rv)); | 2302 » » » dval(adj) = dval(aadj1) * ulp(dval(rv)); |
2309 » » » dval(rv) += adj; | 2303 » » » dval(rv) += dval(adj); |
2310 #else | 2304 #else |
2311 #ifdef Sudden_Underflow | 2305 #ifdef Sudden_Underflow |
2312 if ((word0(rv) & Exp_mask) <= P*Exp_msk1) { | 2306 if ((word0(rv) & Exp_mask) <= P*Exp_msk1) { |
2313 dval(rv0) = dval(rv); | 2307 dval(rv0) = dval(rv); |
2314 word0(rv) += P*Exp_msk1; | 2308 word0(rv) += P*Exp_msk1; |
2315 » » » » adj = aadj1 * ulp(dval(rv)); | 2309 » » » » dval(adj) = dval(aadj1) * ulp(dval(rv)); |
2316 » » » » dval(rv) += adj; | 2310 » » » » dval(rv) += dval(adj); |
2317 #ifdef IBM | 2311 #ifdef IBM |
2318 if ((word0(rv) & Exp_mask) < P*Exp_msk1) | 2312 if ((word0(rv) & Exp_mask) < P*Exp_msk1) |
2319 #else | 2313 #else |
2320 if ((word0(rv) & Exp_mask) <= P*Exp_msk1) | 2314 if ((word0(rv) & Exp_mask) <= P*Exp_msk1) |
2321 #endif | 2315 #endif |
2322 { | 2316 { |
2323 if (word0(rv0) == Tiny0 | 2317 if (word0(rv0) == Tiny0 |
2324 && word1(rv0) == Tiny1) | 2318 && word1(rv0) == Tiny1) |
2325 goto undfl; | 2319 goto undfl; |
2326 word0(rv) = Tiny0; | 2320 word0(rv) = Tiny0; |
2327 word1(rv) = Tiny1; | 2321 word1(rv) = Tiny1; |
2328 goto cont; | 2322 goto cont; |
2329 } | 2323 } |
2330 else | 2324 else |
2331 word0(rv) -= P*Exp_msk1; | 2325 word0(rv) -= P*Exp_msk1; |
2332 } | 2326 } |
2333 else { | 2327 else { |
2334 » » » » adj = aadj1 * ulp(dval(rv)); | 2328 » » » » dval(adj) = dval(aadj1) * ulp(dval(rv)); |
2335 » » » » dval(rv) += adj; | 2329 » » » » dval(rv) += dval(adj); |
2336 } | 2330 } |
2337 #else /*Sudden_Underflow*/ | 2331 #else /*Sudden_Underflow*/ |
2338 /* Compute adj so that the IEEE rounding rules will | 2332 /* Compute adj so that the IEEE rounding rules will |
2339 * correctly round rv + adj in some half-way cases. | 2333 * correctly round rv + adj in some half-way cases. |
2340 * If rv * ulp(rv) is denormalized (i.e., | 2334 * If rv * ulp(rv) is denormalized (i.e., |
2341 * y <= (P-1)*Exp_msk1), we must adjust aadj to avoid | 2335 * y <= (P-1)*Exp_msk1), we must adjust aadj to avoid |
2342 * trouble from bits lost to denormalization; | 2336 * trouble from bits lost to denormalization; |
2343 * example: 1.2e-307 . | 2337 * example: 1.2e-307 . |
2344 */ | 2338 */ |
2345 if (y <= (P-1)*Exp_msk1 && aadj > 1.) { | 2339 if (y <= (P-1)*Exp_msk1 && aadj > 1.) { |
2346 » » » » aadj1 = (double)(int)(aadj + 0.5); | 2340 » » » » dval(aadj1) = (double)(int)(aadj + 0.5); |
2347 if (!dsign) | 2341 if (!dsign) |
2348 » » » » » aadj1 = -aadj1; | 2342 » » » » » dval(aadj1) = -dval(aadj1); |
2349 } | 2343 } |
2350 » » » adj = aadj1 * ulp(dval(rv)); | 2344 » » » dval(adj) = dval(aadj1) * ulp(dval(rv)); |
2351 » » » dval(rv) += adj; | 2345 » » » dval(rv) += dval(adj); |
2352 #endif /*Sudden_Underflow*/ | 2346 #endif /*Sudden_Underflow*/ |
2353 #endif /*Avoid_Underflow*/ | 2347 #endif /*Avoid_Underflow*/ |
2354 } | 2348 } |
2355 z = word0(rv) & Exp_mask; | 2349 z = word0(rv) & Exp_mask; |
2356 #ifndef SET_INEXACT | 2350 #ifndef SET_INEXACT |
2357 #ifdef Avoid_Underflow | 2351 #ifdef Avoid_Underflow |
2358 if (!scale) | 2352 if (!scale) |
2359 #endif | 2353 #endif |
2360 if (y == z) { | 2354 if (y == z) { |
2361 /* Can we stop now? */ | 2355 /* Can we stop now? */ |
(...skipping 269 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2631 * guarantee that the floating-point calculation has given | 2625 * guarantee that the floating-point calculation has given |
2632 * the correctly rounded result. For k requested digits and | 2626 * the correctly rounded result. For k requested digits and |
2633 * "uniformly" distributed input, the probability is | 2627 * "uniformly" distributed input, the probability is |
2634 * something like 10^(k-15) that we must resort to the Long | 2628 * something like 10^(k-15) that we must resort to the Long |
2635 * calculation. | 2629 * calculation. |
2636 */ | 2630 */ |
2637 | 2631 |
2638 char * | 2632 char * |
2639 dtoa | 2633 dtoa |
2640 #ifdef KR_headers | 2634 #ifdef KR_headers |
2641 » (d, mode, ndigits, decpt, sign, rve) | 2635 » (dd, mode, ndigits, decpt, sign, rve) |
2642 » double d; int mode, ndigits, *decpt, *sign; char **rve; | 2636 » double dd; int mode, ndigits, *decpt, *sign; char **rve; |
2643 #else | 2637 #else |
2644 » (double d, int mode, int ndigits, int *decpt, int *sign, char **rve) | 2638 » (double dd, int mode, int ndigits, int *decpt, int *sign, char **rve) |
2645 #endif | 2639 #endif |
2646 { | 2640 { |
2647 /* Arguments ndigits, decpt, sign are similar to those | 2641 /* Arguments ndigits, decpt, sign are similar to those |
2648 of ecvt and fcvt; trailing zeros are suppressed from | 2642 of ecvt and fcvt; trailing zeros are suppressed from |
2649 the returned string. If not null, *rve is set to point | 2643 the returned string. If not null, *rve is set to point |
2650 to the end of the return value. If d is +-Infinity or NaN, | 2644 to the end of the return value. If d is +-Infinity or NaN, |
2651 then *decpt is set to 9999. | 2645 then *decpt is set to 9999. |
2652 | 2646 |
2653 mode: | 2647 mode: |
2654 0 ==> shortest string that yields d when read in | 2648 0 ==> shortest string that yields d when read in |
(...skipping 25 matching lines...) Expand all Loading... |
2680 | 2674 |
2681 int bbits, b2, b5, be, dig, i, ieps, ilim, ilim0, ilim1, | 2675 int bbits, b2, b5, be, dig, i, ieps, ilim, ilim0, ilim1, |
2682 j, j1, k, k0, k_check, leftright, m2, m5, s2, s5, | 2676 j, j1, k, k0, k_check, leftright, m2, m5, s2, s5, |
2683 spec_case, try_quick, bias_round_up; | 2677 spec_case, try_quick, bias_round_up; |
2684 Long L; | 2678 Long L; |
2685 #ifndef Sudden_Underflow | 2679 #ifndef Sudden_Underflow |
2686 int denorm; | 2680 int denorm; |
2687 ULong x; | 2681 ULong x; |
2688 #endif | 2682 #endif |
2689 Bigint *b, *b1, *delta, *mlo, *mhi, *S; | 2683 Bigint *b, *b1, *delta, *mlo, *mhi, *S; |
2690 » double d2, ds, eps; | 2684 double ds; |
| 2685 » U d2, eps; |
2691 char *s, *s0; | 2686 char *s, *s0; |
2692 #ifdef Honor_FLT_ROUNDS | 2687 #ifdef Honor_FLT_ROUNDS |
2693 int rounding; | 2688 int rounding; |
2694 #endif | 2689 #endif |
2695 #ifdef SET_INEXACT | 2690 #ifdef SET_INEXACT |
2696 int inexact, oldinexact; | 2691 int inexact, oldinexact; |
2697 #endif | 2692 #endif |
| 2693 U d; |
| 2694 dval(d) = dd; |
2698 | 2695 |
2699 /* In mode 2 and 3 we bias rounding up when there are ties. */ | 2696 /* In mode 2 and 3 we bias rounding up when there are ties. */ |
2700 bias_round_up = mode == 2 || mode == 3; | 2697 bias_round_up = mode == 2 || mode == 3; |
2701 | 2698 |
2702 ilim = ilim1 = 0; /* to avoid Google3 compiler warnings */ | 2699 ilim = ilim1 = 0; /* to avoid Google3 compiler warnings */ |
2703 | 2700 |
2704 #ifndef MULTIPLE_THREADS | 2701 #ifndef MULTIPLE_THREADS |
2705 if (dtoa_result) { | 2702 if (dtoa_result) { |
2706 freedtoa(dtoa_result); | 2703 freedtoa(dtoa_result); |
2707 dtoa_result = 0; | 2704 dtoa_result = 0; |
(...skipping 617 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3325 Bfree(b); | 3322 Bfree(b); |
3326 *s = 0; | 3323 *s = 0; |
3327 *decpt = k + 1; | 3324 *decpt = k + 1; |
3328 if (rve) | 3325 if (rve) |
3329 *rve = s; | 3326 *rve = s; |
3330 return s0; | 3327 return s0; |
3331 } | 3328 } |
3332 #ifdef __cplusplus | 3329 #ifdef __cplusplus |
3333 } | 3330 } |
3334 #endif | 3331 #endif |
OLD | NEW |