Changeset 319 for clamav/trunk/libclamav/c++/llvm/lib/Support/APFloat.cpp
- Timestamp:
- Apr 19, 2011, 11:12:07 PM (14 years ago)
- Location:
- clamav/trunk
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
clamav/trunk ¶
-
Property svn:mergeinfo
set to
/clamav/vendor/0.97 merged eligible
-
Property svn:mergeinfo
set to
-
TabularUnified clamav/trunk/libclamav/c++/llvm/lib/Support/APFloat.cpp ¶
r189 r319 66 66 67 67 power * 815 / (351 * integerPartWidth) + 1 68 68 69 69 However, whilst the result may require only this many parts, 70 70 because we are multiplying two values to get it, the … … 101 101 102 102 r = c - '0'; 103 if (r <= 9)103 if (r <= 9) 104 104 return r; 105 105 106 106 r = c - 'A'; 107 if (r <= 5)107 if (r <= 5) 108 108 return r + 10; 109 109 110 110 r = c - 'a'; 111 if (r <= 5)111 if (r <= 5) 112 112 return r + 10; 113 113 … … 117 117 static inline void 118 118 assertArithmeticOK(const llvm::fltSemantics &semantics) { 119 assert(semantics.arithmeticOK 120 &&"Compile-time arithmetic does not support these semantics");119 assert(semantics.arithmeticOK && 120 "Compile-time arithmetic does not support these semantics"); 121 121 } 122 122 … … 154 154 if (absExponent >= overlargeExponent) { 155 155 absExponent = overlargeExponent; 156 p = end; /* outwit assert below */ 156 157 break; 157 158 } … … 180 181 181 182 negative = *p == '-'; 182 if (*p == '-' || *p == '+') {183 if (*p == '-' || *p == '+') { 183 184 p++; 184 185 assert(p != end && "Exponent has no digits"); … … 187 188 unsignedExponent = 0; 188 189 overflow = false; 189 for (; p != end; ++p) {190 for (; p != end; ++p) { 190 191 unsigned int value; 191 192 … … 194 195 195 196 unsignedExponent = unsignedExponent * 10 + value; 196 if (unsignedExponent > 65535)197 if (unsignedExponent > 65535) 197 198 overflow = true; 198 199 } 199 200 200 if (exponentAdjustment > 65535 || exponentAdjustment < -65536)201 if (exponentAdjustment > 65535 || exponentAdjustment < -65536) 201 202 overflow = true; 202 203 203 if (!overflow) {204 if (!overflow) { 204 205 exponent = unsignedExponent; 205 if (negative)206 if (negative) 206 207 exponent = -exponent; 207 208 exponent += exponentAdjustment; 208 if (exponent > 65535 || exponent < -65536)209 if (exponent > 65535 || exponent < -65536) 209 210 overflow = true; 210 211 } 211 212 212 if (overflow)213 if (overflow) 213 214 exponent = negative ? -65536: 65535; 214 215 … … 222 223 StringRef::iterator p = begin; 223 224 *dot = end; 224 while (*p == '0' && p != end)225 while (*p == '0' && p != end) 225 226 p++; 226 227 227 if (*p == '.') {228 if (*p == '.') { 228 229 *dot = p++; 229 230 230 231 assert(end - begin != 1 && "Significand has no digits"); 231 232 232 while (*p == '0' && p != end)233 while (*p == '0' && p != end) 233 234 p++; 234 235 } … … 324 325 /* If the first trailing digit isn't 0 or 8 we can work out the 325 326 fraction immediately. */ 326 if (digitValue > 8)327 if (digitValue > 8) 327 328 return lfMoreThanHalf; 328 else if (digitValue < 8 && digitValue > 0)329 else if (digitValue < 8 && digitValue > 0) 329 330 return lfLessThanHalf; 330 331 331 332 /* Otherwise we need to find the first non-zero digit. */ 332 while (*p == '0')333 while (*p == '0') 333 334 p++; 334 335 … … 339 340 /* If we ran off the end it is exactly zero or one-half, otherwise 340 341 a little more. */ 341 if (hexDigit == -1U)342 if (hexDigit == -1U) 342 343 return digitValue == 0 ? lfExactlyZero: lfExactlyHalf; 343 344 else … … 357 358 358 359 /* Note this is guaranteed true if bits == 0, or LSB == -1U. */ 359 if (bits <= lsb)360 if (bits <= lsb) 360 361 return lfExactlyZero; 361 if (bits == lsb + 1)362 if (bits == lsb + 1) 362 363 return lfExactlyHalf; 363 if (bits <= partCount * integerPartWidth364 &&APInt::tcExtractBit(parts, bits - 1))364 if (bits <= partCount * integerPartWidth && 365 APInt::tcExtractBit(parts, bits - 1)) 365 366 return lfMoreThanHalf; 366 367 … … 386 387 lostFraction lessSignificant) 387 388 { 388 if (lessSignificant != lfExactlyZero) {389 if (moreSignificant == lfExactlyZero)389 if (lessSignificant != lfExactlyZero) { 390 if (moreSignificant == lfExactlyZero) 390 391 moreSignificant = lfLessThanHalf; 391 else if (moreSignificant == lfExactlyHalf)392 else if (moreSignificant == lfExactlyHalf) 392 393 moreSignificant = lfMoreThanHalf; 393 394 } … … 469 470 integerPart pow5s[maxPowerOfFiveParts * 2 + 5]; 470 471 pow5s[0] = 78125 * 5; 471 472 472 473 unsigned int partsCount[16] = { 1 }; 473 474 integerPart scratch[maxPowerOfFiveParts], *p1, *p2, *pow5; … … 589 590 semantics = ourSemantics; 590 591 count = partCount(); 591 if (count > 1)592 if (count > 1) 592 593 significand.parts = new integerPart[count]; 593 594 } … … 596 597 APFloat::freeSignificand() 597 598 { 598 if (partCount() > 1)599 if (partCount() > 1) 599 600 delete [] significand.parts; 600 601 } … … 610 611 sign2 = rhs.sign2; 611 612 exponent2 = rhs.exponent2; 612 if (category == fcNormal || category == fcNaN)613 if (category == fcNormal || category == fcNaN) 613 614 copySignificand(rhs); 614 615 } … … 684 685 APFloat::operator=(const APFloat &rhs) 685 686 { 686 if (this != &rhs) {687 if (semantics != rhs.semantics) {687 if (this != &rhs) { 688 if (semantics != rhs.semantics) { 688 689 freeSignificand(); 689 690 initialize(rhs.semantics); … … 762 763 } 763 764 764 APFloat::APFloat(const fltSemantics &ourSemantics, const StringRef&text)765 APFloat::APFloat(const fltSemantics &ourSemantics, StringRef text) 765 766 { 766 767 assertArithmeticOK(ourSemantics); … … 882 883 newPartsCount = partCountForBits(precision * 2); 883 884 884 if (newPartsCount > 4)885 if (newPartsCount > 4) 885 886 fullSignificand = new integerPart[newPartsCount]; 886 887 else … … 897 898 exponent += rhs.exponent; 898 899 899 if (addend) {900 if (addend) { 900 901 Significand savedSignificand = significand; 901 902 const fltSemantics *savedSemantics = semantics; … … 906 907 /* Normalize our MSB. */ 907 908 extendedPrecision = precision + precision - 1; 908 if(omsb != extendedPrecision) 909 { 910 APInt::tcShiftLeft(fullSignificand, newPartsCount, 911 extendedPrecision - omsb); 912 exponent -= extendedPrecision - omsb; 913 } 909 if (omsb != extendedPrecision) { 910 APInt::tcShiftLeft(fullSignificand, newPartsCount, 911 extendedPrecision - omsb); 912 exponent -= extendedPrecision - omsb; 913 } 914 914 915 915 /* Create new semantics. */ … … 917 917 extendedSemantics.precision = extendedPrecision; 918 918 919 if (newPartsCount == 1)919 if (newPartsCount == 1) 920 920 significand.part = fullSignificand[0]; 921 921 else … … 929 929 930 930 /* Restore our state. */ 931 if (newPartsCount == 1)931 if (newPartsCount == 1) 932 932 fullSignificand[0] = significand.part; 933 933 significand = savedSignificand; … … 939 939 exponent -= (precision - 1); 940 940 941 if (omsb > precision) {941 if (omsb > precision) { 942 942 unsigned int bits, significantParts; 943 943 lostFraction lf; … … 952 952 APInt::tcAssign(lhsSignificand, fullSignificand, partsCount); 953 953 954 if (newPartsCount > 4)954 if (newPartsCount > 4) 955 955 delete [] fullSignificand; 956 956 … … 974 974 partsCount = partCount(); 975 975 976 if (partsCount > 2)976 if (partsCount > 2) 977 977 dividend = new integerPart[partsCount * 2]; 978 978 else … … 982 982 983 983 /* Copy the dividend and divisor as they will be modified in-place. */ 984 for (i = 0; i < partsCount; i++) {984 for (i = 0; i < partsCount; i++) { 985 985 dividend[i] = lhsSignificand[i]; 986 986 divisor[i] = rhsSignificand[i]; … … 994 994 /* Normalize the divisor. */ 995 995 bit = precision - APInt::tcMSB(divisor, partsCount) - 1; 996 if (bit) {996 if (bit) { 997 997 exponent += bit; 998 998 APInt::tcShiftLeft(divisor, partsCount, bit); … … 1001 1001 /* Normalize the dividend. */ 1002 1002 bit = precision - APInt::tcMSB(dividend, partsCount) - 1; 1003 if (bit) {1003 if (bit) { 1004 1004 exponent -= bit; 1005 1005 APInt::tcShiftLeft(dividend, partsCount, bit); … … 1009 1009 Incidentally, this means that the division loop below is 1010 1010 guaranteed to set the integer bit to one. */ 1011 if (APInt::tcCompare(dividend, divisor, partsCount) < 0) {1011 if (APInt::tcCompare(dividend, divisor, partsCount) < 0) { 1012 1012 exponent--; 1013 1013 APInt::tcShiftLeft(dividend, partsCount, 1); … … 1016 1016 1017 1017 /* Long division. */ 1018 for (bit = precision; bit; bit -= 1) {1019 if (APInt::tcCompare(dividend, divisor, partsCount) >= 0) {1018 for (bit = precision; bit; bit -= 1) { 1019 if (APInt::tcCompare(dividend, divisor, partsCount) >= 0) { 1020 1020 APInt::tcSubtract(dividend, divisor, 0, partsCount); 1021 1021 APInt::tcSetBit(lhsSignificand, bit - 1); … … 1028 1028 int cmp = APInt::tcCompare(dividend, divisor, partsCount); 1029 1029 1030 if (cmp > 0)1030 if (cmp > 0) 1031 1031 lost_fraction = lfMoreThanHalf; 1032 else if (cmp == 0)1032 else if (cmp == 0) 1033 1033 lost_fraction = lfExactlyHalf; 1034 else if (APInt::tcIsZero(dividend, partsCount))1034 else if (APInt::tcIsZero(dividend, partsCount)) 1035 1035 lost_fraction = lfExactlyZero; 1036 1036 else 1037 1037 lost_fraction = lfLessThanHalf; 1038 1038 1039 if (partsCount > 2)1039 if (partsCount > 2) 1040 1040 delete [] dividend; 1041 1041 … … 1073 1073 assert(bits < semantics->precision); 1074 1074 1075 if (bits) {1075 if (bits) { 1076 1076 unsigned int partsCount = partCount(); 1077 1077 … … 1096 1096 /* If exponents are equal, do an unsigned bignum comparison of the 1097 1097 significands. */ 1098 if (compare == 0)1098 if (compare == 0) 1099 1099 compare = APInt::tcCompare(significandParts(), rhs.significandParts(), 1100 1100 partCount()); 1101 1101 1102 if (compare > 0)1102 if (compare > 0) 1103 1103 return cmpGreaterThan; 1104 else if (compare < 0)1104 else if (compare < 0) 1105 1105 return cmpLessThan; 1106 1106 else … … 1114 1114 { 1115 1115 /* Infinity? */ 1116 if(rounding_mode == rmNearestTiesToEven 1117 || rounding_mode == rmNearestTiesToAway 1118 || (rounding_mode == rmTowardPositive && !sign) 1119 || (rounding_mode == rmTowardNegative && sign)) 1120 { 1121 category = fcInfinity; 1122 return (opStatus) (opOverflow | opInexact); 1123 } 1116 if (rounding_mode == rmNearestTiesToEven || 1117 rounding_mode == rmNearestTiesToAway || 1118 (rounding_mode == rmTowardPositive && !sign) || 1119 (rounding_mode == rmTowardNegative && sign)) { 1120 category = fcInfinity; 1121 return (opStatus) (opOverflow | opInexact); 1122 } 1124 1123 1125 1124 /* Otherwise we become the largest finite number. */ … … 1156 1155 1157 1156 case rmNearestTiesToEven: 1158 if (lost_fraction == lfMoreThanHalf)1157 if (lost_fraction == lfMoreThanHalf) 1159 1158 return true; 1160 1159 1161 1160 /* Our zeroes don't have a significand to test. */ 1162 if (lost_fraction == lfExactlyHalf && category != fcZero)1161 if (lost_fraction == lfExactlyHalf && category != fcZero) 1163 1162 return APInt::tcExtractBit(significandParts(), bit); 1164 1163 … … 1183 1182 int exponentChange; 1184 1183 1185 if (category != fcNormal)1184 if (category != fcNormal) 1186 1185 return opOK; 1187 1186 … … 1189 1188 omsb = significandMSB() + 1; 1190 1189 1191 if (omsb) {1190 if (omsb) { 1192 1191 /* OMSB is numbered from 1. We want to place it in the integer 1193 1192 bit numbered PRECISON if possible, with a compensating change in … … 1197 1196 /* If the resulting exponent is too high, overflow according to 1198 1197 the rounding mode. */ 1199 if (exponent + exponentChange > semantics->maxExponent)1198 if (exponent + exponentChange > semantics->maxExponent) 1200 1199 return handleOverflow(rounding_mode); 1201 1200 1202 1201 /* Subnormal numbers have exponent minExponent, and their MSB 1203 1202 is forced based on that. */ 1204 if (exponent + exponentChange < semantics->minExponent)1203 if (exponent + exponentChange < semantics->minExponent) 1205 1204 exponentChange = semantics->minExponent - exponent; 1206 1205 1207 1206 /* Shifting left is easy as we don't lose precision. */ 1208 if (exponentChange < 0) {1207 if (exponentChange < 0) { 1209 1208 assert(lost_fraction == lfExactlyZero); 1210 1209 … … 1214 1213 } 1215 1214 1216 if (exponentChange > 0) {1215 if (exponentChange > 0) { 1217 1216 lostFraction lf; 1218 1217 … … 1223 1222 1224 1223 /* Keep OMSB up-to-date. */ 1225 if (omsb > (unsigned) exponentChange)1224 if (omsb > (unsigned) exponentChange) 1226 1225 omsb -= exponentChange; 1227 1226 else … … 1235 1234 /* As specified in IEEE 754, since we do not trap we do not report 1236 1235 underflow for exact results. */ 1237 if (lost_fraction == lfExactlyZero) {1236 if (lost_fraction == lfExactlyZero) { 1238 1237 /* Canonicalize zeroes. */ 1239 if (omsb == 0)1238 if (omsb == 0) 1240 1239 category = fcZero; 1241 1240 … … 1244 1243 1245 1244 /* Increment the significand if we're rounding away from zero. */ 1246 if (roundAwayFromZero(rounding_mode, lost_fraction, 0)) {1247 if (omsb == 0)1245 if (roundAwayFromZero(rounding_mode, lost_fraction, 0)) { 1246 if (omsb == 0) 1248 1247 exponent = semantics->minExponent; 1249 1248 … … 1252 1251 1253 1252 /* Did the significand increment overflow? */ 1254 if (omsb == (unsigned) semantics->precision + 1) {1253 if (omsb == (unsigned) semantics->precision + 1) { 1255 1254 /* Renormalize by incrementing the exponent and shifting our 1256 1255 significand right one. However if we already have the 1257 1256 maximum exponent we overflow to infinity. */ 1258 if (exponent == semantics->maxExponent) {1257 if (exponent == semantics->maxExponent) { 1259 1258 category = fcInfinity; 1260 1259 … … 1270 1269 /* The normal case - we were and are not denormal, and any 1271 1270 significand increment above didn't overflow. */ 1272 if (omsb == semantics->precision)1271 if (omsb == semantics->precision) 1273 1272 return opInexact; 1274 1273 … … 1277 1276 1278 1277 /* Canonicalize zeroes. */ 1279 if (omsb == 0)1278 if (omsb == 0) 1280 1279 category = fcZero; 1281 1280 … … 1325 1324 /* Differently signed infinities can only be validly 1326 1325 subtracted. */ 1327 if (((sign ^ rhs.sign)!=0) != subtract) {1326 if (((sign ^ rhs.sign)!=0) != subtract) { 1328 1327 makeNaN(); 1329 1328 return opInvalidOp; … … 1353 1352 1354 1353 /* Subtraction is more subtle than one might naively expect. */ 1355 if (subtract) {1354 if (subtract) { 1356 1355 APFloat temp_rhs(rhs); 1357 1356 bool reverse; … … 1382 1381 /* Invert the lost fraction - it was on the RHS and 1383 1382 subtracted. */ 1384 if (lost_fraction == lfLessThanHalf)1383 if (lost_fraction == lfLessThanHalf) 1385 1384 lost_fraction = lfMoreThanHalf; 1386 else if (lost_fraction == lfMoreThanHalf)1385 else if (lost_fraction == lfMoreThanHalf) 1387 1386 lost_fraction = lfLessThanHalf; 1388 1387 … … 1391 1390 assert(!carry); 1392 1391 } else { 1393 if (bits > 0) {1392 if (bits > 0) { 1394 1393 APFloat temp_rhs(rhs); 1395 1394 … … 1562 1561 1563 1562 /* This return code means it was not a simple case. */ 1564 if (fs == opDivByZero) {1563 if (fs == opDivByZero) { 1565 1564 lostFraction lost_fraction; 1566 1565 … … 1575 1574 positive zero unless rounding to minus infinity, except that 1576 1575 adding two like-signed zeroes gives that zero. */ 1577 if (category == fcZero) {1578 if (rhs.category != fcZero || (sign == rhs.sign) == subtract)1576 if (category == fcZero) { 1577 if (rhs.category != fcZero || (sign == rhs.sign) == subtract) 1579 1578 sign = (rounding_mode == rmTowardNegative); 1580 1579 } … … 1607 1606 fs = multiplySpecials(rhs); 1608 1607 1609 if (category == fcNormal) {1608 if (category == fcNormal) { 1610 1609 lostFraction lost_fraction = multiplySignificand(rhs, 0); 1611 1610 fs = normalize(rounding_mode, lost_fraction); 1612 if (lost_fraction != lfExactlyZero)1611 if (lost_fraction != lfExactlyZero) 1613 1612 fs = (opStatus) (fs | opInexact); 1614 1613 } … … 1627 1626 fs = divideSpecials(rhs); 1628 1627 1629 if (category == fcNormal) {1628 if (category == fcNormal) { 1630 1629 lostFraction lost_fraction = divideSignificand(rhs); 1631 1630 fs = normalize(rounding_mode, lost_fraction); 1632 if (lost_fraction != lfExactlyZero)1631 if (lost_fraction != lfExactlyZero) 1633 1632 fs = (opStatus) (fs | opInexact); 1634 1633 } … … 1674 1673 } 1675 1674 1676 /* Normalized llvm frem (C fmod). 1675 /* Normalized llvm frem (C fmod). 1677 1676 This is not currently correct in all cases. */ 1678 1677 APFloat::opStatus … … 1731 1730 /* If and only if all arguments are normal do we need to do an 1732 1731 extended-precision calculation. */ 1733 if (category == fcNormal1734 && multiplicand.category == fcNormal1735 &&addend.category == fcNormal) {1732 if (category == fcNormal && 1733 multiplicand.category == fcNormal && 1734 addend.category == fcNormal) { 1736 1735 lostFraction lost_fraction; 1737 1736 1738 1737 lost_fraction = multiplySignificand(multiplicand, &addend); 1739 1738 fs = normalize(rounding_mode, lost_fraction); 1740 if (lost_fraction != lfExactlyZero)1739 if (lost_fraction != lfExactlyZero) 1741 1740 fs = (opStatus) (fs | opInexact); 1742 1741 … … 1744 1743 positive zero unless rounding to minus infinity, except that 1745 1744 adding two like-signed zeroes gives that zero. */ 1746 if (category == fcZero && sign != addend.sign)1745 if (category == fcZero && sign != addend.sign) 1747 1746 sign = (rounding_mode == rmTowardNegative); 1748 1747 } else { … … 1756 1755 If we need to do the addition we can do so with normal 1757 1756 precision. */ 1758 if (fs == opOK)1757 if (fs == opOK) 1759 1758 fs = addOrSubtract(addend, rounding_mode, false); 1760 1759 } … … 1788 1787 case convolve(fcInfinity, fcZero): 1789 1788 case convolve(fcNormal, fcZero): 1790 if (sign)1789 if (sign) 1791 1790 return cmpLessThan; 1792 1791 else … … 1796 1795 case convolve(fcZero, fcInfinity): 1797 1796 case convolve(fcZero, fcNormal): 1798 if (rhs.sign)1797 if (rhs.sign) 1799 1798 return cmpGreaterThan; 1800 1799 else … … 1802 1801 1803 1802 case convolve(fcInfinity, fcInfinity): 1804 if (sign == rhs.sign)1803 if (sign == rhs.sign) 1805 1804 return cmpEqual; 1806 else if (sign)1805 else if (sign) 1807 1806 return cmpLessThan; 1808 1807 else … … 1817 1816 1818 1817 /* Two normal numbers. Do they have the same sign? */ 1819 if (sign != rhs.sign) {1820 if (sign)1818 if (sign != rhs.sign) { 1819 if (sign) 1821 1820 result = cmpLessThan; 1822 1821 else … … 1826 1825 result = compareAbsoluteValue(rhs); 1827 1826 1828 if (sign) {1829 if (result == cmpLessThan)1827 if (sign) { 1828 if (result == cmpLessThan) 1830 1829 result = cmpGreaterThan; 1831 else if (result == cmpGreaterThan)1830 else if (result == cmpGreaterThan) 1832 1831 result = cmpLessThan; 1833 1832 } … … 1887 1886 } 1888 1887 1889 if (category == fcNormal) {1888 if (category == fcNormal) { 1890 1889 /* Re-interpret our bit-pattern. */ 1891 1890 exponent += toSemantics.precision - semantics->precision; … … 1912 1911 if (APInt::tcLSB(significandParts(), newPartCount) < ushift) 1913 1912 *losesInfo = true; 1914 if (oldSemantics == &APFloat::x87DoubleExtended && 1913 if (oldSemantics == &APFloat::x87DoubleExtended && 1915 1914 (!(*significandParts() & 0x8000000000000000ULL) || 1916 1915 !(*significandParts() & 0x4000000000000000ULL))) … … 1957 1956 1958 1957 /* Handle the three special cases first. */ 1959 if (category == fcInfinity || category == fcNaN)1958 if (category == fcInfinity || category == fcNaN) 1960 1959 return opInvalidOp; 1961 1960 1962 1961 dstPartsCount = partCountForBits(width); 1963 1962 1964 if (category == fcZero) {1963 if (category == fcZero) { 1965 1964 APInt::tcSet(parts, 0, dstPartsCount); 1966 1965 // Negative zero can't be represented as an int. … … 2005 2004 lost_fraction = lostFractionThroughTruncation(src, partCount(), 2006 2005 truncatedBits); 2007 if (lost_fraction != lfExactlyZero 2008 &&roundAwayFromZero(rounding_mode, lost_fraction, truncatedBits)) {2006 if (lost_fraction != lfExactlyZero && 2007 roundAwayFromZero(rounding_mode, lost_fraction, truncatedBits)) { 2009 2008 if (APInt::tcIncrement(parts, dstPartsCount)) 2010 2009 return opInvalidOp; /* Overflow. */ … … 2063 2062 opStatus fs; 2064 2063 2065 fs = convertToSignExtendedInteger(parts, width, isSigned, rounding_mode, 2064 fs = convertToSignExtendedInteger(parts, width, isSigned, rounding_mode, 2066 2065 isExact); 2067 2066 … … 2150 2149 2151 2150 assertArithmeticOK(*semantics); 2152 if (isSigned 2153 &&APInt::tcExtractBit(src, srcCount * integerPartWidth - 1)) {2151 if (isSigned && 2152 APInt::tcExtractBit(src, srcCount * integerPartWidth - 1)) { 2154 2153 integerPart *copy; 2155 2154 … … 2179 2178 2180 2179 sign = false; 2181 if (isSigned && APInt::tcExtractBit(parts, width - 1)) {2180 if (isSigned && APInt::tcExtractBit(parts, width - 1)) { 2182 2181 sign = true; 2183 2182 api = -api; … … 2188 2187 2189 2188 APFloat::opStatus 2190 APFloat::convertFromHexadecimalString(const StringRef &s, 2191 roundingMode rounding_mode) 2189 APFloat::convertFromHexadecimalString(StringRef s, roundingMode rounding_mode) 2192 2190 { 2193 2191 lostFraction lost_fraction = lfExactlyZero; … … 2210 2208 firstSignificantDigit = p; 2211 2209 2212 for (; p != end;) {2210 for (; p != end;) { 2213 2211 integerPart hex_value; 2214 2212 2215 if (*p == '.') {2213 if (*p == '.') { 2216 2214 assert(dot == end && "String contains multiple dots"); 2217 2215 dot = p++; … … 2222 2220 2223 2221 hex_value = hexDigitValue(*p); 2224 if (hex_value == -1U) {2222 if (hex_value == -1U) { 2225 2223 break; 2226 2224 } … … 2232 2230 } else { 2233 2231 /* Store the number whilst 4-bit nibbles remain. */ 2234 if (bitPos) {2232 if (bitPos) { 2235 2233 bitPos -= 4; 2236 2234 hex_value <<= bitPos % integerPartWidth; … … 2238 2236 } else { 2239 2237 lost_fraction = trailingHexadecimalFraction(p, end, hex_value); 2240 while (p != end && hexDigitValue(*p) != -1U)2238 while (p != end && hexDigitValue(*p) != -1U) 2241 2239 p++; 2242 2240 break; … … 2252 2250 2253 2251 /* Ignore the exponent if we are zero. */ 2254 if (p != firstSignificantDigit) {2252 if (p != firstSignificantDigit) { 2255 2253 int expAdjustment; 2256 2254 … … 2262 2260 significant digits. */ 2263 2261 expAdjustment = static_cast<int>(dot - firstSignificantDigit); 2264 if (expAdjustment < 0)2262 if (expAdjustment < 0) 2265 2263 expAdjustment++; 2266 2264 expAdjustment = expAdjustment * 4 - 1; … … 2288 2286 bool isNearest; 2289 2287 2290 isNearest = (rounding_mode == rmNearestTiesToEven 2291 ||rounding_mode == rmNearestTiesToAway);2288 isNearest = (rounding_mode == rmNearestTiesToEven || 2289 rounding_mode == rmNearestTiesToAway); 2292 2290 2293 2291 parts = partCountForBits(semantics->precision + 11); … … 2364 2362 2365 2363 APFloat::opStatus 2366 APFloat::convertFromDecimalString( const StringRef &str, roundingMode rounding_mode)2364 APFloat::convertFromDecimalString(StringRef str, roundingMode rounding_mode) 2367 2365 { 2368 2366 decimalInfo D; … … 2474 2472 2475 2473 APFloat::opStatus 2476 APFloat::convertFromString( const StringRef &str, roundingMode rounding_mode)2474 APFloat::convertFromString(StringRef str, roundingMode rounding_mode) 2477 2475 { 2478 2476 assertArithmeticOK(*semantics); … … 2483 2481 size_t slen = str.size(); 2484 2482 sign = *p == '-' ? 1 : 0; 2485 if (*p == '-' || *p == '+') {2483 if (*p == '-' || *p == '+') { 2486 2484 p++; 2487 2485 slen--; … … 2489 2487 } 2490 2488 2491 if (slen >= 2 && p[0] == '0' && (p[1] == 'x' || p[1] == 'X')) {2489 if (slen >= 2 && p[0] == '0' && (p[1] == 'x' || p[1] == 'X')) { 2492 2490 assert(slen - 2 && "Invalid string"); 2493 2491 return convertFromHexadecimalString(StringRef(p + 2, slen - 2), … … 3014 3012 category = fcInfinity; 3015 3013 } else if (myexponent==0x7ff && mysignificand!=0) { 3016 // exponent meaningless. So is the whole second word, but keep it 3014 // exponent meaningless. So is the whole second word, but keep it 3017 3015 // for determinism. 3018 3016 category = fcNaN; … … 3032 3030 else 3033 3031 significandParts()[0] |= 0x10000000000000LL; // integer bit 3034 if (myexponent2==0) 3032 if (myexponent2==0) 3035 3033 exponent2 = -1022; 3036 3034 else … … 3218 3216 3219 3217 // ...and then clear the top bits for internal consistency. 3220 significand[N-1] 3221 &=(((integerPart) 1) << ((Sem.precision % integerPartWidth) - 1)) - 1;3218 significand[N-1] &= 3219 (((integerPart) 1) << ((Sem.precision % integerPartWidth) - 1)) - 1; 3222 3220 3223 3221 return Val; … … 3248 3246 Val.exponent = Sem.minExponent; 3249 3247 Val.zeroSignificand(); 3250 Val.significandParts()[partCountForBits(Sem.precision)-1] 3251 |=(((integerPart) 1) << ((Sem.precision % integerPartWidth) - 1));3248 Val.significandParts()[partCountForBits(Sem.precision)-1] |= 3249 (((integerPart) 1) << ((Sem.precision % integerPartWidth) - 1)); 3252 3250 3253 3251 return Val; … … 3434 3432 // <= semantics->precision + e * 137 / 59 3435 3433 // (log_2(5) ~ 2.321928 < 2.322034 ~ 137/59) 3436 3434 3437 3435 unsigned precision = semantics->precision + 137 * texp / 59; 3438 3436 … … 3443 3441 while (true) { 3444 3442 if (texp & 1) significand *= five_to_the_i; 3445 3443 3446 3444 texp >>= 1; 3447 3445 if (!texp) break;
Note:
See TracChangeset
for help on using the changeset viewer.