24#include "llvm/Config/llvm-config.h"
32#define APFLOAT_DISPATCH_ON_SEMANTICS(METHOD_CALL) \
34 if (usesLayout<IEEEFloat>(getSemantics())) \
35 return U.IEEE.METHOD_CALL; \
36 if (usesLayout<DoubleAPFloat>(getSemantics())) \
37 return U.Double.METHOD_CALL; \
38 llvm_unreachable("Unexpected semantics"); \
49#define PackCategoriesIntoKey(_lhs, _rhs) ((_lhs) * 4 + (_rhs))
57constexpr fltSemantics APFloatBase::semIEEEhalf = {15, -14, 11, 16};
58constexpr fltSemantics APFloatBase::semBFloat = {127, -126, 8, 16};
59constexpr fltSemantics APFloatBase::semIEEEsingle = {127, -126, 24, 32};
60constexpr fltSemantics APFloatBase::semIEEEdouble = {1023, -1022, 53, 64};
61constexpr fltSemantics APFloatBase::semIEEEquad = {16383, -16382, 113, 128};
62constexpr fltSemantics APFloatBase::semFloat8E5M2 = {15, -14, 3, 8};
65constexpr fltSemantics APFloatBase::semFloat8E4M3 = {7, -6, 4, 8};
70constexpr fltSemantics APFloatBase::semFloat8E4M3B11FNUZ = {
72constexpr fltSemantics APFloatBase::semFloat8E3M4 = {3, -2, 5, 8};
73constexpr fltSemantics APFloatBase::semFloatTF32 = {127, -126, 11, 19};
91constexpr fltSemantics APFloatBase::semX87DoubleExtended = {16383, -16382, 64,
93constexpr fltSemantics APFloatBase::semBogus = {0, 0, 0, 0};
94constexpr fltSemantics APFloatBase::semPPCDoubleDouble = {-1, 0, 0, 128};
95constexpr fltSemantics APFloatBase::semPPCDoubleDoubleLegacy = {
96 1023, -1022 + 53, 53 + 53, 128};
192 return A.maxExponent <=
B.maxExponent &&
A.minExponent >=
B.minExponent &&
193 A.precision <=
B.precision;
267 if (Src.maxExponent >= Dst.maxExponent || Src.minExponent <= Dst.minExponent)
275 return Dst.precision >= Src.precision;
315static inline unsigned int
328 const unsigned int overlargeExponent = 24000;
332 if (p == end || ((*p ==
'-' || *p ==
'+') && (p + 1) == end))
335 bool isNegative = *p ==
'-';
336 if (*p ==
'-' || *p ==
'+') {
343 if (absExponent >= 10U)
344 return createError(
"Invalid character in exponent");
346 for (; p != end; ++p) {
349 return createError(
"Invalid character in exponent");
351 absExponent = absExponent * 10U + value;
352 if (absExponent >= overlargeExponent) {
353 absExponent = overlargeExponent;
359 return -(int) absExponent;
361 return (
int) absExponent;
368 int exponentAdjustment) {
374 bool negative = *p ==
'-';
375 if (*p ==
'-' || *p ==
'+') {
381 int unsignedExponent = 0;
382 bool overflow =
false;
383 for (; p != end; ++p) {
388 return createError(
"Invalid character in exponent");
390 unsignedExponent = unsignedExponent * 10 + value;
391 if (unsignedExponent > 32767) {
397 if (exponentAdjustment > 32767 || exponentAdjustment < -32768)
401 exponent = unsignedExponent;
403 exponent = -exponent;
404 exponent += exponentAdjustment;
405 if (exponent > 32767 || exponent < -32768)
410 exponent = negative ? -32768: 32767;
420 while (p != end && *p ==
'0')
423 if (p != end && *p ==
'.') {
426 if (end - begin == 1)
429 while (p != end && *p ==
'0')
462 return PtrOrErr.takeError();
465 D->firstSigDigit = p;
467 D->normalizedExponent = 0;
469 for (; p != end; ++p) {
472 return createError(
"String contains multiple dots");
482 if (*p !=
'e' && *p !=
'E')
483 return createError(
"Invalid character in significand");
486 if (dot != end && p - begin == 1)
492 return ExpOrErr.takeError();
493 D->exponent = *ExpOrErr;
501 if (p !=
D->firstSigDigit) {
507 while (p != begin && *p ==
'0');
508 while (p != begin && *p ==
'.');
513 D->normalizedExponent = (
D->exponent +
515 - (dot >
D->firstSigDigit && dot < p)));
527 unsigned int digitValue) {
532 else if (digitValue < 8 && digitValue > 0)
536 while (p != end && (*p ==
'0' || *p ==
'.'))
540 return createError(
"Invalid trailing hexadecimal fraction!");
546 if (hexDigit == UINT_MAX)
556 unsigned int partCount,
581 return lost_fraction;
596 return moreSignificant;
607HUerrBound(
bool inexactMultiply,
unsigned int HUerr1,
unsigned int HUerr2)
609 assert(HUerr1 < 2 || HUerr2 < 2 || (HUerr1 + HUerr2 < 8));
611 if (HUerr1 + HUerr2 == 0)
612 return inexactMultiply * 2;
614 return inexactMultiply + 2 * (HUerr1 + HUerr2);
640 if (part - boundary <= boundary - part)
641 return part - boundary;
643 return boundary - part;
646 if (part == boundary) {
652 }
else if (part == boundary - 1) {
669 pow5s[0] = 78125 * 5;
671 unsigned int partsCount = 1;
678 *p1 = firstEightPowers[power & 7];
684 for (
unsigned int n = 0; power; power >>= 1, n++) {
688 partsCount, partsCount);
690 if (pow5[partsCount - 1] == 0)
698 result += partsCount;
699 if (p2[result - 1] == 0)
724static const char NaNL[] =
"nan";
725static const char NaNU[] =
"NAN";
732 const char *hexDigitChars)
734 unsigned int result =
count;
740 dst[
count] = hexDigitChars[part & 0xf];
780 switch (
X.getCategory()) {
790 if (
X.isDenormal() ||
X.isSmallestNormalized())
793 if (
X.getExactLog2() != INT_MIN)
801void IEEEFloat::initialize(
const fltSemantics *ourSemantics) {
802 semantics = ourSemantics;
803 unsigned count = partCount();
808void IEEEFloat::freeSignificand() {
810 delete [] significand.parts;
813void IEEEFloat::assign(
const IEEEFloat &rhs) {
814 assert(semantics == rhs.semantics);
817 category = rhs.category;
818 exponent = rhs.exponent;
820 copySignificand(rhs);
823void IEEEFloat::copySignificand(
const IEEEFloat &rhs) {
825 assert(rhs.partCount() >= partCount());
838 if (Negative && !semantics->hasSignedRepr)
840 "This floating point format does not support signed values");
844 exponent = exponentNaN();
847 unsigned numParts = partCount();
860 fill = &fill_storage;
864 if (!
fill ||
fill->getNumWords() < numParts)
868 std::min(
fill->getNumWords(), numParts));
871 unsigned bitsToPreserve = semantics->precision - 1;
872 unsigned part = bitsToPreserve / 64;
873 bitsToPreserve %= 64;
874 significand[part] &= ((1ULL << bitsToPreserve) - 1);
875 for (part++; part != numParts; ++part)
876 significand[part] = 0;
880 (semantics->precision >= 2) ? (semantics->precision - 2) : 0;
902 if (semantics == &APFloatBase::semX87DoubleExtended)
908 if (semantics != rhs.semantics) {
910 initialize(rhs.semantics);
921 semantics = rhs.semantics;
922 significand = rhs.significand;
923 exponent = rhs.exponent;
924 category = rhs.category;
927 rhs.semantics = &APFloatBase::semBogus;
934 semantics->precision - 1) == 0);
942 significandMSB() == 0;
947 isSignificandAllZerosExceptMSB();
950unsigned int IEEEFloat::getNumHighBits()
const {
957 const unsigned int NumHighBits = (semantics->
precision > 1)
963bool IEEEFloat::isSignificandAllOnes()
const {
968 for (
unsigned i = 0; i < PartCount - 1; i++)
973 const unsigned NumHighBits = getNumHighBits();
974 assert(NumHighBits <= integerPartWidth && NumHighBits > 0 &&
975 "Can not have more high bits to fill than integerPartWidth");
978 if ((semantics->
precision <= 1) || (~(Parts[PartCount - 1] | HighBitFill)))
984bool IEEEFloat::isSignificandAllOnesExceptLSB()
const {
993 for (
unsigned i = 0; i < PartCount - 1; i++) {
994 if (~Parts[i] & ~
unsigned{!i})
999 const unsigned NumHighBits = getNumHighBits();
1000 assert(NumHighBits <= integerPartWidth && NumHighBits > 0 &&
1001 "Can not have more high bits to fill than integerPartWidth");
1004 if (~(Parts[PartCount - 1] | HighBitFill | 0x1))
1010bool IEEEFloat::isSignificandAllZeros()
const {
1016 for (
unsigned i = 0; i < PartCount - 1; i++)
1021 const unsigned NumHighBits = getNumHighBits();
1023 "clear than integerPartWidth");
1024 const integerPart HighBitMask = ~integerPart(0) >> NumHighBits;
1026 if ((semantics->precision > 1) && (Parts[PartCount - 1] & HighBitMask))
1032bool IEEEFloat::isSignificandAllZerosExceptMSB()
const {
1036 for (
unsigned i = 0; i < PartCount - 1; i++) {
1041 const unsigned NumHighBits = getNumHighBits();
1044 return ((semantics->precision <= 1) || (Parts[PartCount - 1] == MSBMask));
1048 bool IsMaxExp =
isFiniteNonZero() && exponent == semantics->maxExponent;
1055 ? isSignificandAllOnesExceptLSB()
1060 return IsMaxExp && isSignificandAllOnes();
1075 if (semantics != rhs.semantics ||
1076 category != rhs.category ||
1085 return std::equal(significandParts(), significandParts() + partCount(),
1086 rhs.significandParts());
1090 initialize(&ourSemantics);
1095 significandParts()[0] =
value;
1100 initialize(&ourSemantics);
1116 initialize(rhs.semantics);
1121 *
this = std::move(rhs);
1126unsigned int IEEEFloat::partCount()
const {
1131 return const_cast<IEEEFloat *
>(
this)->significandParts();
1135 if (partCount() > 1)
1136 return significand.parts;
1138 return &significand.part;
1141void IEEEFloat::zeroSignificand() {
1146void IEEEFloat::incrementSignificand() {
1158 assert(semantics == rhs.semantics);
1159 assert(exponent == rhs.exponent);
1161 return APInt::tcAdd(parts, rhs.significandParts(), 0, partCount());
1170 assert(semantics == rhs.semantics);
1171 assert(exponent == rhs.exponent);
1182 bool ignoreAddend) {
1186 assert(semantics == rhs.semantics);
1188 unsigned precision = semantics->precision;
1196 newPartsCount > 4 ?
new integerPart[newPartsCount] : scratch;
1199 unsigned partsCount = partCount();
1202 rhs.significandParts(), partsCount, partsCount);
1206 unsigned omsb =
APInt::tcMSB(fullSignificand, newPartsCount) + 1;
1207 exponent += rhs.exponent;
1221 if (!ignoreAddend && addend.isNonZero()) {
1225 Significand savedSignificand = significand;
1226 const fltSemantics *savedSemantics = semantics;
1229 unsigned extendedPrecision = 2 * precision + 1;
1230 if (omsb != extendedPrecision - 1) {
1231 assert(extendedPrecision > omsb);
1233 (extendedPrecision - 1) - omsb);
1234 exponent -= (extendedPrecision - 1) - omsb;
1238 fltSemantics extendedSemantics = *semantics;
1239 extendedSemantics.
precision = extendedPrecision;
1241 if (newPartsCount == 1)
1242 significand.part = fullSignificand[0];
1244 significand.parts = fullSignificand;
1245 semantics = &extendedSemantics;
1258 lost_fraction = extendedAddend.shiftSignificandRight(1);
1260 "Lost precision while shifting addend for fused-multiply-add.");
1262 lost_fraction = addOrSubtractSignificand(extendedAddend,
false);
1265 if (newPartsCount == 1)
1266 fullSignificand[0] = significand.part;
1267 significand = savedSignificand;
1268 semantics = savedSemantics;
1270 omsb =
APInt::tcMSB(fullSignificand, newPartsCount) + 1;
1277 exponent -= precision + 1;
1286 if (omsb > precision) {
1287 unsigned int bits, significantParts;
1290 bits = omsb - precision;
1292 lf =
shiftRight(fullSignificand, significantParts, bits);
1299 if (newPartsCount > 4)
1300 delete [] fullSignificand;
1302 return lost_fraction;
1311 return multiplySignificand(rhs,
IEEEFloat(*semantics), !semantics->hasZero);
1318 assert(semantics == rhs.semantics);
1321 const integerPart *rhsSignificand = rhs.significandParts();
1322 unsigned partsCount = partCount();
1325 partsCount > 2 ?
new integerPart[partsCount * 2] : scratch;
1329 for (
unsigned i = 0; i < partsCount; i++) {
1330 dividend[i] = lhsSignificand[i];
1331 divisor[i] = rhsSignificand[i];
1332 lhsSignificand[i] = 0;
1335 exponent -= rhs.exponent;
1337 unsigned int precision = semantics->precision;
1340 unsigned bit = precision -
APInt::tcMSB(divisor, partsCount) - 1;
1347 bit = precision -
APInt::tcMSB(dividend, partsCount) - 1;
1363 for (bit = precision; bit; bit -= 1) {
1388 return lost_fraction;
1391unsigned int IEEEFloat::significandMSB()
const {
1395unsigned int IEEEFloat::significandLSB()
const {
1400lostFraction IEEEFloat::shiftSignificandRight(
unsigned int bits) {
1406 return shiftRight(significandParts(), partCount(), bits);
1410void IEEEFloat::shiftSignificandLeft(
unsigned int bits) {
1411 assert(bits < semantics->precision ||
1412 (semantics->precision == 1 && bits <= 1));
1415 unsigned int partsCount = partCount();
1425 assert(semantics == rhs.semantics);
1429 int compare = exponent - rhs.exponent;
1481 exponent = semantics->maxExponent;
1483 semantics->precision);
1496bool IEEEFloat::roundAwayFromZero(
roundingMode rounding_mode,
1498 unsigned int bit)
const {
1505 switch (rounding_mode) {
1541 unsigned omsb = significandMSB() + 1;
1548 int exponentChange = omsb - semantics->precision;
1552 if (exponent + exponentChange > semantics->maxExponent)
1553 return handleOverflow(rounding_mode);
1557 if (exponent + exponentChange < semantics->minExponent)
1558 exponentChange = semantics->minExponent - exponent;
1561 if (exponentChange < 0) {
1564 shiftSignificandLeft(-exponentChange);
1569 if (exponentChange > 0) {
1573 lf = shiftSignificandRight(exponentChange);
1578 if (omsb > (
unsigned) exponentChange)
1579 omsb -= exponentChange;
1589 exponent == semantics->maxExponent && isSignificandAllOnes())
1590 return handleOverflow(rounding_mode);
1603 if (!semantics->hasZero)
1611 if (roundAwayFromZero(rounding_mode, lost_fraction, 0)) {
1613 exponent = semantics->minExponent;
1615 incrementSignificand();
1616 omsb = significandMSB() + 1;
1619 if (omsb == (
unsigned) semantics->precision + 1) {
1623 if (exponent == semantics->maxExponent)
1630 shiftSignificandRight(1);
1639 exponent == semantics->maxExponent && isSignificandAllOnes())
1640 return handleOverflow(rounding_mode);
1645 if (omsb == semantics->precision)
1649 assert(omsb < semantics->precision);
1659 if (!semantics->hasZero)
1731 subtract ^=
static_cast<bool>(sign ^ rhs.sign);
1734 int bits = exponent - rhs.exponent;
1738 if ((bits < 0) && !semantics->hasSignedRepr)
1740 "This floating point format does not support signed values");
1743 bool lost_fraction_is_from_rhs =
false;
1747 else if (bits > 0) {
1748 lost_fraction = temp_rhs.shiftSignificandRight(bits - 1);
1749 lost_fraction_is_from_rhs =
true;
1750 shiftSignificandLeft(1);
1752 lost_fraction = shiftSignificandRight(-bits - 1);
1753 temp_rhs.shiftSignificandLeft(1);
1760 lost_fraction !=
lfExactlyZero && !lost_fraction_is_from_rhs;
1769 carry = temp_rhs.subtractSignificand(*
this, borrow);
1770 copySignificand(temp_rhs);
1773 bool borrow = lost_fraction !=
lfExactlyZero && lost_fraction_is_from_rhs;
1782 carry = subtractSignificand(temp_rhs, borrow);
1785 if (lost_fraction !=
lfExactlyZero && lost_fraction_is_from_rhs) {
1798 lost_fraction = temp_rhs.shiftSignificandRight(bits);
1799 carry = addSignificand(temp_rhs);
1801 lost_fraction = shiftSignificandRight(-bits);
1802 carry = addSignificand(rhs);
1809 return lost_fraction;
2002 lost_fraction = addOrSubtractSignificand(rhs,
subtract);
2003 fs = normalize(rounding_mode, lost_fraction);
2012 if (category ==
fcZero) {
2026 return addOrSubtract(rhs, rounding_mode,
false);
2032 return addOrSubtract(rhs, rounding_mode,
true);
2045 fs = normalize(rounding_mode, lost_fraction);
2063 fs = normalize(rounding_mode, lost_fraction);
2073 unsigned int origSign = sign;
2182 unsigned int origSign = sign;
2203 if (!semantics->hasZero && this->isSmallest())
2223 sign ^= multiplicand.sign;
2232 lost_fraction = multiplySignificand(multiplicand, addend);
2233 fs = normalize(rounding_mode, lost_fraction);
2246 fs = multiplySpecials(multiplicand);
2256 fs = addOrSubtract(addend, rounding_mode,
false);
2328 MagicConstant.sign = sign;
2334 fs =
add(MagicConstant, rounding_mode);
2338 subtract(MagicConstant, rounding_mode);
2349 assert(semantics == rhs.semantics);
2381 if (sign == rhs.sign)
2397 if (sign != rhs.sign) {
2433 unsigned oldPartCount = partCount();
2436 bool X86SpecialNan =
false;
2437 if (&fromSemantics == &APFloatBase::semX87DoubleExtended &&
2438 &toSemantics != &APFloatBase::semX87DoubleExtended && category ==
fcNaN &&
2439 (!(*significandParts() & 0x8000000000000000ULL) ||
2440 !(*significandParts() & 0x4000000000000000ULL))) {
2443 X86SpecialNan =
true;
2454 int omsb = significandMSB() + 1;
2455 int exponentChange = omsb - fromSemantics.
precision;
2456 if (exponent + exponentChange < toSemantics.
minExponent)
2457 exponentChange = toSemantics.
minExponent - exponent;
2458 exponentChange = std::max(exponentChange, shift);
2459 if (exponentChange < 0) {
2460 shift -= exponentChange;
2461 exponent += exponentChange;
2462 }
else if (omsb <= -shift) {
2463 exponentChange = omsb + shift - 1;
2464 shift -= exponentChange;
2465 exponent += exponentChange;
2471 (category ==
fcNaN && semantics->nonFiniteBehavior !=
2476 if (newPartCount > oldPartCount) {
2484 significand.parts = newParts;
2485 }
else if (newPartCount == 1 && oldPartCount != 1) {
2489 newPart = significandParts()[0];
2491 significand.part = newPart;
2495 semantics = &toSemantics;
2504 *losesInfo = (
fs !=
opOK);
2505 }
else if (category ==
fcNaN) {
2523 if (!X86SpecialNan && semantics == &APFloatBase::semX87DoubleExtended)
2540 }
else if (category ==
fcZero &&
2553 if (category ==
fcZero && !semantics->hasZero)
2578 assert(dstPartsCount <= parts.
size() &&
"Integer too big");
2580 if (category ==
fcZero) {
2589 unsigned truncatedBits;
2597 truncatedBits = semantics->
precision -1U - exponent;
2601 unsigned int bits = exponent + 1U;
2607 if (bits < semantics->precision) {
2609 truncatedBits = semantics->
precision - bits;
2616 bits - semantics->precision);
2624 if (truncatedBits) {
2628 roundAwayFromZero(rounding_mode, lost_fraction, truncatedBits)) {
2648 if (omsb == width &&
2659 if (omsb >= width + !isSigned)
2681 unsigned int width,
bool isSigned,
2683 opStatus fs = convertToSignExtendedInteger(parts, width, isSigned,
2684 rounding_mode, isExact);
2687 unsigned int bits, dstPartsCount;
2690 assert(dstPartsCount <= parts.
size() &&
"Integer too big");
2692 if (category ==
fcNaN)
2697 bits = width - isSigned;
2700 if (sign && isSigned)
2715 unsigned dstCount = partCount();
2716 unsigned precision = semantics->
precision;
2721 if (precision <= omsb) {
2722 exponent = omsb - 1;
2727 exponent = precision - 1;
2732 return normalize(rounding_mode, lost_fraction);
2746 return convertFromUnsignedParts(api.
getRawData(), partCount, rounding_mode);
2750IEEEFloat::convertFromHexadecimalString(
StringRef s,
2759 unsigned partsCount = partCount();
2761 bool computedTrailingFraction =
false;
2769 return PtrOrErr.takeError();
2778 return createError(
"String contains multiple dots");
2784 if (hex_value == UINT_MAX)
2794 }
else if (!computedTrailingFraction) {
2797 return FractOrErr.takeError();
2798 lost_fraction = *FractOrErr;
2799 computedTrailingFraction =
true;
2805 return createError(
"Hex strings require an exponent");
2806 if (*p !=
'p' && *p !=
'P')
2807 return createError(
"Invalid character in significand");
2810 if (dot != end && p - begin == 1)
2814 if (p != firstSignificantDigit) {
2823 expAdjustment =
static_cast<int>(
dot - firstSignificantDigit);
2824 if (expAdjustment < 0)
2826 expAdjustment = expAdjustment * 4 - 1;
2830 expAdjustment += semantics->precision;
2836 return ExpOrErr.takeError();
2837 exponent = *ExpOrErr;
2840 return normalize(rounding_mode, lost_fraction);
2844IEEEFloat::roundSignificandWithExponent(
const integerPart *decSigParts,
2845 unsigned sigPartCount,
int exp,
2847 fltSemantics calcSemantics = { 32767, -32767, 0, 0 };
2856 unsigned pow5PartCount =
powerOf5(pow5Parts, exp >= 0 ? exp : -exp);
2858 for (;; parts *= 2) {
2860 unsigned int excessPrecision, truncatedBits;
2863 excessPrecision = calcSemantics.
precision - semantics->precision;
2864 truncatedBits = excessPrecision;
2867 decSig.makeZero(sign);
2870 sigStatus = decSig.convertFromUnsignedParts(decSigParts, sigPartCount,
2872 powStatus = pow5.convertFromUnsignedParts(pow5Parts, pow5PartCount,
2875 decSig.exponent += exp;
2879 unsigned int powHUerr;
2883 calcLostFraction = decSig.multiplySignificand(pow5);
2884 powHUerr = powStatus !=
opOK;
2886 calcLostFraction = decSig.divideSignificand(pow5);
2888 if (decSig.exponent < semantics->minExponent) {
2889 excessPrecision += (semantics->minExponent - decSig.exponent);
2890 truncatedBits = excessPrecision;
2891 excessPrecision = std::min(excessPrecision, calcSemantics.
precision);
2900 (decSig.significandParts(), calcSemantics.
precision - 1) == 1);
2905 excessPrecision, isNearest);
2908 if (HUdistance >= HUerr) {
2909 APInt::tcExtract(significandParts(), partCount(), decSig.significandParts(),
2910 calcSemantics.
precision - excessPrecision,
2915 exponent = (decSig.exponent + semantics->precision
2916 - (calcSemantics.
precision - excessPrecision));
2920 return normalize(rounding_mode, calcLostFraction);
2925Expected<APFloat::opStatus>
2926IEEEFloat::convertFromDecimalString(StringRef str,
roundingMode rounding_mode) {
2933 return std::move(Err);
2964 if (!semantics->hasZero)
2969 }
else if (
D.normalizedExponent - 1 > INT_MAX / 42039) {
2970 fs = handleOverflow(rounding_mode);
2976 }
else if (
D.normalizedExponent - 1 < INT_MIN / 42039 ||
2977 (
D.normalizedExponent + 1) * 28738 <=
2978 8651 * (semantics->minExponent - (
int) semantics->precision)) {
2985 }
else if ((
D.normalizedExponent - 1) * 42039
2986 >= 12655 * semantics->maxExponent) {
2988 fs = handleOverflow(rounding_mode);
2991 unsigned int partCount;
2997 partCount =
static_cast<unsigned int>(
D.lastSigDigit -
D.firstSigDigit) + 1;
3015 if (p == str.
end()) {
3020 if (decValue >= 10U) {
3021 delete[] decSignificand;
3022 return createError(
"Invalid character in significand");
3025 val = val * 10 + decValue;
3028 }
while (p <=
D.lastSigDigit && multiplier <= (~ (
integerPart) 0 - 9) / 10);
3032 partCount, partCount + 1,
false);
3036 if (decSignificand[partCount])
3038 }
while (p <=
D.lastSigDigit);
3041 fs = roundSignificandWithExponent(decSignificand, partCount,
3042 D.exponent, rounding_mode);
3044 delete [] decSignificand;
3050bool IEEEFloat::convertFromStringSpecials(StringRef str) {
3051 const size_t MIN_NAME_SIZE = 3;
3053 if (str.
size() < MIN_NAME_SIZE)
3056 if (str ==
"inf" || str ==
"INFINITY" || str ==
"+Inf") {
3063 if (str.
size() < MIN_NAME_SIZE)
3066 if (str ==
"inf" || str ==
"INFINITY" || str ==
"Inf") {
3075 if (str.
size() < MIN_NAME_SIZE)
3082 makeNaN(IsSignaling, IsNegative);
3087 if (str.
front() ==
'(') {
3089 if (str.
size() <= 2 || str.
back() !=
')')
3096 unsigned Radix = 10;
3097 if (str[0] ==
'0') {
3098 if (str.
size() > 1 && tolower(str[1]) ==
'x') {
3109 makeNaN(IsSignaling, IsNegative, &Payload);
3117Expected<APFloat::opStatus>
3123 if (convertFromStringSpecials(str))
3128 size_t slen = str.
size();
3129 sign = *p ==
'-' ? 1 : 0;
3130 if (sign && !semantics->hasSignedRepr)
3132 "This floating point format does not support signed values");
3134 if (*p ==
'-' || *p ==
'+') {
3141 if (slen >= 2 && p[0] ==
'0' && (p[1] ==
'x' || p[1] ==
'X')) {
3144 return convertFromHexadecimalString(
StringRef(p + 2, slen - 2),
3148 return convertFromDecimalString(
StringRef(p, slen), rounding_mode);
3190 dst +=
sizeof NaNU - 1;
3195 *dst++ = upperCase ?
'X':
'x';
3197 if (hexDigits > 1) {
3199 memset (dst,
'0', hexDigits - 1);
3200 dst += hexDigits - 1;
3202 *dst++ = upperCase ?
'P':
'p';
3207 dst = convertNormalToHexString (dst, hexDigits, upperCase, rounding_mode);
3213 return static_cast<unsigned int>(dst - p);
3220char *IEEEFloat::convertNormalToHexString(
char *dst,
unsigned int hexDigits,
3224 *dst++ = upperCase ?
'X':
'x';
3226 bool roundUp =
false;
3229 const integerPart *significand = significandParts();
3230 unsigned partsCount = partCount();
3234 unsigned valueBits = semantics->
precision + 3;
3239 unsigned outputDigits = (valueBits - significandLSB() + 3) / 4;
3245 if (hexDigits < outputDigits) {
3251 bits = valueBits - hexDigits * 4;
3253 roundUp = roundAwayFromZero(rounding_mode, fraction, bits);
3255 outputDigits = hexDigits;
3265 while (outputDigits &&
count) {
3269 if (--
count == partsCount)
3272 part = significand[
count] << shift;
3280 curDigits = std::min(curDigits, outputDigits);
3281 dst +=
partAsHex (dst, part, curDigits, hexDigitChars);
3282 outputDigits -= curDigits;
3292 }
while (*q ==
'0');
3296 memset (dst,
'0', outputDigits);
3297 dst += outputDigits;
3310 *dst++ = upperCase ?
'P':
'p';
3326 Arg.significandParts(),
3327 Arg.significandParts() + Arg.partCount()));
3339APInt IEEEFloat::convertF80LongDoubleAPFloatToAPInt()
const {
3344 uint64_t myexponent, mysignificand;
3347 myexponent = exponent+16383;
3348 mysignificand = significandParts()[0];
3349 if (myexponent==1 && !(mysignificand & 0x8000000000000000ULL))
3351 }
else if (category==
fcZero) {
3355 myexponent = 0x7fff;
3356 mysignificand = 0x8000000000000000ULL;
3359 myexponent = 0x7fff;
3360 mysignificand = significandParts()[0];
3364 words[0] = mysignificand;
3365 words[1] = ((uint64_t)(sign & 1) << 15) |
3366 (myexponent & 0x7fffLL);
3367 return APInt(80, words);
3370APInt IEEEFloat::convertPPCDoubleDoubleLegacyAPFloatToAPInt()
const {
3372 (
const llvm::fltSemantics *)&APFloatBase::semPPCDoubleDoubleLegacy);
3384 fltSemantics extendedSemantics = *semantics;
3394 words[0] = *
u.convertDoubleAPFloatToAPInt().getRawData();
3400 if (
u.isFiniteNonZero() && losesInfo) {
3408 words[1] = *
v.convertDoubleAPFloatToAPInt().getRawData();
3413 return APInt(128, words);
3416template <const fltSemantics &S>
3417APInt IEEEFloat::convertIEEEFloatToAPInt()
const {
3419 const int bias = (semantics == &APFloatBase::semFloat8E8M0FNU)
3421 : -(S.minExponent - 1);
3422 constexpr unsigned int trailing_significand_bits = S.precision - 1;
3423 constexpr int integer_bit_part = trailing_significand_bits /
integerPartWidth;
3426 constexpr uint64_t significand_mask = integer_bit - 1;
3427 constexpr unsigned int exponent_bits =
3428 trailing_significand_bits ? (S.sizeInBits - 1 - trailing_significand_bits)
3430 static_assert(exponent_bits < 64);
3431 constexpr uint64_t exponent_mask = (uint64_t{1} << exponent_bits) - 1;
3433 uint64_t myexponent;
3438 myexponent = exponent + bias;
3439 std::copy_n(significandParts(), mysignificand.size(),
3440 mysignificand.begin());
3441 if (myexponent == 1 &&
3442 !(significandParts()[integer_bit_part] & integer_bit))
3444 }
else if (category ==
fcZero) {
3447 myexponent = ::exponentZero(S) + bias;
3448 mysignificand.fill(0);
3453 myexponent = ::exponentInf(S) + bias;
3454 mysignificand.fill(0);
3459 myexponent = ::exponentNaN(S) + bias;
3460 std::copy_n(significandParts(), mysignificand.size(),
3461 mysignificand.begin());
3463 std::array<uint64_t, (S.sizeInBits + 63) / 64> words;
3465 std::copy_n(mysignificand.begin(), mysignificand.size(), words.begin());
3466 if constexpr (significand_mask != 0 || trailing_significand_bits == 0) {
3468 words[mysignificand.size() - 1] &= significand_mask;
3470 std::fill(words_iter, words.end(), uint64_t{0});
3471 constexpr size_t last_word = words.size() - 1;
3472 uint64_t shifted_sign =
static_cast<uint64_t
>(sign & 1)
3473 << ((S.sizeInBits - 1) % 64);
3474 words[last_word] |= shifted_sign;
3475 uint64_t shifted_exponent = (myexponent & exponent_mask)
3476 << (trailing_significand_bits % 64);
3477 words[last_word] |= shifted_exponent;
3478 if constexpr (last_word == 0) {
3479 return APInt(S.sizeInBits, words[0]);
3481 return APInt(S.sizeInBits, words);
3484APInt IEEEFloat::convertQuadrupleAPFloatToAPInt()
const {
3485 assert(partCount() == 2);
3486 return convertIEEEFloatToAPInt<APFloatBase::semIEEEquad>();
3489APInt IEEEFloat::convertDoubleAPFloatToAPInt()
const {
3491 return convertIEEEFloatToAPInt<APFloatBase::semIEEEdouble>();
3494APInt IEEEFloat::convertFloatAPFloatToAPInt()
const {
3496 return convertIEEEFloatToAPInt<APFloatBase::semIEEEsingle>();
3499APInt IEEEFloat::convertBFloatAPFloatToAPInt()
const {
3500 assert(partCount() == 1);
3501 return convertIEEEFloatToAPInt<APFloatBase::semBFloat>();
3504APInt IEEEFloat::convertHalfAPFloatToAPInt()
const {
3506 return convertIEEEFloatToAPInt<APFloatBase::APFloatBase::semIEEEhalf>();
3509APInt IEEEFloat::convertFloat8E5M2APFloatToAPInt()
const {
3510 assert(partCount() == 1);
3511 return convertIEEEFloatToAPInt<APFloatBase::semFloat8E5M2>();
3514APInt IEEEFloat::convertFloat8E5M2FNUZAPFloatToAPInt()
const {
3515 assert(partCount() == 1);
3516 return convertIEEEFloatToAPInt<APFloatBase::semFloat8E5M2FNUZ>();
3519APInt IEEEFloat::convertFloat8E4M3APFloatToAPInt()
const {
3520 assert(partCount() == 1);
3521 return convertIEEEFloatToAPInt<APFloatBase::semFloat8E4M3>();
3524APInt IEEEFloat::convertFloat8E4M3FNAPFloatToAPInt()
const {
3525 assert(partCount() == 1);
3526 return convertIEEEFloatToAPInt<APFloatBase::semFloat8E4M3FN>();
3529APInt IEEEFloat::convertFloat8E4M3FNUZAPFloatToAPInt()
const {
3530 assert(partCount() == 1);
3531 return convertIEEEFloatToAPInt<APFloatBase::semFloat8E4M3FNUZ>();
3534APInt IEEEFloat::convertFloat8E4M3B11FNUZAPFloatToAPInt()
const {
3535 assert(partCount() == 1);
3536 return convertIEEEFloatToAPInt<APFloatBase::semFloat8E4M3B11FNUZ>();
3539APInt IEEEFloat::convertFloat8E3M4APFloatToAPInt()
const {
3540 assert(partCount() == 1);
3541 return convertIEEEFloatToAPInt<APFloatBase::semFloat8E3M4>();
3544APInt IEEEFloat::convertFloatTF32APFloatToAPInt()
const {
3545 assert(partCount() == 1);
3546 return convertIEEEFloatToAPInt<APFloatBase::semFloatTF32>();
3549APInt IEEEFloat::convertFloat8E8M0FNUAPFloatToAPInt()
const {
3550 assert(partCount() == 1);
3551 return convertIEEEFloatToAPInt<APFloatBase::semFloat8E8M0FNU>();
3554APInt IEEEFloat::convertFloat6E3M2FNAPFloatToAPInt()
const {
3555 assert(partCount() == 1);
3556 return convertIEEEFloatToAPInt<APFloatBase::semFloat6E3M2FN>();
3559APInt IEEEFloat::convertFloat6E2M3FNAPFloatToAPInt()
const {
3560 assert(partCount() == 1);
3561 return convertIEEEFloatToAPInt<APFloatBase::semFloat6E2M3FN>();
3564APInt IEEEFloat::convertFloat4E2M1FNAPFloatToAPInt()
const {
3565 assert(partCount() == 1);
3566 return convertIEEEFloatToAPInt<APFloatBase::semFloat4E2M1FN>();
3575 return convertHalfAPFloatToAPInt();
3578 return convertBFloatAPFloatToAPInt();
3581 return convertFloatAPFloatToAPInt();
3584 return convertDoubleAPFloatToAPInt();
3587 return convertQuadrupleAPFloatToAPInt();
3591 return convertPPCDoubleDoubleLegacyAPFloatToAPInt();
3594 return convertFloat8E5M2APFloatToAPInt();
3597 return convertFloat8E5M2FNUZAPFloatToAPInt();
3600 return convertFloat8E4M3APFloatToAPInt();
3603 return convertFloat8E4M3FNAPFloatToAPInt();
3606 return convertFloat8E4M3FNUZAPFloatToAPInt();
3610 return convertFloat8E4M3B11FNUZAPFloatToAPInt();
3613 return convertFloat8E3M4APFloatToAPInt();
3616 return convertFloatTF32APFloatToAPInt();
3619 return convertFloat8E8M0FNUAPFloatToAPInt();
3622 return convertFloat6E3M2FNAPFloatToAPInt();
3625 return convertFloat6E2M3FNAPFloatToAPInt();
3628 return convertFloat4E2M1FNAPFloatToAPInt();
3633 return convertF80LongDoubleAPFloatToAPInt();
3638 "Float semantics are not IEEEsingle");
3645 "Float semantics are not IEEEdouble");
3650#ifdef HAS_IEE754_FLOAT128
3651float128 IEEEFloat::convertToQuad()
const {
3653 "Float semantics are not IEEEquads");
3655 return api.bitsToQuad();
3666void IEEEFloat::initFromF80LongDoubleAPInt(
const APInt &api) {
3669 uint64_t myexponent = (i2 & 0x7fff);
3671 uint8_t myintegerbit = mysignificand >> 63;
3673 initialize(&APFloatBase::semX87DoubleExtended);
3676 sign =
static_cast<unsigned int>(i2>>15);
3677 if (myexponent == 0 && mysignificand == 0) {
3679 }
else if (myexponent==0x7fff && mysignificand==0x8000000000000000ULL) {
3681 }
else if ((myexponent == 0x7fff && mysignificand != 0x8000000000000000ULL) ||
3682 (myexponent != 0x7fff && myexponent != 0 && myintegerbit == 0)) {
3684 exponent = exponentNaN();
3685 significandParts()[0] = mysignificand;
3686 significandParts()[1] = 0;
3689 exponent = myexponent - 16383;
3690 significandParts()[0] = mysignificand;
3691 significandParts()[1] = 0;
3697void IEEEFloat::initFromPPCDoubleDoubleLegacyAPInt(
const APInt &api) {
3703 initFromDoubleAPInt(APInt(64, i1));
3704 [[maybe_unused]]
opStatus fs =
convert(APFloatBase::semPPCDoubleDoubleLegacy,
3710 IEEEFloat v(APFloatBase::semIEEEdouble, APInt(64, i2));
3724void IEEEFloat::initFromFloat8E8M0FNUAPInt(
const APInt &api) {
3725 const uint64_t exponent_mask = 0xff;
3727 uint64_t myexponent = val & exponent_mask;
3729 initialize(&APFloatBase::semFloat8E8M0FNU);
3730 assert(partCount() == 1);
3738 uint64_t mysignificand = 1;
3739 significandParts()[0] = mysignificand;
3743 if (val == exponent_mask) {
3745 exponent = exponentNaN();
3750 exponent = myexponent - 127;
3753template <const fltSemantics &S>
3754void IEEEFloat::initFromIEEEAPInt(
const APInt &api) {
3758 constexpr uint64_t significand_mask = integer_bit - 1;
3759 constexpr unsigned int trailing_significand_bits = S.precision - 1;
3760 constexpr unsigned int stored_significand_parts =
3762 constexpr unsigned int exponent_bits =
3763 S.sizeInBits - 1 - trailing_significand_bits;
3764 static_assert(exponent_bits < 64);
3765 constexpr uint64_t exponent_mask = (uint64_t{1} << exponent_bits) - 1;
3766 constexpr int bias = -(S.minExponent - 1);
3770 std::array<integerPart, stored_significand_parts> mysignificand;
3771 std::copy_n(api.
getRawData(), mysignificand.size(), mysignificand.begin());
3772 if constexpr (significand_mask != 0) {
3773 mysignificand[mysignificand.size() - 1] &= significand_mask;
3779 uint64_t myexponent =
3780 (last_word >> (trailing_significand_bits % 64)) & exponent_mask;
3783 assert(partCount() == mysignificand.size());
3785 sign =
static_cast<unsigned int>(last_word >> ((S.sizeInBits - 1) % 64));
3789 bool is_zero = myexponent == 0 && all_zero_significand;
3792 if (myexponent - bias == ::exponentInf(S) && all_zero_significand) {
3798 bool is_nan =
false;
3801 is_nan = myexponent - bias == ::exponentNaN(S) && !all_zero_significand;
3803 bool all_ones_significand =
3804 std::all_of(mysignificand.begin(), mysignificand.end() - 1,
3805 [](
integerPart bits) { return bits == ~integerPart{0}; }) &&
3806 (!significand_mask ||
3807 mysignificand[mysignificand.size() - 1] == significand_mask);
3808 is_nan = myexponent - bias == ::exponentNaN(S) && all_ones_significand;
3810 is_nan = is_zero && sign;
3816 std::copy_n(mysignificand.begin(), mysignificand.size(),
3817 significandParts());
3827 exponent = myexponent - bias;
3828 std::copy_n(mysignificand.begin(), mysignificand.size(), significandParts());
3829 if (myexponent == 0)
3830 exponent = S.minExponent;
3832 significandParts()[mysignificand.size()-1] |= integer_bit;
3835void IEEEFloat::initFromQuadrupleAPInt(
const APInt &api) {
3836 initFromIEEEAPInt<APFloatBase::semIEEEquad>(api);
3839void IEEEFloat::initFromDoubleAPInt(
const APInt &api) {
3840 initFromIEEEAPInt<APFloatBase::semIEEEdouble>(api);
3843void IEEEFloat::initFromFloatAPInt(
const APInt &api) {
3844 initFromIEEEAPInt<APFloatBase::semIEEEsingle>(api);
3847void IEEEFloat::initFromBFloatAPInt(
const APInt &api) {
3848 initFromIEEEAPInt<APFloatBase::semBFloat>(api);
3851void IEEEFloat::initFromHalfAPInt(
const APInt &api) {
3852 initFromIEEEAPInt<APFloatBase::semIEEEhalf>(api);
3855void IEEEFloat::initFromFloat8E5M2APInt(
const APInt &api) {
3856 initFromIEEEAPInt<APFloatBase::semFloat8E5M2>(api);
3859void IEEEFloat::initFromFloat8E5M2FNUZAPInt(
const APInt &api) {
3860 initFromIEEEAPInt<APFloatBase::semFloat8E5M2FNUZ>(api);
3863void IEEEFloat::initFromFloat8E4M3APInt(
const APInt &api) {
3864 initFromIEEEAPInt<APFloatBase::semFloat8E4M3>(api);
3867void IEEEFloat::initFromFloat8E4M3FNAPInt(
const APInt &api) {
3868 initFromIEEEAPInt<APFloatBase::semFloat8E4M3FN>(api);
3871void IEEEFloat::initFromFloat8E4M3FNUZAPInt(
const APInt &api) {
3872 initFromIEEEAPInt<APFloatBase::semFloat8E4M3FNUZ>(api);
3875void IEEEFloat::initFromFloat8E4M3B11FNUZAPInt(
const APInt &api) {
3876 initFromIEEEAPInt<APFloatBase::semFloat8E4M3B11FNUZ>(api);
3879void IEEEFloat::initFromFloat8E3M4APInt(
const APInt &api) {
3880 initFromIEEEAPInt<APFloatBase::semFloat8E3M4>(api);
3883void IEEEFloat::initFromFloatTF32APInt(
const APInt &api) {
3884 initFromIEEEAPInt<APFloatBase::semFloatTF32>(api);
3887void IEEEFloat::initFromFloat6E3M2FNAPInt(
const APInt &api) {
3888 initFromIEEEAPInt<APFloatBase::semFloat6E3M2FN>(api);
3891void IEEEFloat::initFromFloat6E2M3FNAPInt(
const APInt &api) {
3892 initFromIEEEAPInt<APFloatBase::semFloat6E2M3FN>(api);
3895void IEEEFloat::initFromFloat4E2M1FNAPInt(
const APInt &api) {
3896 initFromIEEEAPInt<APFloatBase::semFloat4E2M1FN>(api);
3902 if (Sem == &APFloatBase::semIEEEhalf)
3903 return initFromHalfAPInt(api);
3904 if (Sem == &APFloatBase::semBFloat)
3905 return initFromBFloatAPInt(api);
3906 if (Sem == &APFloatBase::semIEEEsingle)
3907 return initFromFloatAPInt(api);
3908 if (Sem == &APFloatBase::semIEEEdouble)
3909 return initFromDoubleAPInt(api);
3910 if (Sem == &APFloatBase::semX87DoubleExtended)
3911 return initFromF80LongDoubleAPInt(api);
3912 if (Sem == &APFloatBase::semIEEEquad)
3913 return initFromQuadrupleAPInt(api);
3914 if (Sem == &APFloatBase::semPPCDoubleDoubleLegacy)
3915 return initFromPPCDoubleDoubleLegacyAPInt(api);
3916 if (Sem == &APFloatBase::semFloat8E5M2)
3917 return initFromFloat8E5M2APInt(api);
3918 if (Sem == &APFloatBase::semFloat8E5M2FNUZ)
3919 return initFromFloat8E5M2FNUZAPInt(api);
3920 if (Sem == &APFloatBase::semFloat8E4M3)
3921 return initFromFloat8E4M3APInt(api);
3922 if (Sem == &APFloatBase::semFloat8E4M3FN)
3923 return initFromFloat8E4M3FNAPInt(api);
3924 if (Sem == &APFloatBase::semFloat8E4M3FNUZ)
3925 return initFromFloat8E4M3FNUZAPInt(api);
3926 if (Sem == &APFloatBase::semFloat8E4M3B11FNUZ)
3927 return initFromFloat8E4M3B11FNUZAPInt(api);
3928 if (Sem == &APFloatBase::semFloat8E3M4)
3929 return initFromFloat8E3M4APInt(api);
3930 if (Sem == &APFloatBase::semFloatTF32)
3931 return initFromFloatTF32APInt(api);
3932 if (Sem == &APFloatBase::semFloat8E8M0FNU)
3933 return initFromFloat8E8M0FNUAPInt(api);
3934 if (Sem == &APFloatBase::semFloat6E3M2FN)
3935 return initFromFloat6E3M2FNAPInt(api);
3936 if (Sem == &APFloatBase::semFloat6E2M3FN)
3937 return initFromFloat6E2M3FNAPInt(api);
3938 if (Sem == &APFloatBase::semFloat4E2M1FN)
3939 return initFromFloat4E2M1FNAPInt(api);
3947 if (Negative && !semantics->hasSignedRepr)
3949 "This floating point format does not support signed values");
3956 exponent = semantics->maxExponent;
3960 unsigned PartCount = partCount();
3961 memset(significand, 0xFF,
sizeof(
integerPart)*(PartCount - 1));
3965 const unsigned NumUnusedHighBits =
3972 (semantics->precision > 1))
3979 if (Negative && !semantics->hasSignedRepr)
3981 "This floating point format does not support signed values");
3988 exponent = semantics->minExponent;
3993 if (Negative && !semantics->hasSignedRepr)
3995 "This floating point format does not support signed values");
4004 exponent = semantics->minExponent;
4009 initFromAPInt(&Sem, API);
4022 Buffer.
append(Str.begin(), Str.end());
4027 void AdjustToPrecision(
APInt &significand,
4028 int &exp,
unsigned FormatPrecision) {
4032 unsigned bitsRequired = (FormatPrecision * 196 + 58) / 59;
4034 if (bits <= bitsRequired)
return;
4036 unsigned tensRemovable = (bits - bitsRequired) * 59 / 196;
4037 if (!tensRemovable)
return;
4039 exp += tensRemovable;
4044 if (tensRemovable & 1)
4046 tensRemovable >>= 1;
4047 if (!tensRemovable)
break;
4051 significand = significand.
udiv(divisor);
4059 int &exp,
unsigned FormatPrecision) {
4060 unsigned N = buffer.
size();
4061 if (
N <= FormatPrecision)
return;
4064 unsigned FirstSignificant =
N - FormatPrecision;
4071 if (buffer[FirstSignificant - 1] <
'5') {
4072 while (FirstSignificant <
N && buffer[FirstSignificant] ==
'0')
4075 exp += FirstSignificant;
4076 buffer.
erase(&buffer[0], &buffer[FirstSignificant]);
4082 for (
unsigned I = FirstSignificant;
I !=
N; ++
I) {
4083 if (buffer[
I] ==
'9') {
4092 if (FirstSignificant ==
N) {
4093 exp += FirstSignificant;
4099 exp += FirstSignificant;
4100 buffer.
erase(&buffer[0], &buffer[FirstSignificant]);
4104 APInt significand,
unsigned FormatPrecision,
4105 unsigned FormatMaxPadding,
bool TruncateZero) {
4106 const int semanticsPrecision = significand.
getBitWidth();
4113 if (!FormatPrecision) {
4121 FormatPrecision = 2 + semanticsPrecision * 59 / 196;
4126 exp += trailingZeros;
4132 }
else if (exp > 0) {
4134 significand = significand.
zext(semanticsPrecision + exp);
4135 significand <<= exp;
4149 unsigned precision = semanticsPrecision + (137 * texp + 136) / 59;
4153 significand = significand.
zext(precision);
4154 APInt five_to_the_i(precision, 5);
4157 significand *= five_to_the_i;
4162 five_to_the_i *= five_to_the_i;
4166 AdjustToPrecision(significand, exp, FormatPrecision);
4171 unsigned precision = significand.getBitWidth();
4172 if (precision < 4) {
4175 significand = significand.zext(precision);
4177 APInt ten(precision, 10);
4178 APInt digit(precision, 0);
4180 bool inTrail =
true;
4181 while (significand != 0) {
4186 unsigned d = digit.getZExtValue();
4197 assert(!buffer.
empty() &&
"no characters in buffer!");
4201 AdjustToPrecision(buffer, exp, FormatPrecision);
4203 unsigned NDigits = buffer.
size();
4206 bool FormatScientific;
4207 if (!FormatMaxPadding) {
4208 FormatScientific =
true;
4214 FormatScientific = ((unsigned) exp > FormatMaxPadding ||
4215 NDigits + (unsigned) exp > FormatPrecision);
4218 int MSD = exp + (int) (NDigits - 1);
4221 FormatScientific =
false;
4225 FormatScientific = ((unsigned) -MSD) > FormatMaxPadding;
4231 if (FormatScientific) {
4232 exp += (NDigits - 1);
4234 Str.push_back(buffer[NDigits-1]);
4236 if (NDigits == 1 && TruncateZero)
4239 for (
unsigned I = 1;
I != NDigits; ++
I)
4240 Str.push_back(buffer[NDigits-1-
I]);
4242 if (!TruncateZero && FormatPrecision > NDigits - 1)
4243 Str.append(FormatPrecision - NDigits + 1,
'0');
4245 Str.push_back(TruncateZero ?
'E' :
'e');
4247 Str.push_back(exp >= 0 ?
'+' :
'-');
4252 expbuf.
push_back((
char) (
'0' + (exp % 10)));
4256 if (!TruncateZero && expbuf.
size() < 2)
4258 for (
unsigned I = 0,
E = expbuf.
size();
I !=
E; ++
I)
4259 Str.push_back(expbuf[
E-1-
I]);
4265 for (
unsigned I = 0;
I != NDigits; ++
I)
4266 Str.push_back(buffer[NDigits-1-
I]);
4267 for (
unsigned I = 0;
I != (unsigned) exp; ++
I)
4275 int NWholeDigits = exp + (int) NDigits;
4278 if (NWholeDigits > 0) {
4279 for (;
I != (unsigned) NWholeDigits; ++
I)
4280 Str.push_back(buffer[NDigits-
I-1]);
4283 unsigned NZeros = 1 + (unsigned) -NWholeDigits;
4287 for (
unsigned Z = 1;
Z != NZeros; ++
Z)
4291 for (;
I != NDigits; ++
I)
4292 Str.push_back(buffer[NDigits-
I-1]);
4298 unsigned FormatMaxPadding,
bool TruncateZero)
const {
4302 return append(Str,
"-Inf");
4304 return append(Str,
"+Inf");
4306 case fcNaN:
return append(Str,
"NaN");
4312 if (!FormatMaxPadding) {
4314 append(Str,
"0.0E+0");
4317 if (FormatPrecision > 1)
4318 Str.append(FormatPrecision - 1,
'0');
4319 append(Str,
"e+00");
4331 int exp = exponent - ((int) semantics->precision - 1);
4333 semantics->precision,
4336 toStringImpl(Str,
isNegative(), exp, significand, FormatPrecision,
4337 FormatMaxPadding, TruncateZero);
4349 for (
int i = 0; i < PartCount; ++i) {
4355 if (exponent != semantics->minExponent)
4358 int CountrParts = 0;
4359 for (
int i = 0; i < PartCount;
4361 if (Parts[i] != 0) {
4362 return exponent - semantics->precision + CountrParts +
4425 if (!semantics->hasZero)
4435 }
else if (semantics->nonFiniteBehavior ==
4443 exponent = semantics->maxExponent + 1;
4457 bool WillCrossBinadeBoundary =
4458 exponent != semantics->minExponent && isSignificandAllZeros();
4476 if (WillCrossBinadeBoundary) {
4497 if (WillCrossBinadeBoundary) {
4501 assert(exponent != semantics->maxExponent &&
4502 "We can not increment an exponent beyond the maxExponent allowed"
4503 " by the given floating point semantics.");
4506 incrementSignificand();
4520 return ::exponentNaN(*semantics);
4524 return ::exponentInf(*semantics);
4528 return ::exponentZero(*semantics);
4547 if (!semantics->hasZero)
4574 return Arg.exponent;
4579 Normalized.exponent += SignificandBits;
4581 return Normalized.exponent - SignificandBits;
4585 auto MaxExp =
X.getSemantics().maxExponent;
4586 auto MinExp =
X.getSemantics().minExponent;
4594 int SignificandBits =
X.getSemantics().precision - 1;
4595 int MaxIncrement = MaxExp - (MinExp - SignificandBits) + 1;
4598 X.exponent += std::clamp(Exp, -MaxIncrement - 1, MaxIncrement);
4621 return scalbn(Val, -Exp, RM);
4627 APFloat(APFloatBase::semIEEEdouble)}) {
4628 assert(Semantics == &APFloatBase::semPPCDoubleDouble);
4632 : Semantics(&S), Floats(new
APFloat[2]{
4635 assert(Semantics == &APFloatBase::semPPCDoubleDouble);
4641 APFloat(APFloatBase::semIEEEdouble)}) {
4642 assert(Semantics == &APFloatBase::semPPCDoubleDouble);
4648 APFloat(APFloatBase::semIEEEdouble,
APInt(64,
I.getRawData()[0])),
4649 APFloat(APFloatBase::semIEEEdouble,
APInt(64,
I.getRawData()[1]))}) {
4650 assert(Semantics == &APFloatBase::semPPCDoubleDouble);
4656 Floats(new
APFloat[2]{std::move(
First), std::move(Second)}) {
4657 assert(Semantics == &APFloatBase::semPPCDoubleDouble);
4658 assert(&Floats[0].getSemantics() == &APFloatBase::semIEEEdouble);
4659 assert(&Floats[1].getSemantics() == &APFloatBase::semIEEEdouble);
4663 : Semantics(RHS.Semantics),
4667 assert(Semantics == &APFloatBase::semPPCDoubleDouble);
4671 : Semantics(RHS.Semantics), Floats(RHS.Floats) {
4672 RHS.Semantics = &APFloatBase::semBogus;
4673 RHS.Floats =
nullptr;
4674 assert(Semantics == &APFloatBase::semPPCDoubleDouble);
4678 if (Semantics == RHS.Semantics && RHS.Floats) {
4679 Floats[0] = RHS.Floats[0];
4680 Floats[1] = RHS.Floats[1];
4681 }
else if (
this != &RHS) {
4714 Floats[0] = std::move(z);
4715 Floats[1].makeZero(
false);
4728 Status |= z.
add(a, RM);
4729 Status |= z.
add(c, RM);
4732 Floats[0] = std::move(z);
4733 Floats[1].makeZero(
false);
4738 Status |= zz.
add(cc, RM);
4742 Status |= Floats[1].subtract(z, RM);
4743 Status |= Floats[1].add(c, RM);
4744 Status |= Floats[1].add(zz, RM);
4748 Status |= Floats[1].subtract(z, RM);
4749 Status |= Floats[1].add(a, RM);
4750 Status |= Floats[1].add(zz, RM);
4755 Status |=
q.subtract(z, RM);
4760 Status |= zz.
add(c, RM);
4761 Status |=
q.add(z, RM);
4762 Status |=
q.subtract(a, RM);
4764 Status |= zz.
add(q, RM);
4765 Status |= zz.
add(
aa, RM);
4766 Status |= zz.
add(cc, RM);
4768 Floats[0] = std::move(z);
4769 Floats[1].makeZero(
false);
4773 Status |= Floats[0].add(zz, RM);
4775 Floats[1].makeZero(
false);
4778 Floats[1] = std::move(z);
4779 Status |= Floats[1].subtract(Floats[0], RM);
4780 Status |= Floats[1].add(zz, RM);
4806 LHS.isNegative() !=
RHS.isNegative()) {
4807 Out.makeNaN(
false, Out.isNegative(),
nullptr);
4822 assert(&
A.getSemantics() == &APFloatBase::semIEEEdouble);
4823 assert(&AA.getSemantics() == &APFloatBase::semIEEEdouble);
4824 assert(&
C.getSemantics() == &APFloatBase::semIEEEdouble);
4825 assert(&CC.getSemantics() == &APFloatBase::semIEEEdouble);
4826 assert(&Out.Floats[0].getSemantics() == &APFloatBase::semIEEEdouble);
4827 assert(&Out.Floats[1].getSemantics() == &APFloatBase::semIEEEdouble);
4828 return Out.addImpl(
A, AA,
C, CC, RM);
4833 return addWithSpecial(*
this, RHS, *
this, RM);
4839 auto Ret =
add(RHS, RM);
4846 const auto &LHS = *
this;
4863 if (LHS.getCategory() ==
fcNaN) {
4867 if (RHS.getCategory() ==
fcNaN) {
4873 Out.makeNaN(
false,
false,
nullptr);
4885 "Special cases not handled exhaustively");
4888 APFloat A = Floats[0],
B = Floats[1],
C = RHS.Floats[0],
D = RHS.Floats[1];
4892 if (!
T.isFiniteNonZero()) {
4893 Floats[0] = std::move(
T);
4894 Floats[1].makeZero(
false);
4916 Status |= U.add(Tau, RM);
4919 if (!U.isFinite()) {
4920 Floats[1].makeZero(
false);
4925 Floats[1] = std::move(
T);
4932 assert(Semantics == &APFloatBase::semPPCDoubleDouble &&
4933 "Unexpected Semantics");
4936 APFloat(APFloatBase::semPPCDoubleDoubleLegacy, RHS.bitcastToAPInt()), RM);
4942 assert(Semantics == &APFloatBase::semPPCDoubleDouble &&
4943 "Unexpected Semantics");
4946 APFloat(APFloatBase::semPPCDoubleDoubleLegacy, RHS.bitcastToAPInt()));
4952 assert(Semantics == &APFloatBase::semPPCDoubleDouble &&
4953 "Unexpected Semantics");
4956 APFloat(APFloatBase::semPPCDoubleDoubleLegacy, RHS.bitcastToAPInt()));
4965 assert(Semantics == &APFloatBase::semPPCDoubleDouble &&
4966 "Unexpected Semantics");
4969 APFloat(APFloatBase::semPPCDoubleDoubleLegacy,
4978 assert(Semantics == &APFloatBase::semPPCDoubleDouble &&
4979 "Unexpected Semantics");
4989 if (!
Hi.isFiniteNonZero() ||
Lo.isZero()) {
4990 Floats[0] = std::move(RoundedHi);
4991 Floats[1].makeZero(
false);
5003 const APFloat RoundingError = Rounded - ToRound;
5004 if (TieBreaker.isNonZero() &&
5005 TieBreaker.isNegative() != RoundingError.
isNegative() &&
5006 abs(RoundingError).isExactlyValue(0.5))
5015 if (RoundedHi !=
Hi) {
5020 RoundedHi = RoundToNearestHelper(
Hi, RoundedHi,
Lo);
5022 Floats[0] = std::move(RoundedHi);
5023 Floats[1].makeZero(
false);
5036 LoRoundingMode = RM;
5044 RoundedLo = RoundToNearestHelper(
Lo, RoundedLo,
Hi);
5047 std::tie(RoundedHi, RoundedLo) =
fastTwoSum(RoundedHi, RoundedLo);
5049 Floats[0] = std::move(RoundedHi);
5050 Floats[1] = std::move(RoundedLo);
5055 Floats[0].changeSign();
5056 Floats[1].changeSign();
5062 const cmpResult HiPartCmp = Floats[0].compareAbsoluteValue(RHS.Floats[0]);
5067 if (Floats[1].
isZero() && RHS.Floats[1].isZero())
5073 const bool ThisIsSubtractive =
5074 Floats[0].isNegative() != Floats[1].isNegative();
5075 const bool RHSIsSubtractive =
5076 RHS.Floats[0].isNegative() != RHS.Floats[1].isNegative();
5086 if (RHS.Floats[1].isZero())
5093 if (ThisIsSubtractive != RHSIsSubtractive)
5098 const cmpResult LoPartCmp = Floats[1].compareAbsoluteValue(RHS.Floats[1]);
5100 if (ThisIsSubtractive) {
5114 return Floats[0].getCategory();
5120 Floats[0].makeInf(Neg);
5121 Floats[1].makeZero(
false);
5125 Floats[0].makeZero(Neg);
5126 Floats[1].makeZero(
false);
5130 assert(Semantics == &APFloatBase::semPPCDoubleDouble &&
5131 "Unexpected Semantics");
5133 APFloat(APFloatBase::semIEEEdouble,
APInt(64, 0x7fefffffffffffffull));
5135 APFloat(APFloatBase::semIEEEdouble,
APInt(64, 0x7c8ffffffffffffeull));
5141 assert(Semantics == &APFloatBase::semPPCDoubleDouble &&
5142 "Unexpected Semantics");
5143 Floats[0].makeSmallest(Neg);
5144 Floats[1].makeZero(
false);
5148 assert(Semantics == &APFloatBase::semPPCDoubleDouble &&
5149 "Unexpected Semantics");
5151 APFloat(APFloatBase::semIEEEdouble,
APInt(64, 0x0360000000000000ull));
5153 Floats[0].changeSign();
5154 Floats[1].makeZero(
false);
5158 Floats[0].makeNaN(SNaN, Neg,
fill);
5159 Floats[1].makeZero(
false);
5163 auto Result = Floats[0].compare(RHS.Floats[0]);
5166 return Floats[1].compare(RHS.Floats[1]);
5171 return Floats[0].bitwiseIsEqual(RHS.Floats[0]) &&
5172 Floats[1].bitwiseIsEqual(RHS.Floats[1]);
5182 assert(Semantics == &APFloatBase::semPPCDoubleDouble &&
5183 "Unexpected Semantics");
5185 Floats[0].bitcastToAPInt().getRawData()[0],
5186 Floats[1].bitcastToAPInt().getRawData()[0],
5193 assert(Semantics == &APFloatBase::semPPCDoubleDouble &&
5194 "Unexpected Semantics");
5195 APFloat Tmp(APFloatBase::semPPCDoubleDoubleLegacy);
5208 assert(Semantics == &APFloatBase::semPPCDoubleDouble &&
5209 "Unexpected Semantics");
5259 if (InLattice(HiOld, NextLo)) {
5261 Floats[1] = std::move(NextLo);
5298 if (!InLattice(NextHi, NextLo))
5302 Floats[0] = std::move(NextHi);
5303 Floats[1] = std::move(NextLo);
5311 assert(Semantics == &APFloatBase::semPPCDoubleDouble &&
5312 "Unexpected Semantics");
5354 const unsigned PositiveOverflowWidth = IsSigned ? Width - 1 : Width;
5355 if (HiExactLog2 >= 0 &&
5356 static_cast<unsigned>(HiExactLog2) == PositiveOverflowWidth) {
5366 Input, Width,
true, RM, &LoIsExact);
5379 *IsExact = RoundStatus ==
opOK;
5391 APSInt LoResult{Width, !IsSigned};
5403 *IsExact = RoundStatus ==
opOK;
5409 unsigned int Width,
bool IsSigned,
5412 convertToSignExtendedInteger(
Input, Width, IsSigned, RM, IsExact);
5416 assert(DstPartsCount <=
Input.size() &&
"Integer too big");
5424 Bits = Width - IsSigned;
5469 if (SrcMSB == UINT_MAX) {
5476 const unsigned SrcBitWidth = SrcMSB + 1;
5492 return handleOverflow(RM);
5498 bool HiAsIntIsExact;
5515 if (
Error.isNegative()) {
5523 const unsigned ErrorActiveBits =
Error.getSignificantBits() - 1;
5525 if (ErrorActiveBits > LoPrecision) {
5526 const unsigned RoundingBoundary = ErrorActiveBits - LoPrecision;
5530 if (
Error.countTrailingZeros() == RoundingBoundary - 1)
5549 Floats[0] = std::move(
Hi);
5550 Floats[1] = std::move(
Lo);
5555 return handleOverflow(RM);
5561 Largest.makeLargest(
false);
5563 return handleOverflow(RM);
5575 const bool NegateInput = IsSigned &&
Input.isNegative();
5588 unsigned int HexDigits,
5591 assert(Semantics == &APFloatBase::semPPCDoubleDouble &&
5592 "Unexpected Semantics");
5599 (Floats[0].isDenormal() || Floats[1].
isDenormal() ||
5601 Floats[0] != Floats[0] + Floats[1]);
5630 assert(Semantics == &APFloatBase::semPPCDoubleDouble &&
5631 "Unexpected Semantics");
5632 return Floats[0].isInteger() && Floats[1].isInteger();
5636 unsigned FormatPrecision,
5637 unsigned FormatMaxPadding,
5638 bool TruncateZero)
const {
5639 assert(Semantics == &APFloatBase::semPPCDoubleDouble &&
5640 "Unexpected Semantics");
5642 .
toString(Str, FormatPrecision, FormatMaxPadding, TruncateZero);
5662 if (
Lo.isZero() ||
Hi.isNegative() ==
Lo.isNegative())
5664 if (
Hi.getExactLog2Abs() == INT_MIN)
5668 return IlogbResult - 1;
5674 "Unexpected Semantics");
5676 scalbn(Arg.Floats[0], Exp, RM),
5677 scalbn(Arg.Floats[1], Exp, RM));
5683 "Unexpected Semantics");
5693 Quiet.getFirst() =
Quiet.getFirst().makeQuiet();
5715 const bool SignsDisagree =
Hi.isNegative() !=
Lo.isNegative();
5732 LoRoundingMode = RM;
5733 Second =
scalbn(
Lo, -Exp, LoRoundingMode);
5741 if (RecomposedLo !=
Lo) {
5745 const APFloat RoundingError = RecomposedLo -
Lo;
5750 const APFloat ScaledUlpOfSecond =
5752 const bool IsMidpoint =
abs(RoundingError) == ScaledUlpOfSecond;
5753 const bool RoundedLoAway =
5758 if (IsMidpoint && RoundedLoAway)
5774 if (Second.
isZero() && SignsDisagree &&
Hi.getExactLog2Abs() != INT_MIN)
5785APFloat::Storage::Storage(IEEEFloat
F,
const fltSemantics &Semantics) {
5790 if (usesLayout<DoubleAPFloat>(
Semantics)) {
5791 const fltSemantics& S =
F.getSemantics();
5805 if (APFloat::usesLayout<detail::IEEEFloat>(Arg.
getSemantics()))
5807 if (APFloat::usesLayout<detail::DoubleAPFloat>(Arg.
getSemantics()))
5815 assert(StatusOrErr &&
"Invalid floating point representation");
5867 APFloat Reciprocal =
5885 *Inv = std::move(Reciprocal);
5897 usesLayout<IEEEFloat>(ToSemantics))
5898 return U.IEEE.convert(ToSemantics, RM, losesInfo);
5900 usesLayout<DoubleAPFloat>(ToSemantics)) {
5901 assert(&ToSemantics == &APFloatBase::semPPCDoubleDouble);
5903 U.IEEE.convert(APFloatBase::semPPCDoubleDoubleLegacy, RM, losesInfo);
5904 *
this =
APFloat(ToSemantics, U.IEEE.bitcastToAPInt());
5908 usesLayout<IEEEFloat>(ToSemantics)) {
5909 auto Ret = getIEEE().convert(ToSemantics, RM, losesInfo);
5910 *
this =
APFloat(std::move(getIEEE()), ToSemantics);
5926#if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
5939 bool *isExact)
const {
5943 rounding_mode, isExact);
5945 result =
APInt(bitWidth, parts);
5951 return getIEEE().convertToDouble();
5953 "Float semantics is not representable by IEEEdouble");
5954 APFloat Temp = *
this;
5962#ifdef HAS_IEE754_FLOAT128
5963float128 APFloat::convertToQuad()
const {
5965 return getIEEE().convertToQuad();
5967 "Float semantics is not representable by IEEEquad");
5973 return Temp.getIEEE().convertToQuad();
5979 return getIEEE().convertToFloat();
5981 "Float semantics is not representable by IEEEsingle");
5982 APFloat Temp = *
this;
5992 "Float8E5M2",
"Float8E5M2FNUZ",
"Float8E4M3",
"Float8E4M3FN",
5993 "Float8E4M3FNUZ",
"Float8E4M3B11FNUZ",
"Float8E3M4",
"Float8E8M0FNU",
5994 "Float6E3M2FN",
"Float6E2M3FN",
"Float4E2M1FN"};
6002 .
Case(
"Float8E5M2", &semFloat8E5M2)
6003 .
Case(
"Float8E4M3FN", &semFloat8E4M3FN)
6004 .
Case(
"Float4E2M1FN", &semFloat4E2M1FN)
6005 .
Case(
"Float6E3M2FN", &semFloat6E3M2FN)
6006 .
Case(
"Float6E2M3FN", &semFloat6E2M3FN)
6010APFloat::Storage::~Storage() {
6011 if (usesLayout<IEEEFloat>(*semantics)) {
6015 if (usesLayout<DoubleAPFloat>(*semantics)) {
6022APFloat::Storage::Storage(
const APFloat::Storage &
RHS) {
6023 if (usesLayout<IEEEFloat>(*
RHS.semantics)) {
6027 if (usesLayout<DoubleAPFloat>(*
RHS.semantics)) {
6034APFloat::Storage::Storage(APFloat::Storage &&
RHS) {
6035 if (usesLayout<IEEEFloat>(*
RHS.semantics)) {
6039 if (usesLayout<DoubleAPFloat>(*
RHS.semantics)) {
6046APFloat::Storage &APFloat::Storage::operator=(
const APFloat::Storage &
RHS) {
6047 if (usesLayout<IEEEFloat>(*semantics) &&
6048 usesLayout<IEEEFloat>(*
RHS.semantics)) {
6050 }
else if (usesLayout<DoubleAPFloat>(*semantics) &&
6051 usesLayout<DoubleAPFloat>(*
RHS.semantics)) {
6053 }
else if (
this != &
RHS) {
6055 new (
this) Storage(
RHS);
6060APFloat::Storage &APFloat::Storage::operator=(APFloat::Storage &&
RHS) {
6061 if (usesLayout<IEEEFloat>(*semantics) &&
6062 usesLayout<IEEEFloat>(*
RHS.semantics)) {
6064 }
else if (usesLayout<DoubleAPFloat>(*semantics) &&
6065 usesLayout<DoubleAPFloat>(*
RHS.semantics)) {
6067 }
else if (
this != &
RHS) {
6069 new (
this) Storage(std::move(
RHS));
6076#undef APFLOAT_DISPATCH_ON_SEMANTICS
assert(UImm &&(UImm !=~static_cast< T >(0)) &&"Invalid immediate!")
#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...
Function Alias Analysis false
static GCRegistry::Add< ErlangGC > A("erlang", "erlang-compatible garbage collector")
static GCRegistry::Add< StatepointGC > D("statepoint-example", "an example strategy for statepoint")
static GCRegistry::Add< CoreCLRGC > E("coreclr", "CoreCLR-compatible GC")
static GCRegistry::Add< OcamlGC > B("ocaml", "ocaml 3.10-compatible GC")
#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.
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)
This file implements the StringSwitch template, which mimics a switch() statement whose cases are str...
static TableGen::Emitter::Opt Y("gen-skeleton-entry", EmitSkeleton, "Generate example skeleton entry")
static void initialize(TargetLibraryInfoImpl &TLI, const Triple &T, const llvm::StringTable &StandardNames, VectorLibrary VecLib)
Initialize the set of available library functions based on the specified target triple.
static const fltSemantics & IEEEsingle()
static const fltSemantics & Float8E4M3FN()
static LLVM_ABI const llvm::fltSemantics & EnumToSemantics(Semantics S)
static LLVM_ABI bool semanticsHasInf(const fltSemantics &)
cmpResult
IEEE-754R 5.11: Floating Point Comparison Relations.
static constexpr roundingMode rmTowardZero
static LLVM_ABI ExponentType semanticsMinExponent(const fltSemantics &)
llvm::RoundingMode roundingMode
IEEE-754R 4.3: Rounding-direction attributes.
static const fltSemantics & BFloat()
static const fltSemantics & IEEEquad()
static LLVM_ABI unsigned int semanticsSizeInBits(const fltSemantics &)
static const fltSemantics & Float8E8M0FNU()
static LLVM_ABI bool semanticsHasSignedRepr(const fltSemantics &)
static const fltSemantics & IEEEdouble()
static LLVM_ABI unsigned getSizeInBits(const fltSemantics &Sem)
Returns the size of the floating point number (in bits) in the given semantics.
static const fltSemantics & x87DoubleExtended()
static constexpr roundingMode rmTowardNegative
static constexpr roundingMode rmNearestTiesToEven
static LLVM_ABI bool isValidArbitraryFPFormat(StringRef Format)
Returns true if the given string is a valid arbitrary floating-point format interpretation for llvm....
static LLVM_ABI bool hasSignBitInMSB(const fltSemantics &)
static LLVM_ABI ExponentType semanticsMaxExponent(const fltSemantics &)
static LLVM_ABI unsigned int semanticsPrecision(const fltSemantics &)
static LLVM_ABI bool semanticsHasNaN(const fltSemantics &)
static LLVM_ABI Semantics SemanticsToEnum(const llvm::fltSemantics &Sem)
int32_t ExponentType
A signed type to represent a floating point numbers unbiased exponent.
static constexpr unsigned integerPartWidth
static const fltSemantics & PPCDoubleDoubleLegacy()
APInt::WordType integerPart
static LLVM_ABI bool semanticsHasZero(const fltSemantics &)
static LLVM_ABI bool isRepresentableAsNormalIn(const fltSemantics &Src, const fltSemantics &Dst)
static const fltSemantics & Float8E5M2FNUZ()
static const fltSemantics & Float8E4M3FNUZ()
static constexpr roundingMode rmTowardPositive
static const fltSemantics & IEEEhalf()
static const fltSemantics & Float4E2M1FN()
static const fltSemantics & Float6E2M3FN()
static const fltSemantics & Float8E4M3()
static const fltSemantics & Float8E4M3B11FNUZ()
static LLVM_ABI bool isRepresentableBy(const fltSemantics &A, const fltSemantics &B)
static const fltSemantics & Float8E3M4()
static LLVM_ABI bool isIEEELikeFP(const fltSemantics &)
static const fltSemantics & Float8E5M2()
fltCategory
Category of internally-represented number.
static constexpr roundingMode rmNearestTiesToAway
static const fltSemantics & PPCDoubleDouble()
@ S_PPCDoubleDoubleLegacy
static const fltSemantics & Float6E3M2FN()
opStatus
IEEE-754R 7: Default exception handling.
static LLVM_ABI const fltSemantics * getArbitraryFPSemantics(StringRef Format)
Returns the fltSemantics for a given arbitrary FP format string, or nullptr if invalid.
static const fltSemantics & FloatTF32()
static LLVM_ABI unsigned int semanticsIntSizeInBits(const fltSemantics &, bool)
static APFloat getQNaN(const fltSemantics &Sem, bool Negative=false, const APInt *payload=nullptr)
Factory for QNaN values.
LLVM_ABI 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 isFiniteNonZero() const
LLVM_ABI opStatus convert(const fltSemantics &ToSemantics, roundingMode RM, bool *losesInfo)
LLVM_READONLY int getExactLog2Abs() const
LLVM_ABI bool getExactInverse(APFloat *Inv) const
If this value is normal and has an exact, normal, multiplicative inverse, store it in inv and return ...
cmpResult compareAbsoluteValue(const APFloat &RHS) const
LLVM_ABI 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 LLVM_ABI APFloat getAllOnesValue(const fltSemantics &Semantics)
Returns a float which is bitcasted from an all one value int.
LLVM_ABI friend hash_code hash_value(const APFloat &Arg)
See friend declarations above.
const fltSemantics & getSemantics() const
static APFloat getOne(const fltSemantics &Sem, bool Negative=false)
Factory for Positive and Negative One.
unsigned int convertToHexString(char *DST, unsigned int HexDigits, bool UpperCase, roundingMode RM) const
LLVM_ABI 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)
static APFloat getInf(const fltSemantics &Sem, bool Negative=false)
Factory for Positive and Negative Infinity.
friend APFloat scalbn(APFloat X, int Exp, roundingMode RM)
static APFloat getSmallest(const fltSemantics &Sem, bool Negative=false)
Returns the smallest (by magnitude) finite number in the given semantics.
LLVM_ABI FPClassTest classify() const
Return the FPClassTest which will return true for the value.
opStatus mod(const APFloat &RHS)
LLVM_ABI Expected< opStatus > convertFromString(StringRef, roundingMode)
LLVM_DUMP_METHOD void dump() const
LLVM_ABI void print(raw_ostream &) const
opStatus roundToIntegral(roundingMode RM)
static bool hasSignificand(const fltSemantics &Sem)
Returns true if the given semantics has actual significand.
static APFloat getZero(const fltSemantics &Sem, bool Negative=false)
Factory for Positive and Negative Zero.
Class for arbitrary precision integers.
LLVM_ABI APInt udiv(const APInt &RHS) const
Unsigned division operation.
static LLVM_ABI 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 LLVM_ABI void tcSet(WordType *, WordType, unsigned)
Sets the least significant part of a bignum to the input value, and zeroes out higher parts.
static LLVM_ABI void udivrem(const APInt &LHS, const APInt &RHS, APInt &Quotient, APInt &Remainder)
Dual division/remainder interface.
static LLVM_ABI int tcExtractBit(const WordType *, unsigned bit)
Extract the given bit of a bignum; returns 0 or 1. Zero-based.
LLVM_ABI APInt zext(unsigned width) const
Zero extend to a new width.
static LLVM_ABI WordType tcAdd(WordType *, const WordType *, WordType carry, unsigned)
DST += RHS + CARRY where CARRY is zero or one. Returns the carry flag.
static LLVM_ABI 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.
LLVM_ABI APInt trunc(unsigned width) const
Truncate to new width.
static LLVM_ABI int tcCompare(const WordType *, const WordType *, unsigned)
Comparison (unsigned) of two bignums.
static APInt floatToBits(float V)
Converts a float to APInt bits.
static LLVM_ABI void tcAssign(WordType *, const WordType *, unsigned)
Assign one bignum to another.
unsigned getBitWidth() const
Return the number of bits in the APInt.
static LLVM_ABI void tcShiftRight(WordType *, unsigned Words, unsigned Count)
Shift a bignum right Count bits.
static LLVM_ABI 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 LLVM_ABI void tcClearBit(WordType *, unsigned bit)
Clear the given bit of a bignum. Zero-based.
void negate()
Negate this APInt in place.
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 LLVM_ABI unsigned tcLSB(const WordType *, unsigned n)
Returns the bit number of the least or most significant set bit of a number.
static LLVM_ABI void tcShiftLeft(WordType *, unsigned Words, unsigned Count)
Shift a bignum left Count bits.
static LLVM_ABI bool tcIsZero(const WordType *, unsigned)
Returns true if a bignum is zero, false otherwise.
static LLVM_ABI unsigned tcMSB(const WordType *parts, unsigned n)
Returns the bit number of the most significant set bit of a number.
float bitsToFloat() const
Converts APInt bits to a float.
static LLVM_ABI 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 constexpr unsigned APINT_BITS_PER_WORD
Bits in a word.
static LLVM_ABI WordType tcSubtract(WordType *, const WordType *, WordType carry, unsigned)
DST -= RHS + CARRY where CARRY is zero or one. Returns the carry flag.
static LLVM_ABI 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.
A wrapper around a string literal that serves as a proxy for constructing global tables of StringRefs...
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.
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.
bool consume_front(char Prefix)
Returns true if this StringRef has the given prefix and removes that prefix.
bool consume_front_insensitive(StringRef Prefix)
Returns true if this StringRef has the given prefix, ignoring case, and removes that prefix.
A switch()-like statement whose cases are string literals.
StringSwitch & Case(StringLiteral S, T Value)
Twine - A lightweight data structure for efficiently representing the concatenation of temporary valu...
LLVM_ABI void makeSmallestNormalized(bool Neg)
LLVM_ABI DoubleAPFloat & operator=(const DoubleAPFloat &RHS)
LLVM_ABI void changeSign()
LLVM_ABI bool isLargest() const
LLVM_ABI opStatus remainder(const DoubleAPFloat &RHS)
LLVM_ABI opStatus multiply(const DoubleAPFloat &RHS, roundingMode RM)
LLVM_ABI fltCategory getCategory() const
LLVM_ABI bool bitwiseIsEqual(const DoubleAPFloat &RHS) const
LLVM_ABI LLVM_READONLY int getExactLog2Abs() const
LLVM_ABI opStatus convertFromAPInt(const APInt &Input, bool IsSigned, roundingMode RM)
LLVM_ABI APInt bitcastToAPInt() const
LLVM_ABI Expected< opStatus > convertFromString(StringRef, roundingMode)
LLVM_ABI bool isSmallest() const
LLVM_ABI opStatus subtract(const DoubleAPFloat &RHS, roundingMode RM)
LLVM_ABI friend hash_code hash_value(const DoubleAPFloat &Arg)
LLVM_ABI cmpResult compareAbsoluteValue(const DoubleAPFloat &RHS) const
LLVM_ABI bool isDenormal() const
LLVM_ABI opStatus convertToInteger(MutableArrayRef< integerPart > Input, unsigned int Width, bool IsSigned, roundingMode RM, bool *IsExact) const
LLVM_ABI void makeSmallest(bool Neg)
LLVM_ABI friend int ilogb(const DoubleAPFloat &X)
LLVM_ABI opStatus next(bool nextDown)
LLVM_ABI void makeInf(bool Neg)
LLVM_ABI bool isInteger() const
LLVM_ABI void makeZero(bool Neg)
LLVM_ABI opStatus divide(const DoubleAPFloat &RHS, roundingMode RM)
LLVM_ABI bool isSmallestNormalized() const
LLVM_ABI opStatus mod(const DoubleAPFloat &RHS)
LLVM_ABI DoubleAPFloat(const fltSemantics &S)
LLVM_ABI void toString(SmallVectorImpl< char > &Str, unsigned FormatPrecision, unsigned FormatMaxPadding, bool TruncateZero=true) const
LLVM_ABI void makeLargest(bool Neg)
LLVM_ABI cmpResult compare(const DoubleAPFloat &RHS) const
LLVM_ABI friend DoubleAPFloat scalbn(const DoubleAPFloat &X, int Exp, roundingMode)
LLVM_ABI opStatus roundToIntegral(roundingMode RM)
LLVM_ABI opStatus fusedMultiplyAdd(const DoubleAPFloat &Multiplicand, const DoubleAPFloat &Addend, roundingMode RM)
LLVM_ABI unsigned int convertToHexString(char *DST, unsigned int HexDigits, bool UpperCase, roundingMode RM) const
LLVM_ABI bool isNegative() const
LLVM_ABI opStatus add(const DoubleAPFloat &RHS, roundingMode RM)
LLVM_ABI void makeNaN(bool SNaN, bool Neg, const APInt *fill)
LLVM_ABI 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...
LLVM_ABI cmpResult compareAbsoluteValue(const IEEEFloat &) const
LLVM_ABI opStatus mod(const IEEEFloat &)
C fmod, or llvm frem.
fltCategory getCategory() const
LLVM_ABI opStatus convertFromAPInt(const APInt &, bool, roundingMode)
bool isFiniteNonZero() const
bool needsCleanup() const
Returns whether this instance allocated memory.
LLVM_ABI void makeLargest(bool Neg=false)
Make this number the largest magnitude normal number in the given semantics.
LLVM_ABI LLVM_READONLY int getExactLog2Abs() const
LLVM_ABI APInt bitcastToAPInt() const
LLVM_ABI friend IEEEFloat scalbn(IEEEFloat X, int Exp, roundingMode)
LLVM_ABI cmpResult compare(const IEEEFloat &) const
IEEE comparison with another floating point number (NaNs compare unordered, 0==-0).
bool isNegative() const
IEEE-754R isSignMinus: Returns true if and only if the current value is negative.
LLVM_ABI opStatus divide(const IEEEFloat &, roundingMode)
bool isNaN() const
Returns true if and only if the float is a quiet or signaling NaN.
LLVM_ABI opStatus remainder(const IEEEFloat &)
IEEE remainder.
LLVM_ABI double convertToDouble() const
LLVM_ABI float convertToFloat() const
LLVM_ABI opStatus subtract(const IEEEFloat &, roundingMode)
LLVM_ABI void toString(SmallVectorImpl< char > &Str, unsigned FormatPrecision=0, unsigned FormatMaxPadding=3, bool TruncateZero=true) const
Converts this value into a decimal string.
LLVM_ABI void makeSmallest(bool Neg=false)
Make this number the smallest magnitude denormal number in the given semantics.
LLVM_ABI void makeInf(bool Neg=false)
LLVM_ABI bool isSmallestNormalized() const
Returns true if this is the smallest (by magnitude) normalized finite number in the given semantics.
LLVM_ABI void makeQuiet()
LLVM_ABI bool isLargest() const
Returns true if and only if the number has the largest possible finite magnitude in the current seman...
LLVM_ABI opStatus add(const IEEEFloat &, roundingMode)
bool isFinite() const
Returns true if and only if the current value is zero, subnormal, or normal.
LLVM_ABI Expected< opStatus > convertFromString(StringRef, roundingMode)
LLVM_ABI void makeNaN(bool SNaN=false, bool Neg=false, const APInt *fill=nullptr)
LLVM_ABI opStatus multiply(const IEEEFloat &, roundingMode)
LLVM_ABI opStatus roundToIntegral(roundingMode)
LLVM_ABI IEEEFloat & operator=(const IEEEFloat &)
LLVM_ABI bool bitwiseIsEqual(const IEEEFloat &) const
Bitwise comparison for equality (QNaNs compare equal, 0!=-0).
LLVM_ABI void makeSmallestNormalized(bool Negative=false)
Returns the smallest (by magnitude) normalized finite number in the given semantics.
LLVM_ABI bool isInteger() const
Returns true if and only if the number is an exact integer.
LLVM_ABI IEEEFloat(const fltSemantics &)
LLVM_ABI opStatus fusedMultiplyAdd(const IEEEFloat &, const IEEEFloat &, roundingMode)
LLVM_ABI friend int ilogb(const IEEEFloat &Arg)
LLVM_ABI opStatus next(bool nextDown)
IEEE-754R 5.3.1: nextUp/nextDown.
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.
LLVM_ABI bool isSignaling() const
Returns true if and only if the float is a signaling NaN.
LLVM_ABI void makeZero(bool Neg=false)
LLVM_ABI opStatus convert(const fltSemantics &, roundingMode, bool *)
IEEEFloat::convert - convert a value of one floating point type to another.
LLVM_ABI void changeSign()
LLVM_ABI bool isDenormal() const
IEEE-754R isSubnormal(): Returns true if and only if the float is a denormal.
LLVM_ABI opStatus convertToInteger(MutableArrayRef< integerPart >, unsigned int, bool, roundingMode, bool *) const
LLVM_ABI bool isSmallest() const
Returns true if and only if the number has the smallest possible non-zero magnitude in the current se...
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.
static constexpr opStatus opInexact
LLVM_ABI SlowDynamicAPInt abs(const SlowDynamicAPInt &X)
Redeclarations of friend declarations above to make it discoverable by lookups.
static constexpr fltCategory fcNaN
static constexpr opStatus opDivByZero
static constexpr opStatus opOverflow
static constexpr cmpResult cmpLessThan
const char unit< Period >::value[]
static void tcSetLeastSignificantBits(APInt::WordType *dst, unsigned parts, unsigned bits)
static constexpr roundingMode rmTowardPositive
static constexpr uninitializedTag uninitialized
static constexpr fltCategory fcZero
static constexpr opStatus opOK
static constexpr cmpResult cmpGreaterThan
static constexpr unsigned integerPartWidth
LLVM_ABI hash_code hash_value(const IEEEFloat &Arg)
APFloatBase::ExponentType ExponentType
static constexpr fltCategory fcNormal
static constexpr opStatus opInvalidOp
APFloatBase::opStatus opStatus
LLVM_ABI IEEEFloat frexp(const IEEEFloat &Val, int &Exp, roundingMode RM)
APFloatBase::uninitializedTag uninitializedTag
static constexpr cmpResult cmpUnordered
static constexpr roundingMode rmTowardNegative
APFloatBase::roundingMode roundingMode
APFloatBase::cmpResult cmpResult
static constexpr fltCategory fcInfinity
static constexpr roundingMode rmNearestTiesToAway
static constexpr roundingMode rmTowardZero
static constexpr opStatus opUnderflow
static constexpr roundingMode rmNearestTiesToEven
LLVM_ABI int ilogb(const IEEEFloat &Arg)
static constexpr cmpResult cmpEqual
LLVM_ABI IEEEFloat scalbn(IEEEFloat X, int Exp, roundingMode)
static std::pair< APFloat, APFloat > fastTwoSum(APFloat X, APFloat Y)
APFloatBase::integerPart integerPart
LLVM_ABI 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)
void fill(R &&Range, T &&Value)
Provide wrappers to std::fill which take ranges instead of having to pass begin/end explicitly.
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.
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)
unsigned hexDigitValue(char C)
Interpret the given character C as a hexadecimal digit and return its value.
static APFloat harrisonUlp(const APFloat &X)
static constexpr APFloatBase::ExponentType exponentZero(const fltSemantics &semantics)
static Expected< int > totalExponent(StringRef::iterator p, StringRef::iterator end, int exponentAdjustment)
LLVM_ABI std::error_code inconvertibleErrorCode()
The value returned by this function can be returned from convertToErrorCode for Error values where no...
const unsigned int maxPowerOfFiveExponent
int ilogb(const APFloat &Arg)
Returns the exponent of the internal representation of the APFloat.
static char * writeUnsignedDecimal(char *dst, unsigned int n)
constexpr auto equal_to(T &&Arg)
Functor variant of std::equal_to that can be used as a UnaryPredicate in functional algorithms like a...
constexpr int popcount(T Value) noexcept
Count the number of set bits in a value.
const unsigned int maxPrecision
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 const char infinityU[]
lostFraction
Enum that represents what fraction of the LSB truncated bits of an fp number represent.
static Error interpretDecimal(StringRef::iterator begin, StringRef::iterator end, decimalInfo *D)
LLVM_ABI 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
APFloat scalbn(APFloat X, int Exp, APFloat::roundingMode RM)
Returns: X * 2^Exp for integral exponents.
LLVM_ABI 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 lostFraction shiftRight(APFloatBase::integerPart *dst, unsigned int parts, unsigned int bits)
Error make_error(ArgTs &&... Args)
Make a Error instance representing failure using the given error info type.
@ First
Helpers to iterate all locations in the MemoryEffectsBase class.
static const char hexDigitsUpper[]
FunctionAddr VTableAddr uintptr_t uintptr_t Data
const unsigned int maxExponent
static unsigned int decDigitValue(unsigned int c)
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.
ArrayRef(const T &OneElt) -> ArrayRef< T >
static constexpr APFloatBase::ExponentType exponentInf(const fltSemantics &semantics)
bool is_contained(R &&Range, const E &Element)
Returns true if Element is found in Range.
static lostFraction lostFractionThroughTruncation(const APFloatBase::integerPart *parts, unsigned int partCount, unsigned int bits)
APFloat neg(APFloat X)
Returns the negated value of the argument.
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 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.
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[]
const char * lastSigDigit
const char * firstSigDigit
APFloatBase::ExponentType maxExponent
fltNonfiniteBehavior nonFiniteBehavior
APFloatBase::ExponentType minExponent
fltNanEncoding nanEncoding