23#include "llvm/Config/llvm-config.h"
31#define APFLOAT_DISPATCH_ON_SEMANTICS(METHOD_CALL) \
33 if (usesLayout<IEEEFloat>(getSemantics())) \
34 return U.IEEE.METHOD_CALL; \
35 if (usesLayout<DoubleAPFloat>(getSemantics())) \
36 return U.Double.METHOD_CALL; \
37 llvm_unreachable("Unexpected semantics"); \
48#define PackCategoriesIntoKey(_lhs, _rhs) ((_lhs) * 4 + (_rhs))
351 if (Src.maxExponent >= Dst.maxExponent || Src.minExponent <= Dst.minExponent)
359 return Dst.precision >= Src.precision;
397static inline unsigned int
411 unsigned int absExponent;
412 const unsigned int overlargeExponent = 24000;
416 if (p == end || ((*p ==
'-' || *p ==
'+') && (p + 1) == end)) {
420 isNegative = (*p ==
'-');
421 if (*p ==
'-' || *p ==
'+') {
428 if (absExponent >= 10U)
429 return createError(
"Invalid character in exponent");
431 for (; p != end; ++p) {
436 return createError(
"Invalid character in exponent");
438 absExponent = absExponent * 10U +
value;
439 if (absExponent >= overlargeExponent) {
440 absExponent = overlargeExponent;
446 return -(int) absExponent;
448 return (
int) absExponent;
455 int exponentAdjustment) {
456 int unsignedExponent;
457 bool negative, overflow;
463 negative = *p ==
'-';
464 if (*p ==
'-' || *p ==
'+') {
470 unsignedExponent = 0;
472 for (; p != end; ++p) {
477 return createError(
"Invalid character in exponent");
479 unsignedExponent = unsignedExponent * 10 +
value;
480 if (unsignedExponent > 32767) {
486 if (exponentAdjustment > 32767 || exponentAdjustment < -32768)
490 exponent = unsignedExponent;
492 exponent = -exponent;
493 exponent += exponentAdjustment;
494 if (exponent > 32767 || exponent < -32768)
499 exponent = negative ? -32768: 32767;
509 while (p != end && *p ==
'0')
512 if (p != end && *p ==
'.') {
515 if (end - begin == 1)
518 while (p != end && *p ==
'0')
551 return PtrOrErr.takeError();
554 D->firstSigDigit = p;
556 D->normalizedExponent = 0;
558 for (; p != end; ++p) {
561 return createError(
"String contains multiple dots");
571 if (*p !=
'e' && *p !=
'E')
572 return createError(
"Invalid character in significand");
575 if (dot != end && p - begin == 1)
581 return ExpOrErr.takeError();
582 D->exponent = *ExpOrErr;
590 if (p !=
D->firstSigDigit) {
596 while (p != begin && *p ==
'0');
597 while (p != begin && *p ==
'.');
602 D->normalizedExponent = (
D->exponent +
604 - (dot >
D->firstSigDigit && dot < p)));
616 unsigned int digitValue) {
617 unsigned int hexDigit;
623 else if (digitValue < 8 && digitValue > 0)
627 while (p != end && (*p ==
'0' || *p ==
'.'))
631 return createError(
"Invalid trailing hexadecimal fraction!");
633 hexDigit = hexDigitValue(*p);
637 if (hexDigit == UINT_MAX)
647 unsigned int partCount,
676 return lost_fraction;
691 return moreSignificant;
702HUerrBound(
bool inexactMultiply,
unsigned int HUerr1,
unsigned int HUerr2)
704 assert(HUerr1 < 2 || HUerr2 < 2 || (HUerr1 + HUerr2 < 8));
706 if (HUerr1 + HUerr2 == 0)
707 return inexactMultiply * 2;
709 return inexactMultiply + 2 * (HUerr1 + HUerr2);
718 unsigned int count, partBits;
735 if (part - boundary <= boundary - part)
736 return part - boundary;
738 return boundary - part;
741 if (part == boundary) {
747 }
else if (part == boundary - 1) {
764 pow5s[0] = 78125 * 5;
766 unsigned int partsCount = 1;
774 *p1 = firstEightPowers[power & 7];
780 for (
unsigned int n = 0; power; power >>= 1, n++) {
784 partsCount, partsCount);
786 if (pow5[partsCount - 1] == 0)
794 result += partsCount;
795 if (p2[result - 1] == 0)
820static const char NaNL[] =
"nan";
821static const char NaNU[] =
"NAN";
828 const char *hexDigitChars)
830 unsigned int result =
count;
836 dst[
count] = hexDigitChars[part & 0xf];
876void IEEEFloat::initialize(
const fltSemantics *ourSemantics) {
879 semantics = ourSemantics;
885void IEEEFloat::freeSignificand() {
887 delete [] significand.parts;
890void IEEEFloat::assign(
const IEEEFloat &rhs) {
891 assert(semantics == rhs.semantics);
894 category = rhs.category;
895 exponent = rhs.exponent;
897 copySignificand(rhs);
900void IEEEFloat::copySignificand(
const IEEEFloat &rhs) {
902 assert(rhs.partCount() >= partCount());
917 exponent = exponentNaN();
920 unsigned numParts = partCount();
933 fill = &fill_storage;
944 unsigned bitsToPreserve = semantics->
precision - 1;
945 unsigned part = bitsToPreserve / 64;
946 bitsToPreserve %= 64;
947 significand[part] &= ((1ULL << bitsToPreserve) - 1);
948 for (part++; part != numParts; ++part)
949 significand[part] = 0;
952 unsigned QNaNBit = semantics->
precision - 2;
980 if (semantics != rhs.semantics) {
982 initialize(rhs.semantics);
993 semantics = rhs.semantics;
994 significand = rhs.significand;
995 exponent = rhs.exponent;
996 category = rhs.category;
1014 significandMSB() == 0;
1019 isSignificandAllZerosExceptMSB();
1022bool IEEEFloat::isSignificandAllOnes()
const {
1027 for (
unsigned i = 0; i < PartCount - 1; i++)
1032 const unsigned NumHighBits =
1034 assert(NumHighBits <= integerPartWidth && NumHighBits > 0 &&
1035 "Can not have more high bits to fill than integerPartWidth");
1038 if (~(Parts[PartCount - 1] | HighBitFill))
1044bool IEEEFloat::isSignificandAllOnesExceptLSB()
const {
1053 for (
unsigned i = 0; i < PartCount - 1; i++) {
1054 if (~Parts[i] & ~
unsigned{!i})
1059 const unsigned NumHighBits =
1061 assert(NumHighBits <= integerPartWidth && NumHighBits > 0 &&
1062 "Can not have more high bits to fill than integerPartWidth");
1065 if (~(Parts[PartCount - 1] | HighBitFill | 0x1))
1071bool IEEEFloat::isSignificandAllZeros()
const {
1077 for (
unsigned i = 0; i < PartCount - 1; i++)
1082 const unsigned NumHighBits =
1085 "clear than integerPartWidth");
1086 const integerPart HighBitMask = ~integerPart(0) >> NumHighBits;
1088 if (Parts[PartCount - 1] & HighBitMask)
1094bool IEEEFloat::isSignificandAllZerosExceptMSB()
const {
1098 for (
unsigned i = 0; i < PartCount - 1; i++) {
1103 const unsigned NumHighBits =
1116 isSignificandAllOnesExceptLSB();
1121 isSignificandAllOnes();
1136 if (semantics != rhs.semantics ||
1137 category != rhs.category ||
1146 return std::equal(significandParts(), significandParts() + partCount(),
1147 rhs.significandParts());
1151 initialize(&ourSemantics);
1156 significandParts()[0] =
value;
1161 initialize(&ourSemantics);
1171 initialize(rhs.semantics);
1176 *
this = std::move(rhs);
1181unsigned int IEEEFloat::partCount()
const {
1186 return const_cast<IEEEFloat *
>(
this)->significandParts();
1190 if (partCount() > 1)
1191 return significand.parts;
1193 return &significand.part;
1196void IEEEFloat::zeroSignificand() {
1201void IEEEFloat::incrementSignificand() {
1215 parts = significandParts();
1217 assert(semantics == rhs.semantics);
1218 assert(exponent == rhs.exponent);
1220 return APInt::tcAdd(parts, rhs.significandParts(), 0, partCount());
1226 integerPart borrow) {
1229 parts = significandParts();
1231 assert(semantics == rhs.semantics);
1232 assert(exponent == rhs.exponent);
1241lostFraction IEEEFloat::multiplySignificand(
const IEEEFloat &rhs,
1244 unsigned int partsCount, newPartsCount, precision;
1251 assert(semantics == rhs.semantics);
1259 if (newPartsCount > 4)
1262 fullSignificand = scratch;
1264 lhsSignificand = significandParts();
1265 partsCount = partCount();
1268 rhs.significandParts(), partsCount, partsCount);
1271 omsb =
APInt::tcMSB(fullSignificand, newPartsCount) + 1;
1272 exponent += rhs.exponent;
1286 if (addend.isNonZero()) {
1290 Significand savedSignificand = significand;
1294 unsigned int extendedPrecision;
1297 extendedPrecision = 2 * precision + 1;
1298 if (omsb != extendedPrecision - 1) {
1299 assert(extendedPrecision > omsb);
1301 (extendedPrecision - 1) - omsb);
1302 exponent -= (extendedPrecision - 1) - omsb;
1306 extendedSemantics = *semantics;
1307 extendedSemantics.
precision = extendedPrecision;
1309 if (newPartsCount == 1)
1310 significand.part = fullSignificand[0];
1312 significand.parts = fullSignificand;
1313 semantics = &extendedSemantics;
1326 lost_fraction = extendedAddend.shiftSignificandRight(1);
1328 "Lost precision while shifting addend for fused-multiply-add.");
1330 lost_fraction = addOrSubtractSignificand(extendedAddend,
false);
1333 if (newPartsCount == 1)
1334 fullSignificand[0] = significand.part;
1335 significand = savedSignificand;
1336 semantics = savedSemantics;
1338 omsb =
APInt::tcMSB(fullSignificand, newPartsCount) + 1;
1345 exponent -= precision + 1;
1354 if (omsb > precision) {
1355 unsigned int bits, significantParts;
1358 bits = omsb - precision;
1360 lf =
shiftRight(fullSignificand, significantParts, bits);
1367 if (newPartsCount > 4)
1368 delete [] fullSignificand;
1370 return lost_fraction;
1373lostFraction IEEEFloat::multiplySignificand(
const IEEEFloat &rhs) {
1374 return multiplySignificand(rhs,
IEEEFloat(*semantics));
1378lostFraction IEEEFloat::divideSignificand(
const IEEEFloat &rhs) {
1379 unsigned int bit, i, partsCount;
1385 assert(semantics == rhs.semantics);
1387 lhsSignificand = significandParts();
1388 rhsSignificand = rhs.significandParts();
1389 partsCount = partCount();
1396 divisor = dividend + partsCount;
1399 for (i = 0; i < partsCount; i++) {
1400 dividend[i] = lhsSignificand[i];
1401 divisor[i] = rhsSignificand[i];
1402 lhsSignificand[i] = 0;
1405 exponent -= rhs.exponent;
1407 unsigned int precision = semantics->
precision;
1410 bit = precision -
APInt::tcMSB(divisor, partsCount) - 1;
1417 bit = precision -
APInt::tcMSB(dividend, partsCount) - 1;
1433 for (bit = precision; bit; bit -= 1) {
1457 return lost_fraction;
1460unsigned int IEEEFloat::significandMSB()
const {
1464unsigned int IEEEFloat::significandLSB()
const {
1469lostFraction IEEEFloat::shiftSignificandRight(
unsigned int bits) {
1475 return shiftRight(significandParts(), partCount(), bits);
1479void IEEEFloat::shiftSignificandLeft(
unsigned int bits) {
1480 assert(bits < semantics->precision);
1483 unsigned int partsCount = partCount();
1496 assert(semantics == rhs.semantics);
1500 compare = exponent - rhs.exponent;
1567bool IEEEFloat::roundAwayFromZero(roundingMode rounding_mode,
1569 unsigned int bit)
const {
1576 switch (rounding_mode) {
1614 omsb = significandMSB() + 1;
1620 exponentChange = omsb - semantics->
precision;
1624 if (exponent + exponentChange > semantics->
maxExponent)
1625 return handleOverflow(rounding_mode);
1629 if (exponent + exponentChange < semantics->minExponent)
1630 exponentChange = semantics->
minExponent - exponent;
1633 if (exponentChange < 0) {
1636 shiftSignificandLeft(-exponentChange);
1641 if (exponentChange > 0) {
1645 lf = shiftSignificandRight(exponentChange);
1650 if (omsb > (
unsigned) exponentChange)
1651 omsb -= exponentChange;
1661 exponent == semantics->
maxExponent && isSignificandAllOnes())
1662 return handleOverflow(rounding_mode);
1681 if (roundAwayFromZero(rounding_mode, lost_fraction, 0)) {
1685 incrementSignificand();
1686 omsb = significandMSB() + 1;
1689 if (omsb == (
unsigned) semantics->
precision + 1) {
1700 shiftSignificandRight(1);
1709 exponent == semantics->
maxExponent && isSignificandAllOnes())
1710 return handleOverflow(rounding_mode);
1719 assert(omsb < semantics->precision);
1789lostFraction IEEEFloat::addOrSubtractSignificand(
const IEEEFloat &rhs,
1797 subtract ^=
static_cast<bool>(sign ^ rhs.sign);
1800 bits = exponent - rhs.exponent;
1808 else if (bits > 0) {
1809 lost_fraction = temp_rhs.shiftSignificandRight(bits - 1);
1810 shiftSignificandLeft(1);
1812 lost_fraction = shiftSignificandRight(-bits - 1);
1813 temp_rhs.shiftSignificandLeft(1);
1818 carry = temp_rhs.subtractSignificand
1820 copySignificand(temp_rhs);
1823 carry = subtractSignificand
1842 lost_fraction = temp_rhs.shiftSignificandRight(bits);
1843 carry = addSignificand(temp_rhs);
1845 lost_fraction = shiftSignificandRight(-bits);
1846 carry = addSignificand(rhs);
1854 return lost_fraction;
2039 roundingMode rounding_mode,
2043 fs = addOrSubtractSpecials(rhs,
subtract);
2049 lost_fraction = addOrSubtractSignificand(rhs,
subtract);
2050 fs = normalize(rounding_mode, lost_fraction);
2059 if (category ==
fcZero) {
2073 return addOrSubtract(rhs, rounding_mode,
false);
2079 return addOrSubtract(rhs, rounding_mode,
true);
2088 fs = multiplySpecials(rhs);
2094 fs = normalize(rounding_mode, lost_fraction);
2108 fs = divideSpecials(rhs);
2114 fs = normalize(rounding_mode, lost_fraction);
2125 unsigned int origSign = sign;
2128 fs = remainderSpecials(rhs);
2235 fs = modSpecials(rhs);
2236 unsigned int origSign = sign;
2266 sign ^= multiplicand.sign;
2275 lost_fraction = multiplySignificand(multiplicand, addend);
2276 fs = normalize(rounding_mode, lost_fraction);
2289 fs = multiplySpecials(multiplicand);
2299 fs = addOrSubtract(addend, rounding_mode,
false);
2372 MagicConstant.sign = sign;
2378 fs =
add(MagicConstant, rounding_mode);
2382 subtract(MagicConstant, rounding_mode);
2396 assert(semantics == rhs.semantics);
2428 if (sign == rhs.sign)
2443 if (sign != rhs.sign) {
2474 unsigned int newPartCount, oldPartCount;
2482 oldPartCount = partCount();
2485 bool X86SpecialNan =
false;
2488 (!(*significandParts() & 0x8000000000000000ULL) ||
2489 !(*significandParts() & 0x4000000000000000ULL))) {
2492 X86SpecialNan =
true;
2503 int omsb = significandMSB() + 1;
2504 int exponentChange = omsb - fromSemantics.
precision;
2505 if (exponent + exponentChange < toSemantics.
minExponent)
2506 exponentChange = toSemantics.
minExponent - exponent;
2507 if (exponentChange < shift)
2508 exponentChange = shift;
2509 if (exponentChange < 0) {
2510 shift -= exponentChange;
2511 exponent += exponentChange;
2512 }
else if (omsb <= -shift) {
2513 exponentChange = omsb + shift - 1;
2514 shift -= exponentChange;
2515 exponent += exponentChange;
2526 if (newPartCount > oldPartCount) {
2534 significand.parts = newParts;
2535 }
else if (newPartCount == 1 && oldPartCount != 1) {
2539 newPart = significandParts()[0];
2541 significand.part = newPart;
2545 semantics = &toSemantics;
2554 *losesInfo = (fs !=
opOK);
2555 }
else if (category ==
fcNaN) {
2590 }
else if (category ==
fcZero &&
2618 roundingMode rounding_mode,
bool *isExact)
const {
2621 unsigned int dstPartsCount, truncatedBits;
2630 assert(dstPartsCount <= parts.
size() &&
"Integer too big");
2632 if (category ==
fcZero) {
2639 src = significandParts();
2648 truncatedBits = semantics->
precision -1U - exponent;
2652 unsigned int bits = exponent + 1U;
2658 if (bits < semantics->precision) {
2660 truncatedBits = semantics->
precision - bits;
2674 if (truncatedBits) {
2678 roundAwayFromZero(rounding_mode, lost_fraction, truncatedBits)) {
2698 if (omsb == width &&
2735 fs = convertToSignExtendedInteger(parts, width,
isSigned, rounding_mode,
2739 unsigned int bits, dstPartsCount;
2742 assert(dstPartsCount <= parts.
size() &&
"Integer too big");
2744 if (category ==
fcNaN)
2763 const integerPart *src,
unsigned int srcCount, roundingMode rounding_mode) {
2764 unsigned int omsb, precision, dstCount;
2770 dst = significandParts();
2771 dstCount = partCount();
2776 if (precision <= omsb) {
2777 exponent = omsb - 1;
2782 exponent = precision - 1;
2787 return normalize(rounding_mode, lost_fraction);
2801 return convertFromUnsignedParts(api.
getRawData(), partCount, rounding_mode);
2809 unsigned int srcCount,
bool isSigned,
2822 status = convertFromUnsignedParts(
copy, srcCount, rounding_mode);
2826 status = convertFromUnsignedParts(src, srcCount, rounding_mode);
2846 return convertFromUnsignedParts(api.
getRawData(), partCount, rounding_mode);
2850IEEEFloat::convertFromHexadecimalString(
StringRef s,
2851 roundingMode rounding_mode) {
2859 unsigned partsCount = partCount();
2861 bool computedTrailingFraction =
false;
2869 return PtrOrErr.takeError();
2878 return createError(
"String contains multiple dots");
2883 hex_value = hexDigitValue(*p);
2884 if (hex_value == UINT_MAX)
2894 }
else if (!computedTrailingFraction) {
2897 return FractOrErr.takeError();
2898 lost_fraction = *FractOrErr;
2899 computedTrailingFraction =
true;
2905 return createError(
"Hex strings require an exponent");
2906 if (*p !=
'p' && *p !=
'P')
2907 return createError(
"Invalid character in significand");
2910 if (dot != end && p - begin == 1)
2914 if (p != firstSignificantDigit) {
2923 expAdjustment =
static_cast<int>(
dot - firstSignificantDigit);
2924 if (expAdjustment < 0)
2926 expAdjustment = expAdjustment * 4 - 1;
2936 return ExpOrErr.takeError();
2937 exponent = *ExpOrErr;
2940 return normalize(rounding_mode, lost_fraction);
2944IEEEFloat::roundSignificandWithExponent(
const integerPart *decSigParts,
2945 unsigned sigPartCount,
int exp,
2946 roundingMode rounding_mode) {
2947 unsigned int parts, pow5PartCount;
2958 pow5PartCount =
powerOf5(pow5Parts, exp >= 0 ? exp: -exp);
2960 for (;; parts *= 2) {
2962 unsigned int excessPrecision, truncatedBits;
2966 truncatedBits = excessPrecision;
2969 decSig.makeZero(sign);
2972 sigStatus = decSig.convertFromUnsignedParts(decSigParts, sigPartCount,
2974 powStatus = pow5.convertFromUnsignedParts(pow5Parts, pow5PartCount,
2977 decSig.exponent += exp;
2981 unsigned int powHUerr;
2985 calcLostFraction = decSig.multiplySignificand(pow5);
2986 powHUerr = powStatus !=
opOK;
2988 calcLostFraction = decSig.divideSignificand(pow5);
2991 excessPrecision += (semantics->
minExponent - decSig.exponent);
2992 truncatedBits = excessPrecision;
2993 if (excessPrecision > calcSemantics.
precision)
2994 excessPrecision = calcSemantics.
precision;
3003 (decSig.significandParts(), calcSemantics.
precision - 1) == 1);
3008 excessPrecision, isNearest);
3011 if (HUdistance >= HUerr) {
3012 APInt::tcExtract(significandParts(), partCount(), decSig.significandParts(),
3013 calcSemantics.
precision - excessPrecision,
3018 exponent = (decSig.exponent + semantics->
precision
3019 - (calcSemantics.
precision - excessPrecision));
3023 return normalize(rounding_mode, calcLostFraction);
3029IEEEFloat::convertFromDecimalString(
StringRef str, roundingMode rounding_mode) {
3036 return std::move(Err);
3070 }
else if (
D.normalizedExponent - 1 > INT_MAX / 42039) {
3071 fs = handleOverflow(rounding_mode);
3077 }
else if (
D.normalizedExponent - 1 < INT_MIN / 42039 ||
3078 (
D.normalizedExponent + 1) * 28738 <=
3086 }
else if ((
D.normalizedExponent - 1) * 42039
3089 fs = handleOverflow(rounding_mode);
3092 unsigned int partCount;
3098 partCount =
static_cast<unsigned int>(
D.lastSigDigit -
D.firstSigDigit) + 1;
3116 if (p == str.
end()) {
3121 if (decValue >= 10U) {
3122 delete[] decSignificand;
3123 return createError(
"Invalid character in significand");
3126 val = val * 10 + decValue;
3129 }
while (p <=
D.lastSigDigit && multiplier <= (~ (
integerPart) 0 - 9) / 10);
3133 partCount, partCount + 1,
false);
3137 if (decSignificand[partCount])
3139 }
while (p <=
D.lastSigDigit);
3142 fs = roundSignificandWithExponent(decSignificand, partCount,
3143 D.exponent, rounding_mode);
3145 delete [] decSignificand;
3151bool IEEEFloat::convertFromStringSpecials(
StringRef str) {
3152 const size_t MIN_NAME_SIZE = 3;
3154 if (str.
size() < MIN_NAME_SIZE)
3157 if (str ==
"inf" || str ==
"INFINITY" || str ==
"+Inf") {
3162 bool IsNegative = str.
front() ==
'-';
3165 if (str.
size() < MIN_NAME_SIZE)
3168 if (str ==
"inf" || str ==
"INFINITY" || str ==
"Inf") {
3175 bool IsSignaling = str.
front() ==
's' || str.
front() ==
'S';
3178 if (str.
size() < MIN_NAME_SIZE)
3187 makeNaN(IsSignaling, IsNegative);
3192 if (str.
front() ==
'(') {
3194 if (str.
size() <= 2 || str.
back() !=
')')
3201 unsigned Radix = 10;
3202 if (str[0] ==
'0') {
3203 if (str.
size() > 1 && tolower(str[1]) ==
'x') {
3213 makeNaN(IsSignaling, IsNegative, &Payload);
3227 if (convertFromStringSpecials(str))
3232 size_t slen = str.
size();
3233 sign = *p ==
'-' ? 1 : 0;
3234 if (*p ==
'-' || *p ==
'+') {
3241 if (slen >= 2 && p[0] ==
'0' && (p[1] ==
'x' || p[1] ==
'X')) {
3244 return convertFromHexadecimalString(
StringRef(p + 2, slen - 2),
3248 return convertFromDecimalString(
StringRef(p, slen), rounding_mode);
3292 dst +=
sizeof NaNU - 1;
3297 *dst++ = upperCase ?
'X':
'x';
3299 if (hexDigits > 1) {
3301 memset (dst,
'0', hexDigits - 1);
3302 dst += hexDigits - 1;
3304 *dst++ = upperCase ?
'P':
'p';
3309 dst = convertNormalToHexString (dst, hexDigits, upperCase, rounding_mode);
3315 return static_cast<unsigned int>(dst - p);
3322char *IEEEFloat::convertNormalToHexString(
char *dst,
unsigned int hexDigits,
3324 roundingMode rounding_mode)
const {
3325 unsigned int count, valueBits, shift, partsCount, outputDigits;
3326 const char *hexDigitChars;
3332 *dst++ = upperCase ?
'X':
'x';
3337 significand = significandParts();
3338 partsCount = partCount();
3347 outputDigits = (valueBits - significandLSB () + 3) / 4;
3353 if (hexDigits < outputDigits) {
3359 bits = valueBits - hexDigits * 4;
3361 roundUp = roundAwayFromZero(rounding_mode, fraction, bits);
3363 outputDigits = hexDigits;
3373 while (outputDigits &&
count) {
3377 if (--
count == partsCount)
3380 part = significand[
count] << shift;
3388 if (curDigits > outputDigits)
3389 curDigits = outputDigits;
3390 dst +=
partAsHex (dst, part, curDigits, hexDigitChars);
3391 outputDigits -= curDigits;
3400 *
q = hexDigitChars[hexDigitValue (*q) + 1];
3401 }
while (*q ==
'0');
3405 memset (dst,
'0', outputDigits);
3406 dst += outputDigits;
3419 *dst++ = upperCase ?
'P':
'p';
3428 Arg.
isNaN() ? (uint8_t)0 : (uint8_t)Arg.sign,
3432 return hash_combine((uint8_t)Arg.category, (uint8_t)Arg.sign,
3435 Arg.significandParts(),
3436 Arg.significandParts() + Arg.partCount()));
3448APInt IEEEFloat::convertF80LongDoubleAPFloatToAPInt()
const {
3452 uint64_t myexponent, mysignificand;
3455 myexponent = exponent+16383;
3456 mysignificand = significandParts()[0];
3457 if (myexponent==1 && !(mysignificand & 0x8000000000000000ULL))
3459 }
else if (category==
fcZero) {
3463 myexponent = 0x7fff;
3464 mysignificand = 0x8000000000000000ULL;
3467 myexponent = 0x7fff;
3468 mysignificand = significandParts()[0];
3472 words[0] = mysignificand;
3473 words[1] = ((
uint64_t)(sign & 1) << 15) |
3474 (myexponent & 0x7fffLL);
3475 return APInt(80, words);
3478APInt IEEEFloat::convertPPCDoubleDoubleAPFloatToAPInt()
const {
3503 words[0] = *
u.convertDoubleAPFloatToAPInt().getRawData();
3509 if (
u.isFiniteNonZero() && losesInfo) {
3519 words[1] = *
v.convertDoubleAPFloatToAPInt().getRawData();
3524 return APInt(128, words);
3527template <const fltSemantics &S>
3528APInt IEEEFloat::convertIEEEFloatToAPInt()
const {
3531 constexpr int bias = -(S.minExponent - 1);
3532 constexpr unsigned int trailing_significand_bits = S.precision - 1;
3533 constexpr int integer_bit_part = trailing_significand_bits /
integerPartWidth;
3536 constexpr uint64_t significand_mask = integer_bit - 1;
3537 constexpr unsigned int exponent_bits =
3538 S.sizeInBits - 1 - trailing_significand_bits;
3539 static_assert(exponent_bits < 64);
3547 myexponent = exponent + bias;
3548 std::copy_n(significandParts(), mysignificand.size(),
3549 mysignificand.begin());
3550 if (myexponent == 1 &&
3551 !(significandParts()[integer_bit_part] & integer_bit))
3553 }
else if (category ==
fcZero) {
3554 myexponent = ::exponentZero(S) + bias;
3555 mysignificand.fill(0);
3560 myexponent = ::exponentInf(S) + bias;
3561 mysignificand.fill(0);
3566 myexponent = ::exponentNaN(S) + bias;
3567 std::copy_n(significandParts(), mysignificand.size(),
3568 mysignificand.begin());
3570 std::array<
uint64_t, (S.sizeInBits + 63) / 64> words;
3572 std::copy_n(mysignificand.begin(), mysignificand.size(), words.begin());
3573 if constexpr (significand_mask != 0) {
3575 words[mysignificand.size() - 1] &= significand_mask;
3577 std::fill(words_iter, words.end(),
uint64_t{0});
3578 constexpr size_t last_word = words.size() - 1;
3580 << ((S.sizeInBits - 1) % 64);
3581 words[last_word] |= shifted_sign;
3582 uint64_t shifted_exponent = (myexponent & exponent_mask)
3583 << (trailing_significand_bits % 64);
3584 words[last_word] |= shifted_exponent;
3585 if constexpr (last_word == 0) {
3586 return APInt(S.sizeInBits, words[0]);
3588 return APInt(S.sizeInBits, words);
3591APInt IEEEFloat::convertQuadrupleAPFloatToAPInt()
const {
3592 assert(partCount() == 2);
3593 return convertIEEEFloatToAPInt<semIEEEquad>();
3596APInt IEEEFloat::convertDoubleAPFloatToAPInt()
const {
3598 return convertIEEEFloatToAPInt<semIEEEdouble>();
3601APInt IEEEFloat::convertFloatAPFloatToAPInt()
const {
3603 return convertIEEEFloatToAPInt<semIEEEsingle>();
3606APInt IEEEFloat::convertBFloatAPFloatToAPInt()
const {
3607 assert(partCount() == 1);
3608 return convertIEEEFloatToAPInt<semBFloat>();
3611APInt IEEEFloat::convertHalfAPFloatToAPInt()
const {
3613 return convertIEEEFloatToAPInt<semIEEEhalf>();
3616APInt IEEEFloat::convertFloat8E5M2APFloatToAPInt()
const {
3617 assert(partCount() == 1);
3618 return convertIEEEFloatToAPInt<semFloat8E5M2>();
3621APInt IEEEFloat::convertFloat8E5M2FNUZAPFloatToAPInt()
const {
3622 assert(partCount() == 1);
3623 return convertIEEEFloatToAPInt<semFloat8E5M2FNUZ>();
3626APInt IEEEFloat::convertFloat8E4M3APFloatToAPInt()
const {
3627 assert(partCount() == 1);
3628 return convertIEEEFloatToAPInt<semFloat8E4M3>();
3631APInt IEEEFloat::convertFloat8E4M3FNAPFloatToAPInt()
const {
3632 assert(partCount() == 1);
3633 return convertIEEEFloatToAPInt<semFloat8E4M3FN>();
3636APInt IEEEFloat::convertFloat8E4M3FNUZAPFloatToAPInt()
const {
3637 assert(partCount() == 1);
3638 return convertIEEEFloatToAPInt<semFloat8E4M3FNUZ>();
3641APInt IEEEFloat::convertFloat8E4M3B11FNUZAPFloatToAPInt()
const {
3642 assert(partCount() == 1);
3643 return convertIEEEFloatToAPInt<semFloat8E4M3B11FNUZ>();
3646APInt IEEEFloat::convertFloatTF32APFloatToAPInt()
const {
3647 assert(partCount() == 1);
3648 return convertIEEEFloatToAPInt<semFloatTF32>();
3651APInt IEEEFloat::convertFloat6E3M2FNAPFloatToAPInt()
const {
3652 assert(partCount() == 1);
3653 return convertIEEEFloatToAPInt<semFloat6E3M2FN>();
3656APInt IEEEFloat::convertFloat6E2M3FNAPFloatToAPInt()
const {
3657 assert(partCount() == 1);
3658 return convertIEEEFloatToAPInt<semFloat6E2M3FN>();
3661APInt IEEEFloat::convertFloat4E2M1FNAPFloatToAPInt()
const {
3662 assert(partCount() == 1);
3663 return convertIEEEFloatToAPInt<semFloat4E2M1FN>();
3672 return convertHalfAPFloatToAPInt();
3675 return convertBFloatAPFloatToAPInt();
3678 return convertFloatAPFloatToAPInt();
3681 return convertDoubleAPFloatToAPInt();
3684 return convertQuadrupleAPFloatToAPInt();
3687 return convertPPCDoubleDoubleAPFloatToAPInt();
3690 return convertFloat8E5M2APFloatToAPInt();
3693 return convertFloat8E5M2FNUZAPFloatToAPInt();
3696 return convertFloat8E4M3APFloatToAPInt();
3699 return convertFloat8E4M3FNAPFloatToAPInt();
3702 return convertFloat8E4M3FNUZAPFloatToAPInt();
3705 return convertFloat8E4M3B11FNUZAPFloatToAPInt();
3708 return convertFloatTF32APFloatToAPInt();
3711 return convertFloat6E3M2FNAPFloatToAPInt();
3714 return convertFloat6E2M3FNAPFloatToAPInt();
3717 return convertFloat4E2M1FNAPFloatToAPInt();
3721 return convertF80LongDoubleAPFloatToAPInt();
3726 "Float semantics are not IEEEsingle");
3733 "Float semantics are not IEEEdouble");
3738#ifdef HAS_IEE754_FLOAT128
3739float128 IEEEFloat::convertToQuad()
const {
3741 "Float semantics are not IEEEquads");
3743 return api.bitsToQuad();
3754void IEEEFloat::initFromF80LongDoubleAPInt(
const APInt &api) {
3757 uint64_t myexponent = (i2 & 0x7fff);
3759 uint8_t myintegerbit = mysignificand >> 63;
3764 sign =
static_cast<unsigned int>(i2>>15);
3765 if (myexponent == 0 && mysignificand == 0) {
3767 }
else if (myexponent==0x7fff && mysignificand==0x8000000000000000ULL) {
3769 }
else if ((myexponent == 0x7fff && mysignificand != 0x8000000000000000ULL) ||
3770 (myexponent != 0x7fff && myexponent != 0 && myintegerbit == 0)) {
3772 exponent = exponentNaN();
3773 significandParts()[0] = mysignificand;
3774 significandParts()[1] = 0;
3777 exponent = myexponent - 16383;
3778 significandParts()[0] = mysignificand;
3779 significandParts()[1] = 0;
3785void IEEEFloat::initFromPPCDoubleDoubleAPInt(
const APInt &api) {
3792 initFromDoubleAPInt(
APInt(64, i1));
3808template <const fltSemantics &S>
3809void IEEEFloat::initFromIEEEAPInt(
const APInt &api) {
3813 constexpr uint64_t significand_mask = integer_bit - 1;
3814 constexpr unsigned int trailing_significand_bits = S.precision - 1;
3815 constexpr unsigned int stored_significand_parts =
3817 constexpr unsigned int exponent_bits =
3818 S.sizeInBits - 1 - trailing_significand_bits;
3819 static_assert(exponent_bits < 64);
3821 constexpr int bias = -(S.minExponent - 1);
3825 std::array<integerPart, stored_significand_parts> mysignificand;
3826 std::copy_n(api.
getRawData(), mysignificand.size(), mysignificand.begin());
3827 if constexpr (significand_mask != 0) {
3828 mysignificand[mysignificand.size() - 1] &= significand_mask;
3835 (last_word >> (trailing_significand_bits % 64)) & exponent_mask;
3838 assert(partCount() == mysignificand.size());
3840 sign =
static_cast<unsigned int>(last_word >> ((S.sizeInBits - 1) % 64));
3842 bool all_zero_significand =
3845 bool is_zero = myexponent == 0 && all_zero_significand;
3848 if (myexponent - bias == ::exponentInf(S) && all_zero_significand) {
3857 is_nan = myexponent - bias == ::exponentNaN(S) && !all_zero_significand;
3859 bool all_ones_significand =
3860 std::all_of(mysignificand.begin(), mysignificand.end() - 1,
3861 [](
integerPart bits) { return bits == ~integerPart{0}; }) &&
3862 (!significand_mask ||
3863 mysignificand[mysignificand.size() - 1] == significand_mask);
3864 is_nan = myexponent - bias == ::exponentNaN(S) && all_ones_significand;
3872 std::copy_n(mysignificand.begin(), mysignificand.size(),
3873 significandParts());
3883 exponent = myexponent - bias;
3884 std::copy_n(mysignificand.begin(), mysignificand.size(), significandParts());
3885 if (myexponent == 0)
3886 exponent = S.minExponent;
3888 significandParts()[mysignificand.size()-1] |= integer_bit;
3891void IEEEFloat::initFromQuadrupleAPInt(
const APInt &api) {
3892 initFromIEEEAPInt<semIEEEquad>(api);
3895void IEEEFloat::initFromDoubleAPInt(
const APInt &api) {
3896 initFromIEEEAPInt<semIEEEdouble>(api);
3899void IEEEFloat::initFromFloatAPInt(
const APInt &api) {
3900 initFromIEEEAPInt<semIEEEsingle>(api);
3903void IEEEFloat::initFromBFloatAPInt(
const APInt &api) {
3904 initFromIEEEAPInt<semBFloat>(api);
3907void IEEEFloat::initFromHalfAPInt(
const APInt &api) {
3908 initFromIEEEAPInt<semIEEEhalf>(api);
3911void IEEEFloat::initFromFloat8E5M2APInt(
const APInt &api) {
3912 initFromIEEEAPInt<semFloat8E5M2>(api);
3915void IEEEFloat::initFromFloat8E5M2FNUZAPInt(
const APInt &api) {
3916 initFromIEEEAPInt<semFloat8E5M2FNUZ>(api);
3919void IEEEFloat::initFromFloat8E4M3APInt(
const APInt &api) {
3920 initFromIEEEAPInt<semFloat8E4M3>(api);
3923void IEEEFloat::initFromFloat8E4M3FNAPInt(
const APInt &api) {
3924 initFromIEEEAPInt<semFloat8E4M3FN>(api);
3927void IEEEFloat::initFromFloat8E4M3FNUZAPInt(
const APInt &api) {
3928 initFromIEEEAPInt<semFloat8E4M3FNUZ>(api);
3931void IEEEFloat::initFromFloat8E4M3B11FNUZAPInt(
const APInt &api) {
3932 initFromIEEEAPInt<semFloat8E4M3B11FNUZ>(api);
3935void IEEEFloat::initFromFloatTF32APInt(
const APInt &api) {
3936 initFromIEEEAPInt<semFloatTF32>(api);
3939void IEEEFloat::initFromFloat6E3M2FNAPInt(
const APInt &api) {
3940 initFromIEEEAPInt<semFloat6E3M2FN>(api);
3943void IEEEFloat::initFromFloat6E2M3FNAPInt(
const APInt &api) {
3944 initFromIEEEAPInt<semFloat6E2M3FN>(api);
3947void IEEEFloat::initFromFloat4E2M1FNAPInt(
const APInt &api) {
3948 initFromIEEEAPInt<semFloat4E2M1FN>(api);
3955 return initFromHalfAPInt(api);
3957 return initFromBFloatAPInt(api);
3959 return initFromFloatAPInt(api);
3961 return initFromDoubleAPInt(api);
3963 return initFromF80LongDoubleAPInt(api);
3965 return initFromQuadrupleAPInt(api);
3967 return initFromPPCDoubleDoubleAPInt(api);
3969 return initFromFloat8E5M2APInt(api);
3971 return initFromFloat8E5M2FNUZAPInt(api);
3973 return initFromFloat8E4M3APInt(api);
3975 return initFromFloat8E4M3FNAPInt(api);
3977 return initFromFloat8E4M3FNUZAPInt(api);
3979 return initFromFloat8E4M3B11FNUZAPInt(api);
3981 return initFromFloatTF32APInt(api);
3983 return initFromFloat6E3M2FNAPInt(api);
3985 return initFromFloat6E2M3FNAPInt(api);
3987 return initFromFloat4E2M1FNAPInt(api);
3994void IEEEFloat::makeLargest(
bool Negative) {
4001 exponent = semantics->maxExponent;
4005 unsigned PartCount = partCount();
4006 memset(significand, 0xFF,
sizeof(
integerPart)*(PartCount - 1));
4010 const unsigned NumUnusedHighBits =
4011 PartCount*integerPartWidth - semantics->precision;
4012 significand[PartCount - 1] = (NumUnusedHighBits < integerPartWidth)
4023void IEEEFloat::makeSmallest(
bool Negative) {
4030 exponent = semantics->minExponent;
4034void IEEEFloat::makeSmallestNormalized(
bool Negative) {
4043 exponent = semantics->minExponent;
4048 initFromAPInt(&Sem, API);
4051IEEEFloat::IEEEFloat(
float f) {
4055IEEEFloat::IEEEFloat(
double d) {
4061 Buffer.
append(Str.begin(), Str.end());
4066 void AdjustToPrecision(
APInt &significand,
4067 int &exp,
unsigned FormatPrecision) {
4071 unsigned bitsRequired = (FormatPrecision * 196 + 58) / 59;
4073 if (bits <= bitsRequired)
return;
4075 unsigned tensRemovable = (bits - bitsRequired) * 59 / 196;
4076 if (!tensRemovable)
return;
4078 exp += tensRemovable;
4083 if (tensRemovable & 1)
4085 tensRemovable >>= 1;
4086 if (!tensRemovable)
break;
4090 significand = significand.
udiv(divisor);
4098 int &exp,
unsigned FormatPrecision) {
4099 unsigned N = buffer.
size();
4100 if (
N <= FormatPrecision)
return;
4103 unsigned FirstSignificant =
N - FormatPrecision;
4110 if (buffer[FirstSignificant - 1] <
'5') {
4111 while (FirstSignificant <
N && buffer[FirstSignificant] ==
'0')
4114 exp += FirstSignificant;
4115 buffer.
erase(&buffer[0], &buffer[FirstSignificant]);
4121 for (
unsigned I = FirstSignificant;
I !=
N; ++
I) {
4122 if (buffer[
I] ==
'9') {
4131 if (FirstSignificant ==
N) {
4132 exp += FirstSignificant;
4138 exp += FirstSignificant;
4139 buffer.
erase(&buffer[0], &buffer[FirstSignificant]);
4143 APInt significand,
unsigned FormatPrecision,
4144 unsigned FormatMaxPadding,
bool TruncateZero) {
4145 const int semanticsPrecision = significand.
getBitWidth();
4152 if (!FormatPrecision) {
4160 FormatPrecision = 2 + semanticsPrecision * 59 / 196;
4165 exp += trailingZeros;
4171 }
else if (exp > 0) {
4173 significand = significand.
zext(semanticsPrecision + exp);
4174 significand <<= exp;
4188 unsigned precision = semanticsPrecision + (137 * texp + 136) / 59;
4192 significand = significand.
zext(precision);
4193 APInt five_to_the_i(precision, 5);
4196 significand *= five_to_the_i;
4201 five_to_the_i *= five_to_the_i;
4205 AdjustToPrecision(significand, exp, FormatPrecision);
4210 unsigned precision = significand.getBitWidth();
4211 if (precision < 4) {
4214 significand = significand.zext(precision);
4216 APInt ten(precision, 10);
4217 APInt digit(precision, 0);
4219 bool inTrail =
true;
4220 while (significand != 0) {
4225 unsigned d = digit.getZExtValue();
4236 assert(!buffer.
empty() &&
"no characters in buffer!");
4240 AdjustToPrecision(buffer, exp, FormatPrecision);
4242 unsigned NDigits = buffer.
size();
4245 bool FormatScientific;
4246 if (!FormatMaxPadding)
4247 FormatScientific =
true;
4253 FormatScientific = ((
unsigned) exp > FormatMaxPadding ||
4254 NDigits + (
unsigned) exp > FormatPrecision);
4257 int MSD = exp + (int) (NDigits - 1);
4260 FormatScientific =
false;
4264 FormatScientific = ((
unsigned) -MSD) > FormatMaxPadding;
4270 if (FormatScientific) {
4271 exp += (NDigits - 1);
4273 Str.push_back(buffer[NDigits-1]);
4275 if (NDigits == 1 && TruncateZero)
4278 for (
unsigned I = 1;
I != NDigits; ++
I)
4279 Str.push_back(buffer[NDigits-1-
I]);
4281 if (!TruncateZero && FormatPrecision > NDigits - 1)
4282 Str.append(FormatPrecision - NDigits + 1,
'0');
4284 Str.push_back(TruncateZero ?
'E' :
'e');
4286 Str.push_back(exp >= 0 ?
'+' :
'-');
4291 expbuf.
push_back((
char) (
'0' + (exp % 10)));
4295 if (!TruncateZero && expbuf.
size() < 2)
4297 for (
unsigned I = 0, E = expbuf.
size();
I != E; ++
I)
4298 Str.push_back(expbuf[E-1-
I]);
4304 for (
unsigned I = 0;
I != NDigits; ++
I)
4305 Str.push_back(buffer[NDigits-1-
I]);
4314 int NWholeDigits = exp + (int) NDigits;
4317 if (NWholeDigits > 0) {
4319 Str.push_back(buffer[NDigits-
I-1]);
4322 unsigned NZeros = 1 + (
unsigned) -NWholeDigits;
4326 for (
unsigned Z = 1;
Z != NZeros; ++
Z)
4330 for (;
I != NDigits; ++
I)
4331 Str.push_back(buffer[NDigits-
I-1]);
4337 unsigned FormatMaxPadding,
bool TruncateZero)
const {
4341 return append(Str,
"-Inf");
4343 return append(Str,
"+Inf");
4345 case fcNaN:
return append(Str,
"NaN");
4351 if (!FormatMaxPadding) {
4353 append(Str,
"0.0E+0");
4356 if (FormatPrecision > 1)
4357 Str.append(FormatPrecision - 1,
'0');
4358 append(Str,
"e+00");
4369 int exp = exponent - ((int) semantics->precision - 1);
4371 semantics->precision,
4374 toStringImpl(Str, isNegative(), exp, significand, FormatPrecision,
4375 FormatMaxPadding, TruncateZero);
4379bool IEEEFloat::getExactInverse(
APFloat *inv)
const {
4381 if (!isFiniteNonZero())
4386 if (significandLSB() != semantics->precision - 1)
4391 if (reciprocal.
divide(*
this, rmNearestTiesToEven) != opOK)
4400 reciprocal.significandLSB() == reciprocal.semantics->
precision - 1);
4403 *inv =
APFloat(reciprocal, *semantics);
4408int IEEEFloat::getExactLog2Abs()
const {
4416 for (
int i = 0; i < PartCount; ++i) {
4422 if (exponent != semantics->minExponent)
4425 int CountrParts = 0;
4426 for (
int i = 0; i < PartCount;
4428 if (Parts[i] != 0) {
4429 return exponent - semantics->precision + CountrParts +
4437bool IEEEFloat::isSignaling()
const {
4474 if (isSignaling()) {
4475 result = opInvalidOp;
4477 makeNaN(
false, isNegative(),
nullptr);
4482 makeSmallest(
false);
4486 if (isSmallest() && isNegative()) {
4495 if (isLargest() && !isNegative()) {
4500 }
else if (semantics->nonFiniteBehavior ==
4507 category = fcInfinity;
4508 exponent = semantics->maxExponent + 1;
4522 bool WillCrossBinadeBoundary =
4523 exponent != semantics->minExponent && isSignificandAllZeros();
4541 if (WillCrossBinadeBoundary) {
4557 bool WillCrossBinadeBoundary = !isDenormal() && isSignificandAllOnes();
4559 if (WillCrossBinadeBoundary) {
4563 assert(exponent != semantics->maxExponent &&
4564 "We can not increment an exponent beyond the maxExponent allowed"
4565 " by the given floating point semantics.");
4568 incrementSignificand();
4582 return ::exponentNaN(*semantics);
4586 return ::exponentInf(*semantics);
4590 return ::exponentZero(*semantics);
4593void IEEEFloat::makeInf(
bool Negative) {
4599 makeNaN(
false, Negative);
4602 category = fcInfinity;
4608void IEEEFloat::makeZero(
bool Negative) {
4619void IEEEFloat::makeQuiet() {
4627 return IEEEFloat::IEK_NaN;
4629 return IEEEFloat::IEK_Zero;
4631 return IEEEFloat::IEK_Inf;
4633 return Arg.exponent;
4638 Normalized.exponent += SignificandBits;
4639 Normalized.normalize(IEEEFloat::rmNearestTiesToEven,
lfExactlyZero);
4640 return Normalized.exponent - SignificandBits;
4644 auto MaxExp =
X.getSemantics().maxExponent;
4645 auto MinExp =
X.getSemantics().minExponent;
4653 int SignificandBits =
X.getSemantics().precision - 1;
4654 int MaxIncrement = MaxExp - (MinExp - SignificandBits) + 1;
4657 X.exponent += std::clamp(Exp, -MaxIncrement - 1, MaxIncrement);
4668 if (Exp == IEEEFloat::IEK_NaN) {
4674 if (Exp == IEEEFloat::IEK_Inf)
4679 Exp = Exp == IEEEFloat::IEK_Zero ? 0 : Exp + 1;
4680 return scalbn(Val, -Exp, RM);
4713 Floats(new
APFloat[2]{std::move(
First), std::move(Second)}) {
4735 Floats[0] =
RHS.Floats[0];
4736 Floats[1] =
RHS.Floats[1];
4737 }
else if (
this != &
RHS) {
4755 Floats[0] = std::move(z);
4756 Floats[1].makeZero(
false);
4760 auto AComparedToC = a.compareAbsoluteValue(c);
4773 Floats[0] = std::move(z);
4774 Floats[1].makeZero(
false);
4783 Status |= Floats[1].subtract(z, RM);
4784 Status |= Floats[1].add(c, RM);
4785 Status |= Floats[1].add(zz, RM);
4789 Status |= Floats[1].subtract(z, RM);
4790 Status |= Floats[1].add(a, RM);
4791 Status |= Floats[1].add(zz, RM);
4809 Floats[0] = std::move(z);
4810 Floats[1].makeZero(
false);
4814 Status |= Floats[0].add(zz, RM);
4816 Floats[1].makeZero(
false);
4819 Floats[1] = std::move(z);
4820 Status |= Floats[1].subtract(Floats[0], RM);
4821 Status |= Floats[1].add(zz, RM);
4827 const DoubleAPFloat &RHS,
4847 LHS.isNegative() !=
RHS.isNegative()) {
4848 Out.makeNaN(
false, Out.isNegative(),
nullptr);
4869 return Out.addImpl(
A, AA,
C,
CC, RM);
4874 return addWithSpecial(*
this,
RHS, *
this, RM);
4887 const auto &
LHS = *
this;
4914 Out.makeNaN(
false,
false,
nullptr);
4926 "Special cases not handled exhaustively");
4933 if (!
T.isFiniteNonZero()) {
4935 Floats[1].makeZero(
false);
4957 Status |= U.add(Tau, RM);
4960 if (!U.isFinite()) {
4961 Floats[1].makeZero(
false);
5020 Floats[0].changeSign();
5021 Floats[1].changeSign();
5026 auto Result = Floats[0].compareAbsoluteValue(
RHS.Floats[0]);
5029 Result = Floats[1].compareAbsoluteValue(
RHS.Floats[1]);
5031 auto Against = Floats[0].isNegative() ^ Floats[1].isNegative();
5032 auto RHSAgainst =
RHS.Floats[0].isNegative() ^
RHS.Floats[1].isNegative();
5033 if (Against && !RHSAgainst)
5035 if (!Against && RHSAgainst)
5037 if (!Against && !RHSAgainst)
5039 if (Against && RHSAgainst)
5046 return Floats[0].getCategory();
5052 Floats[0].makeInf(Neg);
5053 Floats[1].makeZero(
false);
5057 Floats[0].makeZero(Neg);
5058 Floats[1].makeZero(
false);
5071 Floats[0].makeSmallest(Neg);
5072 Floats[1].makeZero(
false);
5079 Floats[0].changeSign();
5080 Floats[1].makeZero(
false);
5084 Floats[0].makeNaN(SNaN, Neg, fill);
5085 Floats[1].makeZero(
false);
5089 auto Result = Floats[0].compare(
RHS.Floats[0]);
5092 return Floats[1].compare(
RHS.Floats[1]);
5097 return Floats[0].bitwiseIsEqual(
RHS.Floats[0]) &&
5098 Floats[1].bitwiseIsEqual(
RHS.Floats[1]);
5110 Floats[0].bitcastToAPInt().getRawData()[0],
5111 Floats[1].bitcastToAPInt().getRawData()[0],
5128 auto Ret = Tmp.
next(nextDown);
5135 unsigned int Width,
bool IsSigned,
5154 unsigned int InputSize,
5165 unsigned int InputSize,
5175 unsigned int HexDigits,
5185 (Floats[0].isDenormal() || Floats[1].isDenormal() ||
5187 Floats[0] != Floats[0] + Floats[1]);
5217 return Floats[0].isInteger() && Floats[1].isInteger();
5221 unsigned FormatPrecision,
5222 unsigned FormatMaxPadding,
5223 bool TruncateZero)
const {
5226 .
toString(Str, FormatPrecision, FormatMaxPadding, TruncateZero);
5254 scalbn(Arg.Floats[1], Exp, RM));
5261 APFloat Second = Arg.Floats[1];
5263 Second =
scalbn(Second, -Exp, RM);
5269APFloat::Storage::Storage(IEEEFloat
F,
const fltSemantics &Semantics) {
5270 if (usesLayout<IEEEFloat>(Semantics)) {
5271 new (&
IEEE) IEEEFloat(std::move(
F));
5274 if (usesLayout<DoubleAPFloat>(Semantics)) {
5277 DoubleAPFloat(Semantics,
APFloat(std::move(
F), S),
5290 if (APFloat::usesLayout<detail::IEEEFloat>(Arg.
getSemantics()))
5292 if (APFloat::usesLayout<detail::DoubleAPFloat>(Arg.
getSemantics()))
5300 assert(StatusOrErr &&
"Invalid floating point representation");
5324 usesLayout<IEEEFloat>(ToSemantics))
5325 return U.IEEE.convert(ToSemantics, RM, losesInfo);
5327 usesLayout<DoubleAPFloat>(ToSemantics)) {
5330 *
this =
APFloat(ToSemantics, U.IEEE.bitcastToAPInt());
5334 usesLayout<IEEEFloat>(ToSemantics)) {
5335 auto Ret = getIEEE().
convert(ToSemantics, RM, losesInfo);
5336 *
this =
APFloat(std::move(getIEEE()), ToSemantics);
5349 OS << Buffer <<
"\n";
5352#if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
5366 bool *isExact)
const {
5370 rounding_mode, isExact);
5372 result =
APInt(bitWidth, parts);
5380 "Float semantics is not representable by IEEEdouble");
5389#ifdef HAS_IEE754_FLOAT128
5390float128 APFloat::convertToQuad()
const {
5392 return getIEEE().convertToQuad();
5394 "Float semantics is not representable by IEEEquad");
5400 return Temp.getIEEE().convertToQuad();
5408 "Float semantics is not representable by IEEEsingle");
5419#undef APFLOAT_DISPATCH_ON_SEMANTICS
#define PackCategoriesIntoKey(_lhs, _rhs)
A macro used to combine two fcCategory enums into one key which can be used in a switch statement to ...
This file declares a class to represent arbitrary precision floating point values and provide a varie...
#define APFLOAT_DISPATCH_ON_SEMANTICS(METHOD_CALL)
This file implements the APSInt class, which is a simple class that represents an arbitrary sized int...
static GCRegistry::Add< OcamlGC > B("ocaml", "ocaml 3.10-compatible GC")
static GCRegistry::Add< ErlangGC > A("erlang", "erlang-compatible garbage collector")
static GCRegistry::Add< StatepointGC > D("statepoint-example", "an example strategy for statepoint")
#define LLVM_DUMP_METHOD
Mark debug helper function definitions like dump() that should not be stripped from debug builds.
static bool isNeg(Value *V)
Returns true if the operation is a negation of V, and it works for both integers and floats.
Looks at all the uses of the given value Returns the Liveness deduced from the uses of this value Adds all uses that cause the result to be MaybeLive to MaybeLiveRetUses If the result is MaybeLiveUses might be modified but its content should be ignored(since it might not be complete). DeadArgumentEliminationPass
Given that RA is a live value
static GCMetadataPrinterRegistry::Add< ErlangGCPrinter > X("erlang", "erlang-compatible garbage collector")
static bool isSigned(unsigned int Opcode)
Utilities for dealing with flags related to floating point properties and mode controls.
This file defines a hash set that can be used to remove duplication of nodes in a graph.
static bool isZero(Value *V, const DataLayout &DL, DominatorTree *DT, AssumptionCache *AC)
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
void Profile(FoldingSetNodeID &NID) const
Used to insert APFloat objects, or objects that contain APFloat objects, into FoldingSets.
opStatus divide(const APFloat &RHS, roundingMode RM)
bool getExactInverse(APFloat *inv) const
opStatus convert(const fltSemantics &ToSemantics, roundingMode RM, bool *losesInfo)
double convertToDouble() const
Converts this APFloat to host double value.
void toString(SmallVectorImpl< char > &Str, unsigned FormatPrecision=0, unsigned FormatMaxPadding=3, bool TruncateZero=true) const
opStatus add(const APFloat &RHS, roundingMode RM)
static APFloat getAllOnesValue(const fltSemantics &Semantics)
Returns a float which is bitcasted from an all one value int.
const fltSemantics & getSemantics() const
opStatus convertFromSignExtendedInteger(const integerPart *Input, unsigned int InputSize, bool IsSigned, roundingMode RM)
opStatus convertFromAPInt(const APInt &Input, bool IsSigned, roundingMode RM)
unsigned int convertToHexString(char *DST, unsigned int HexDigits, bool UpperCase, roundingMode RM) const
float convertToFloat() const
Converts this APFloat to host float value.
opStatus fusedMultiplyAdd(const APFloat &Multiplicand, const APFloat &Addend, roundingMode RM)
opStatus remainder(const APFloat &RHS)
APInt bitcastToAPInt() const
opStatus convertToInteger(MutableArrayRef< integerPart > Input, unsigned int Width, bool IsSigned, roundingMode RM, bool *IsExact) const
opStatus next(bool nextDown)
FPClassTest classify() const
Return the FPClassTest which will return true for the value.
opStatus mod(const APFloat &RHS)
Expected< opStatus > convertFromString(StringRef, roundingMode)
void print(raw_ostream &) const
opStatus roundToIntegral(roundingMode RM)
opStatus convertFromZeroExtendedInteger(const integerPart *Input, unsigned int InputSize, bool IsSigned, roundingMode RM)
Class for arbitrary precision integers.
APInt udiv(const APInt &RHS) const
Unsigned division operation.
static void tcSetBit(WordType *, unsigned bit)
Set the given bit of a bignum. Zero-based.
static APInt getAllOnes(unsigned numBits)
Return an APInt of a specified width with all bits set.
static void tcSet(WordType *, WordType, unsigned)
Sets the least significant part of a bignum to the input value, and zeroes out higher parts.
static void udivrem(const APInt &LHS, const APInt &RHS, APInt &Quotient, APInt &Remainder)
Dual division/remainder interface.
static int tcExtractBit(const WordType *, unsigned bit)
Extract the given bit of a bignum; returns 0 or 1. Zero-based.
APInt zext(unsigned width) const
Zero extend to a new width.
static WordType tcAdd(WordType *, const WordType *, WordType carry, unsigned)
DST += RHS + CARRY where CARRY is zero or one. Returns the carry flag.
static void tcExtract(WordType *, unsigned dstCount, const WordType *, unsigned srcBits, unsigned srcLSB)
Copy the bit vector of width srcBITS from SRC, starting at bit srcLSB, to DST, of dstCOUNT parts,...
unsigned getActiveBits() const
Compute the number of active bits in the value.
APInt trunc(unsigned width) const
Truncate to new width.
static int tcCompare(const WordType *, const WordType *, unsigned)
Comparison (unsigned) of two bignums.
static APInt floatToBits(float V)
Converts a float to APInt bits.
static void tcAssign(WordType *, const WordType *, unsigned)
Assign one bignum to another.
unsigned getBitWidth() const
Return the number of bits in the APInt.
static void tcShiftRight(WordType *, unsigned Words, unsigned Count)
Shift a bignum right Count bits.
static void tcFullMultiply(WordType *, const WordType *, const WordType *, unsigned, unsigned)
DST = LHS * RHS, where DST has width the sum of the widths of the operands.
unsigned getNumWords() const
Get the number of words.
bool isNegative() const
Determine sign of this APInt.
static void tcClearBit(WordType *, unsigned bit)
Clear the given bit of a bignum. Zero-based.
static WordType tcDecrement(WordType *dst, unsigned parts)
Decrement a bignum in-place. Return the borrow flag.
unsigned countr_zero() const
Count the number of trailing zero bits.
static unsigned tcLSB(const WordType *, unsigned n)
Returns the bit number of the least or most significant set bit of a number.
static void tcShiftLeft(WordType *, unsigned Words, unsigned Count)
Shift a bignum left Count bits.
static bool tcIsZero(const WordType *, unsigned)
Returns true if a bignum is zero, false otherwise.
static unsigned tcMSB(const WordType *parts, unsigned n)
Returns the bit number of the most significant set bit of a number.
@ APINT_BITS_PER_WORD
Bits in a word.
float bitsToFloat() const
Converts APInt bits to a float.
static int tcMultiplyPart(WordType *dst, const WordType *src, WordType multiplier, WordType carry, unsigned srcParts, unsigned dstParts, bool add)
DST += SRC * MULTIPLIER + PART if add is true DST = SRC * MULTIPLIER + PART if add is false.
static WordType tcSubtract(WordType *, const WordType *, WordType carry, unsigned)
DST -= RHS + CARRY where CARRY is zero or one. Returns the carry flag.
static void tcNegate(WordType *, unsigned)
Negate a bignum in-place.
static APInt doubleToBits(double V)
Converts a double to APInt bits.
static WordType tcIncrement(WordType *dst, unsigned parts)
Increment a bignum in-place. Return the carry flag.
double bitsToDouble() const
Converts APInt bits to a double.
const uint64_t * getRawData() const
This function returns a pointer to the internal storage of the APInt.
static APInt getZero(unsigned numBits)
Get the '0' value for the specified bit-width.
void lshrInPlace(unsigned ShiftAmt)
Logical right-shift this APInt by ShiftAmt in place.
An arbitrary precision integer that knows its signedness.
ArrayRef - Represent a constant reference to an array (0 or more elements consecutively in memory),...
size_t size() const
size - Get the array size.
Lightweight error class with error context and mandatory checking.
static ErrorSuccess success()
Create a success value.
Tagged union holding either a T or a Error.
FoldingSetNodeID - This class is used to gather all the unique data bits of a node.
MutableArrayRef - Represent a mutable reference to an array (0 or more elements consecutively in memo...
This class consists of common code factored out of the SmallVector class to reduce code duplication b...
iterator erase(const_iterator CI)
void append(ItTy in_start, ItTy in_end)
Add the specified range to the end of the SmallVector.
void push_back(const T &Elt)
This is a 'vector' (really, a variable-sized array), optimized for the case when the array is small.
StringRef - Represent a constant reference to a string, i.e.
bool getAsInteger(unsigned Radix, T &Result) const
Parse the current string as an integer of the specified radix.
bool starts_with(StringRef Prefix) const
Check if this string starts with the given Prefix.
constexpr bool empty() const
empty - Check if the string is empty.
StringRef drop_front(size_t N=1) const
Return a StringRef equal to 'this' but with the first N elements dropped.
char back() const
back - Get the last character in the string.
StringRef slice(size_t Start, size_t End) const
Return a reference to the substring from [Start, End).
constexpr size_t size() const
size - Get the string size.
char front() const
front - Get the first character in the string.
Twine - A lightweight data structure for efficiently representing the concatenation of temporary valu...
void makeSmallestNormalized(bool Neg)
DoubleAPFloat & operator=(const DoubleAPFloat &RHS)
LLVM_READONLY int getExactLog2() const
opStatus remainder(const DoubleAPFloat &RHS)
opStatus multiply(const DoubleAPFloat &RHS, roundingMode RM)
fltCategory getCategory() const
bool bitwiseIsEqual(const DoubleAPFloat &RHS) const
LLVM_READONLY int getExactLog2Abs() const
opStatus convertFromAPInt(const APInt &Input, bool IsSigned, roundingMode RM)
opStatus convertFromZeroExtendedInteger(const integerPart *Input, unsigned int InputSize, bool IsSigned, roundingMode RM)
APInt bitcastToAPInt() const
bool getExactInverse(APFloat *inv) const
Expected< opStatus > convertFromString(StringRef, roundingMode)
opStatus subtract(const DoubleAPFloat &RHS, roundingMode RM)
cmpResult compareAbsoluteValue(const DoubleAPFloat &RHS) const
opStatus convertToInteger(MutableArrayRef< integerPart > Input, unsigned int Width, bool IsSigned, roundingMode RM, bool *IsExact) const
void makeSmallest(bool Neg)
opStatus next(bool nextDown)
opStatus divide(const DoubleAPFloat &RHS, roundingMode RM)
bool isSmallestNormalized() const
opStatus mod(const DoubleAPFloat &RHS)
DoubleAPFloat(const fltSemantics &S)
void toString(SmallVectorImpl< char > &Str, unsigned FormatPrecision, unsigned FormatMaxPadding, bool TruncateZero=true) const
void makeLargest(bool Neg)
cmpResult compare(const DoubleAPFloat &RHS) const
opStatus roundToIntegral(roundingMode RM)
opStatus convertFromSignExtendedInteger(const integerPart *Input, unsigned int InputSize, bool IsSigned, roundingMode RM)
opStatus fusedMultiplyAdd(const DoubleAPFloat &Multiplicand, const DoubleAPFloat &Addend, roundingMode RM)
unsigned int convertToHexString(char *DST, unsigned int HexDigits, bool UpperCase, roundingMode RM) const
opStatus add(const DoubleAPFloat &RHS, roundingMode RM)
void makeNaN(bool SNaN, bool Neg, const APInt *fill)
unsigned int convertToHexString(char *dst, unsigned int hexDigits, bool upperCase, roundingMode) const
Write out a hexadecimal representation of the floating point value to DST, which must be of sufficien...
fltCategory getCategory() const
bool isFiniteNonZero() const
opStatus add(const IEEEFloat &, roundingMode)
bool needsCleanup() const
Returns whether this instance allocated memory.
APInt bitcastToAPInt() const
bool isNegative() const
IEEE-754R isSignMinus: Returns true if and only if the current value is negative.
opStatus convertFromZeroExtendedInteger(const integerPart *, unsigned int, bool, roundingMode)
bool isNaN() const
Returns true if and only if the float is a quiet or signaling NaN.
opStatus convertFromAPInt(const APInt &, bool, roundingMode)
opStatus roundToIntegral(roundingMode)
double convertToDouble() const
float convertToFloat() const
cmpResult compareAbsoluteValue(const IEEEFloat &) const
opStatus fusedMultiplyAdd(const IEEEFloat &, const IEEEFloat &, roundingMode)
void makeInf(bool Neg=false)
Expected< opStatus > convertFromString(StringRef, roundingMode)
bool isSmallestNormalized() const
Returns true if this is the smallest (by magnitude) normalized finite number in the given semantics.
bool isLargest() const
Returns true if and only if the number has the largest possible finite magnitude in the current seman...
bool isFinite() const
Returns true if and only if the current value is zero, subnormal, or normal.
void makeNaN(bool SNaN=false, bool Neg=false, const APInt *fill=nullptr)
opStatus convertToInteger(MutableArrayRef< integerPart >, unsigned int, bool, roundingMode, bool *) const
friend int ilogb(const IEEEFloat &Arg)
Returns the exponent of the internal representation of the APFloat.
opStatus remainder(const IEEEFloat &)
IEEE remainder.
IEEEFloat & operator=(const IEEEFloat &)
opStatus divide(const IEEEFloat &, roundingMode)
friend IEEEFloat scalbn(IEEEFloat X, int Exp, roundingMode)
Returns: X * 2^Exp for integral exponents.
bool bitwiseIsEqual(const IEEEFloat &) const
Bitwise comparison for equality (QNaNs compare equal, 0!=-0).
bool isInteger() const
Returns true if and only if the number is an exact integer.
IEEEFloat(const fltSemantics &)
cmpResult compare(const IEEEFloat &) const
IEEE comparison with another floating point number (NaNs compare unordered, 0==-0).
opStatus subtract(const IEEEFloat &, roundingMode)
bool isInfinity() const
IEEE-754R isInfinite(): Returns true if and only if the float is infinity.
const fltSemantics & getSemantics() const
bool isZero() const
Returns true if and only if the float is plus or minus zero.
bool isSignaling() const
Returns true if and only if the float is a signaling NaN.
opStatus convertFromSignExtendedInteger(const integerPart *, unsigned int, bool, roundingMode)
opStatus convert(const fltSemantics &, roundingMode, bool *)
IEEEFloat::convert - convert a value of one floating point type to another.
void makeZero(bool Neg=false)
bool isDenormal() const
IEEE-754R isSubnormal(): Returns true if and only if the float is a denormal.
bool isSmallest() const
Returns true if and only if the number has the smallest possible non-zero magnitude in the current se...
opStatus mod(const IEEEFloat &)
C fmod, or llvm frem.
opStatus multiply(const IEEEFloat &, roundingMode)
An opaque object representing a hash code.
This class implements an extremely fast bulk output stream that can only output to a stream.
#define llvm_unreachable(msg)
Marks that the current location is not supposed to be reachable.
@ C
The default llvm calling convention, compatible with C.
IEEEFloat scalbn(IEEEFloat X, int Exp, IEEEFloat::roundingMode)
static void tcSetLeastSignificantBits(APInt::WordType *dst, unsigned parts, unsigned bits)
hash_code hash_value(const IEEEFloat &Arg)
IEEEFloat frexp(const IEEEFloat &Val, int &Exp, IEEEFloat::roundingMode RM)
int ilogb(const IEEEFloat &Arg)
std::error_code status(const Twine &path, file_status &result, bool follow=true)
Get file status as if by POSIX stat().
This is an optimization pass for GlobalISel generic memory operations.
static unsigned int partAsHex(char *dst, APFloatBase::integerPart part, unsigned int count, const char *hexDigitChars)
static constexpr fltSemantics semBogus
static const char infinityL[]
bool all_of(R &&range, UnaryPredicate P)
Provide wrappers to std::all_of which take ranges instead of having to pass begin/end explicitly.
hash_code hash_value(const FixedPointSemantics &Val)
int popcount(T Value) noexcept
Count the number of set bits in a value.
static constexpr unsigned int partCountForBits(unsigned int bits)
static unsigned int HUerrBound(bool inexactMultiply, unsigned int HUerr1, unsigned int HUerr2)
static unsigned int powerOf5(APFloatBase::integerPart *dst, unsigned int power)
static constexpr fltSemantics semFloat6E2M3FN
static constexpr APFloatBase::ExponentType exponentZero(const fltSemantics &semantics)
static Expected< int > totalExponent(StringRef::iterator p, StringRef::iterator end, int exponentAdjustment)
std::error_code inconvertibleErrorCode()
The value returned by this function can be returned from convertToErrorCode for Error values where no...
static constexpr fltSemantics semIEEEquad
const unsigned int maxPowerOfFiveExponent
static constexpr fltSemantics semFloat6E3M2FN
static char * writeUnsignedDecimal(char *dst, unsigned int n)
static constexpr fltSemantics semFloat8E4M3FNUZ
const unsigned int maxPrecision
static constexpr fltSemantics semIEEEdouble
APFloat frexp(const APFloat &X, int &Exp, APFloat::roundingMode RM)
Equivalent of C standard library function.
int countr_zero(T Val)
Count number of 0's from the least significant bit to the most stopping at the first 1.
static constexpr fltSemantics semFloat8E4M3FN
static const char infinityU[]
lostFraction
Enum that represents what fraction of the LSB truncated bits of an fp number represent.
static constexpr fltSemantics semPPCDoubleDouble
static Error interpretDecimal(StringRef::iterator begin, StringRef::iterator end, decimalInfo *D)
static constexpr fltSemantics semFloat8E5M2FNUZ
bool isFinite(const Loop *L)
Return true if this loop can be assumed to run for a finite number of iterations.
FPClassTest
Floating-point class tests, supported by 'is_fpclass' intrinsic.
const unsigned int maxPowerOfFiveParts
static constexpr fltSemantics semIEEEsingle
APFloat scalbn(APFloat X, int Exp, APFloat::roundingMode RM)
static constexpr fltSemantics semFloat4E2M1FN
raw_ostream & dbgs()
dbgs() - This returns a reference to a raw_ostream for debugging messages.
static constexpr APFloatBase::ExponentType exponentNaN(const fltSemantics &semantics)
static Error createError(const Twine &Err)
static constexpr fltSemantics semIEEEhalf
static constexpr fltSemantics semPPCDoubleDoubleLegacy
static lostFraction shiftRight(APFloatBase::integerPart *dst, unsigned int parts, unsigned int bits)
static constexpr fltSemantics semFloat8E5M2
@ First
Helpers to iterate all locations in the MemoryEffectsBase class.
static const char hexDigitsUpper[]
const unsigned int maxExponent
static unsigned int decDigitValue(unsigned int c)
static constexpr fltSemantics semFloat8E4M3B11FNUZ
auto count(R &&Range, const E &Element)
Wrapper function around std::count to count the number of times an element Element occurs in the give...
static lostFraction combineLostFractions(lostFraction moreSignificant, lostFraction lessSignificant)
static Expected< StringRef::iterator > skipLeadingZeroesAndAnyDot(StringRef::iterator begin, StringRef::iterator end, StringRef::iterator *dot)
RoundingMode
Rounding mode.
OutputIt copy(R &&Range, OutputIt Out)
static constexpr fltSemantics semX87DoubleExtended
OutputIt move(R &&Range, OutputIt Out)
Provide wrappers to std::move which take ranges instead of having to pass begin/end explicitly.
static constexpr fltSemantics semFloatTF32
static constexpr APFloatBase::ExponentType exponentInf(const fltSemantics &semantics)
static lostFraction lostFractionThroughTruncation(const APFloatBase::integerPart *parts, unsigned int partCount, unsigned int bits)
static APFloatBase::integerPart ulpsFromBoundary(const APFloatBase::integerPart *parts, unsigned int bits, bool isNearest)
static char * writeSignedDecimal(char *dst, int value)
hash_code hash_combine(const Ts &...args)
Combine values into a single hash_code.
static constexpr fltSemantics semBFloat
static Expected< lostFraction > trailingHexadecimalFraction(StringRef::iterator p, StringRef::iterator end, unsigned int digitValue)
void consumeError(Error Err)
Consume a Error without doing anything.
static Expected< int > readExponent(StringRef::iterator begin, StringRef::iterator end)
hash_code hash_combine_range(InputIteratorT first, InputIteratorT last)
Compute a hash_code for a sequence of values.
static constexpr fltSemantics semFloat8E4M3
constexpr uint64_t NextPowerOf2(uint64_t A)
Returns the next power of two (in 64-bits) that is strictly greater than A.
static const char hexDigitsLower[]
Implement std::hash so that hash_code can be used in STL containers.
static const llvm::fltSemantics & EnumToSemantics(Semantics S)
static const fltSemantics & IEEEsingle() LLVM_READNONE
static const fltSemantics & Float6E3M2FN() LLVM_READNONE
static constexpr roundingMode rmNearestTiesToAway
cmpResult
IEEE-754R 5.11: Floating Point Comparison Relations.
static constexpr roundingMode rmTowardNegative
static ExponentType semanticsMinExponent(const fltSemantics &)
static constexpr roundingMode rmNearestTiesToEven
static unsigned int semanticsSizeInBits(const fltSemantics &)
static const fltSemantics & Float8E4M3() LLVM_READNONE
static unsigned getSizeInBits(const fltSemantics &Sem)
Returns the size of the floating point number (in bits) in the given semantics.
static const fltSemantics & Float8E4M3FN() LLVM_READNONE
static const fltSemantics & PPCDoubleDouble() LLVM_READNONE
static constexpr roundingMode rmTowardZero
static const fltSemantics & x87DoubleExtended() LLVM_READNONE
uninitializedTag
Convenience enum used to construct an uninitialized APFloat.
static const fltSemantics & IEEEquad() LLVM_READNONE
static const fltSemantics & Float4E2M1FN() LLVM_READNONE
static const fltSemantics & Float8E4M3B11FNUZ() LLVM_READNONE
static const fltSemantics & Bogus() LLVM_READNONE
A Pseudo fltsemantic used to construct APFloats that cannot conflict with anything real.
static ExponentType semanticsMaxExponent(const fltSemantics &)
static unsigned int semanticsPrecision(const fltSemantics &)
static const fltSemantics & IEEEdouble() LLVM_READNONE
static const fltSemantics & Float8E5M2() LLVM_READNONE
static Semantics SemanticsToEnum(const llvm::fltSemantics &Sem)
static constexpr unsigned integerPartWidth
static const fltSemantics & IEEEhalf() LLVM_READNONE
APInt::WordType integerPart
static constexpr roundingMode rmTowardPositive
static bool isRepresentableAsNormalIn(const fltSemantics &Src, const fltSemantics &Dst)
static const fltSemantics & Float8E4M3FNUZ() LLVM_READNONE
static const fltSemantics & BFloat() LLVM_READNONE
static const fltSemantics & FloatTF32() LLVM_READNONE
static const fltSemantics & Float8E5M2FNUZ() LLVM_READNONE
static const fltSemantics & Float6E2M3FN() LLVM_READNONE
fltCategory
Category of internally-represented number.
opStatus
IEEE-754R 7: Default exception handling.
int32_t ExponentType
A signed type to represent a floating point numbers unbiased exponent.
static unsigned int semanticsIntSizeInBits(const fltSemantics &, bool)
const char * lastSigDigit
const char * firstSigDigit
bool isRepresentableBy(const fltSemantics &S) const
APFloatBase::ExponentType maxExponent
fltNonfiniteBehavior nonFiniteBehavior
APFloatBase::ExponentType minExponent
fltNanEncoding nanEncoding