24#include "llvm/Config/llvm-config.h"
40#define LIBC_NAMESPACE __llvm_libc_apfloat
41#define LIBC_MATH (LIBC_MATH_NO_ERRNO | LIBC_MATH_NO_EXCEPT)
43#include "shared/math.h"
45#define APFLOAT_DISPATCH_ON_SEMANTICS(METHOD_CALL) \
47 if (usesLayout<IEEEFloat>(getSemantics())) \
48 return U.IEEE.METHOD_CALL; \
49 if (usesLayout<DoubleAPFloat>(getSemantics())) \
50 return U.Double.METHOD_CALL; \
51 llvm_unreachable("Unexpected semantics"); \
62#define PackCategoriesIntoKey(_lhs, _rhs) ((_lhs) * 4 + (_rhs))
70constexpr fltSemantics APFloatBase::semIEEEhalf = {15, -14, 11, 16};
71constexpr fltSemantics APFloatBase::semBFloat = {127, -126, 8, 16};
72constexpr fltSemantics APFloatBase::semIEEEsingle = {127, -126, 24, 32};
73constexpr fltSemantics APFloatBase::semIEEEdouble = {1023, -1022, 53, 64};
74constexpr fltSemantics APFloatBase::semIEEEquad = {16383, -16382, 113, 128};
75constexpr fltSemantics APFloatBase::semFloat8E5M2 = {15, -14, 3, 8};
78constexpr fltSemantics APFloatBase::semFloat8E4M3 = {7, -6, 4, 8};
83constexpr fltSemantics APFloatBase::semFloat8E4M3B11FNUZ = {
85constexpr fltSemantics APFloatBase::semFloat8E3M4 = {3, -2, 5, 8};
86constexpr fltSemantics APFloatBase::semFloatTF32 = {127, -126, 11, 19};
104constexpr fltSemantics APFloatBase::semX87DoubleExtended = {16383, -16382, 64,
106constexpr fltSemantics APFloatBase::semBogus = {0, 0, 0, 0};
107constexpr fltSemantics APFloatBase::semPPCDoubleDouble = {-1, 0, 0, 128};
108constexpr fltSemantics APFloatBase::semPPCDoubleDoubleLegacy = {
109 1023, -1022 + 53, 53 + 53, 128};
205 return A.maxExponent <=
B.maxExponent &&
A.minExponent >=
B.minExponent &&
206 A.precision <=
B.precision;
280 if (Src.maxExponent >= Dst.maxExponent || Src.minExponent <= Dst.minExponent)
288 return Dst.precision >= Src.precision;
328static inline unsigned int
341 const unsigned int overlargeExponent = 24000;
345 if (p == end || ((*p ==
'-' || *p ==
'+') && (p + 1) == end))
348 bool isNegative = *p ==
'-';
349 if (*p ==
'-' || *p ==
'+') {
356 if (absExponent >= 10U)
357 return createError(
"Invalid character in exponent");
359 for (; p != end; ++p) {
362 return createError(
"Invalid character in exponent");
364 absExponent = absExponent * 10U + value;
365 if (absExponent >= overlargeExponent) {
366 absExponent = overlargeExponent;
372 return -(int) absExponent;
374 return (
int) absExponent;
381 int exponentAdjustment) {
387 bool negative = *p ==
'-';
388 if (*p ==
'-' || *p ==
'+') {
394 int unsignedExponent = 0;
395 bool overflow =
false;
396 for (; p != end; ++p) {
401 return createError(
"Invalid character in exponent");
403 unsignedExponent = unsignedExponent * 10 + value;
404 if (unsignedExponent > 32767) {
410 if (exponentAdjustment > 32767 || exponentAdjustment < -32768)
414 exponent = unsignedExponent;
416 exponent = -exponent;
417 exponent += exponentAdjustment;
418 if (exponent > 32767 || exponent < -32768)
423 exponent = negative ? -32768: 32767;
433 while (p != end && *p ==
'0')
436 if (p != end && *p ==
'.') {
439 if (end - begin == 1)
442 while (p != end && *p ==
'0')
475 return PtrOrErr.takeError();
478 D->firstSigDigit = p;
480 D->normalizedExponent = 0;
482 for (; p != end; ++p) {
485 return createError(
"String contains multiple dots");
495 if (*p !=
'e' && *p !=
'E')
496 return createError(
"Invalid character in significand");
499 if (dot != end && p - begin == 1)
505 return ExpOrErr.takeError();
506 D->exponent = *ExpOrErr;
514 if (p !=
D->firstSigDigit) {
520 while (p != begin && *p ==
'0');
521 while (p != begin && *p ==
'.');
526 D->normalizedExponent = (
D->exponent +
528 - (dot >
D->firstSigDigit && dot < p)));
540 unsigned int digitValue) {
545 else if (digitValue < 8 && digitValue > 0)
549 while (p != end && (*p ==
'0' || *p ==
'.'))
553 return createError(
"Invalid trailing hexadecimal fraction!");
559 if (hexDigit == UINT_MAX)
569 unsigned int partCount,
594 return lost_fraction;
609 return moreSignificant;
620HUerrBound(
bool inexactMultiply,
unsigned int HUerr1,
unsigned int HUerr2)
622 assert(HUerr1 < 2 || HUerr2 < 2 || (HUerr1 + HUerr2 < 8));
624 if (HUerr1 + HUerr2 == 0)
625 return inexactMultiply * 2;
627 return inexactMultiply + 2 * (HUerr1 + HUerr2);
653 if (part - boundary <= boundary - part)
654 return part - boundary;
656 return boundary - part;
659 if (part == boundary) {
665 }
else if (part == boundary - 1) {
682 pow5s[0] = 78125 * 5;
684 unsigned int partsCount = 1;
691 *p1 = firstEightPowers[power & 7];
697 for (
unsigned int n = 0; power; power >>= 1, n++) {
701 partsCount, partsCount);
703 if (pow5[partsCount - 1] == 0)
711 result += partsCount;
712 if (p2[result - 1] == 0)
737static const char NaNL[] =
"nan";
738static const char NaNU[] =
"NAN";
745 const char *hexDigitChars)
747 unsigned int result =
count;
753 dst[
count] = hexDigitChars[part & 0xf];
793 switch (
X.getCategory()) {
803 if (
X.isDenormal() ||
X.isSmallestNormalized())
806 if (
X.getExactLog2() != INT_MIN)
814void IEEEFloat::initialize(
const fltSemantics *ourSemantics) {
815 semantics = ourSemantics;
816 unsigned count = partCount();
821void IEEEFloat::freeSignificand() {
823 delete [] significand.parts;
826void IEEEFloat::assign(
const IEEEFloat &rhs) {
827 assert(semantics == rhs.semantics);
830 category = rhs.category;
831 exponent = rhs.exponent;
833 copySignificand(rhs);
836void IEEEFloat::copySignificand(
const IEEEFloat &rhs) {
838 assert(rhs.partCount() >= partCount());
851 if (Negative && !semantics->hasSignedRepr)
853 "This floating point format does not support signed values");
857 exponent = exponentNaN();
860 unsigned numParts = partCount();
873 fill = &fill_storage;
877 if (!
fill ||
fill->getNumWords() < numParts)
881 std::min(
fill->getNumWords(), numParts));
884 unsigned bitsToPreserve = semantics->precision - 1;
885 unsigned part = bitsToPreserve / 64;
886 bitsToPreserve %= 64;
887 significand[part] &= ((1ULL << bitsToPreserve) - 1);
888 for (part++; part != numParts; ++part)
889 significand[part] = 0;
893 (semantics->precision >= 2) ? (semantics->precision - 2) : 0;
915 if (semantics == &APFloatBase::semX87DoubleExtended)
921 if (semantics != rhs.semantics) {
923 initialize(rhs.semantics);
934 semantics = rhs.semantics;
935 significand = rhs.significand;
936 exponent = rhs.exponent;
937 category = rhs.category;
940 rhs.semantics = &APFloatBase::semBogus;
947 semantics->precision - 1) == 0);
955 significandMSB() == 0;
960 isSignificandAllZerosExceptMSB();
963unsigned int IEEEFloat::getNumHighBits()
const {
970 const unsigned int NumHighBits = (semantics->
precision > 1)
976bool IEEEFloat::isSignificandAllOnes()
const {
981 for (
unsigned i = 0; i < PartCount - 1; i++)
986 const unsigned NumHighBits = getNumHighBits();
987 assert(NumHighBits <= integerPartWidth && NumHighBits > 0 &&
988 "Can not have more high bits to fill than integerPartWidth");
991 if ((semantics->
precision <= 1) || (~(Parts[PartCount - 1] | HighBitFill)))
997bool IEEEFloat::isSignificandAllOnesExceptLSB()
const {
1006 for (
unsigned i = 0; i < PartCount - 1; i++) {
1007 if (~Parts[i] & ~
unsigned{!i})
1012 const unsigned NumHighBits = getNumHighBits();
1013 assert(NumHighBits <= integerPartWidth && NumHighBits > 0 &&
1014 "Can not have more high bits to fill than integerPartWidth");
1017 if (~(Parts[PartCount - 1] | HighBitFill | 0x1))
1023bool IEEEFloat::isSignificandAllZeros()
const {
1029 for (
unsigned i = 0; i < PartCount - 1; i++)
1034 const unsigned NumHighBits = getNumHighBits();
1036 "clear than integerPartWidth");
1037 const integerPart HighBitMask = ~integerPart(0) >> NumHighBits;
1039 if ((semantics->precision > 1) && (Parts[PartCount - 1] & HighBitMask))
1045bool IEEEFloat::isSignificandAllZerosExceptMSB()
const {
1049 for (
unsigned i = 0; i < PartCount - 1; i++) {
1054 const unsigned NumHighBits = getNumHighBits();
1057 return ((semantics->precision <= 1) || (Parts[PartCount - 1] == MSBMask));
1061 bool IsMaxExp =
isFiniteNonZero() && exponent == semantics->maxExponent;
1068 ? isSignificandAllOnesExceptLSB()
1073 return IsMaxExp && isSignificandAllOnes();
1088 if (semantics != rhs.semantics ||
1089 category != rhs.category ||
1098 return std::equal(significandParts(), significandParts() + partCount(),
1099 rhs.significandParts());
1103 initialize(&ourSemantics);
1108 significandParts()[0] =
value;
1113 initialize(&ourSemantics);
1129 initialize(rhs.semantics);
1134 *
this = std::move(rhs);
1139unsigned int IEEEFloat::partCount()
const {
1144 return const_cast<IEEEFloat *
>(
this)->significandParts();
1148 if (partCount() > 1)
1149 return significand.parts;
1151 return &significand.part;
1154void IEEEFloat::zeroSignificand() {
1159void IEEEFloat::incrementSignificand() {
1171 assert(semantics == rhs.semantics);
1172 assert(exponent == rhs.exponent);
1174 return APInt::tcAdd(parts, rhs.significandParts(), 0, partCount());
1183 assert(semantics == rhs.semantics);
1184 assert(exponent == rhs.exponent);
1195 bool ignoreAddend) {
1199 assert(semantics == rhs.semantics);
1201 unsigned precision = semantics->precision;
1209 newPartsCount > 4 ?
new integerPart[newPartsCount] : scratch;
1212 unsigned partsCount = partCount();
1215 rhs.significandParts(), partsCount, partsCount);
1219 unsigned omsb =
APInt::tcMSB(fullSignificand, newPartsCount) + 1;
1220 exponent += rhs.exponent;
1234 if (!ignoreAddend && addend.isNonZero()) {
1238 Significand savedSignificand = significand;
1239 const fltSemantics *savedSemantics = semantics;
1242 unsigned extendedPrecision = 2 * precision + 1;
1243 if (omsb != extendedPrecision - 1) {
1244 assert(extendedPrecision > omsb);
1246 (extendedPrecision - 1) - omsb);
1247 exponent -= (extendedPrecision - 1) - omsb;
1251 fltSemantics extendedSemantics = *semantics;
1252 extendedSemantics.
precision = extendedPrecision;
1254 if (newPartsCount == 1)
1255 significand.part = fullSignificand[0];
1257 significand.parts = fullSignificand;
1258 semantics = &extendedSemantics;
1271 lost_fraction = extendedAddend.shiftSignificandRight(1);
1273 "Lost precision while shifting addend for fused-multiply-add.");
1275 lost_fraction = addOrSubtractSignificand(extendedAddend,
false);
1278 if (newPartsCount == 1)
1279 fullSignificand[0] = significand.part;
1280 significand = savedSignificand;
1281 semantics = savedSemantics;
1283 omsb =
APInt::tcMSB(fullSignificand, newPartsCount) + 1;
1290 exponent -= precision + 1;
1299 if (omsb > precision) {
1300 unsigned int bits, significantParts;
1303 bits = omsb - precision;
1305 lf =
shiftRight(fullSignificand, significantParts, bits);
1312 if (newPartsCount > 4)
1313 delete [] fullSignificand;
1315 return lost_fraction;
1324 return multiplySignificand(rhs,
IEEEFloat(*semantics), !semantics->hasZero);
1331 assert(semantics == rhs.semantics);
1334 const integerPart *rhsSignificand = rhs.significandParts();
1335 unsigned partsCount = partCount();
1338 partsCount > 2 ?
new integerPart[partsCount * 2] : scratch;
1342 for (
unsigned i = 0; i < partsCount; i++) {
1343 dividend[i] = lhsSignificand[i];
1344 divisor[i] = rhsSignificand[i];
1345 lhsSignificand[i] = 0;
1348 exponent -= rhs.exponent;
1350 unsigned int precision = semantics->precision;
1353 unsigned bit = precision -
APInt::tcMSB(divisor, partsCount) - 1;
1360 bit = precision -
APInt::tcMSB(dividend, partsCount) - 1;
1376 for (bit = precision; bit; bit -= 1) {
1401 return lost_fraction;
1404unsigned int IEEEFloat::significandMSB()
const {
1408unsigned int IEEEFloat::significandLSB()
const {
1413lostFraction IEEEFloat::shiftSignificandRight(
unsigned int bits) {
1419 return shiftRight(significandParts(), partCount(), bits);
1423void IEEEFloat::shiftSignificandLeft(
unsigned int bits) {
1424 assert(bits < semantics->precision ||
1425 (semantics->precision == 1 && bits <= 1));
1428 unsigned int partsCount = partCount();
1438 assert(semantics == rhs.semantics);
1442 int compare = exponent - rhs.exponent;
1494 exponent = semantics->maxExponent;
1496 semantics->precision);
1509bool IEEEFloat::roundAwayFromZero(
roundingMode rounding_mode,
1511 unsigned int bit)
const {
1518 switch (rounding_mode) {
1554 unsigned omsb = significandMSB() + 1;
1561 int exponentChange = omsb - semantics->precision;
1565 if (exponent + exponentChange > semantics->maxExponent)
1566 return handleOverflow(rounding_mode);
1570 if (exponent + exponentChange < semantics->minExponent)
1571 exponentChange = semantics->minExponent - exponent;
1574 if (exponentChange < 0) {
1577 shiftSignificandLeft(-exponentChange);
1582 if (exponentChange > 0) {
1586 lf = shiftSignificandRight(exponentChange);
1591 if (omsb > (
unsigned) exponentChange)
1592 omsb -= exponentChange;
1602 exponent == semantics->maxExponent && isSignificandAllOnes())
1603 return handleOverflow(rounding_mode);
1616 if (!semantics->hasZero)
1624 if (roundAwayFromZero(rounding_mode, lost_fraction, 0)) {
1626 exponent = semantics->minExponent;
1628 incrementSignificand();
1629 omsb = significandMSB() + 1;
1632 if (omsb == (
unsigned) semantics->precision + 1) {
1636 if (exponent == semantics->maxExponent)
1643 shiftSignificandRight(1);
1652 exponent == semantics->maxExponent && isSignificandAllOnes())
1653 return handleOverflow(rounding_mode);
1658 if (omsb == semantics->precision)
1662 assert(omsb < semantics->precision);
1672 if (!semantics->hasZero)
1744 subtract ^=
static_cast<bool>(sign ^ rhs.sign);
1747 int bits = exponent - rhs.exponent;
1751 if ((bits < 0) && !semantics->hasSignedRepr)
1753 "This floating point format does not support signed values");
1756 bool lost_fraction_is_from_rhs =
false;
1760 else if (bits > 0) {
1761 lost_fraction = temp_rhs.shiftSignificandRight(bits - 1);
1762 lost_fraction_is_from_rhs =
true;
1763 shiftSignificandLeft(1);
1765 lost_fraction = shiftSignificandRight(-bits - 1);
1766 temp_rhs.shiftSignificandLeft(1);
1773 lost_fraction !=
lfExactlyZero && !lost_fraction_is_from_rhs;
1782 carry = temp_rhs.subtractSignificand(*
this, borrow);
1783 copySignificand(temp_rhs);
1786 bool borrow = lost_fraction !=
lfExactlyZero && lost_fraction_is_from_rhs;
1795 carry = subtractSignificand(temp_rhs, borrow);
1798 if (lost_fraction !=
lfExactlyZero && lost_fraction_is_from_rhs) {
1811 lost_fraction = temp_rhs.shiftSignificandRight(bits);
1812 carry = addSignificand(temp_rhs);
1814 lost_fraction = shiftSignificandRight(-bits);
1815 carry = addSignificand(rhs);
1822 return lost_fraction;
2015 lost_fraction = addOrSubtractSignificand(rhs,
subtract);
2016 fs = normalize(rounding_mode, lost_fraction);
2025 if (category ==
fcZero) {
2039 return addOrSubtract(rhs, rounding_mode,
false);
2045 return addOrSubtract(rhs, rounding_mode,
true);
2058 fs = normalize(rounding_mode, lost_fraction);
2076 fs = normalize(rounding_mode, lost_fraction);
2086 unsigned int origSign = sign;
2195 unsigned int origSign = sign;
2216 if (!semantics->hasZero && this->isSmallest())
2236 sign ^= multiplicand.sign;
2245 lost_fraction = multiplySignificand(multiplicand, addend);
2246 fs = normalize(rounding_mode, lost_fraction);
2259 fs = multiplySpecials(multiplicand);
2269 fs = addOrSubtract(addend, rounding_mode,
false);
2341 MagicConstant.sign = sign;
2347 fs =
add(MagicConstant, rounding_mode);
2351 subtract(MagicConstant, rounding_mode);
2362 assert(semantics == rhs.semantics);
2394 if (sign == rhs.sign)
2410 if (sign != rhs.sign) {
2446 unsigned oldPartCount = partCount();
2449 bool X86SpecialNan =
false;
2450 if (&fromSemantics == &APFloatBase::semX87DoubleExtended &&
2451 &toSemantics != &APFloatBase::semX87DoubleExtended && category ==
fcNaN &&
2452 (!(*significandParts() & 0x8000000000000000ULL) ||
2453 !(*significandParts() & 0x4000000000000000ULL))) {
2456 X86SpecialNan =
true;
2467 int omsb = significandMSB() + 1;
2468 int exponentChange = omsb - fromSemantics.
precision;
2469 if (exponent + exponentChange < toSemantics.
minExponent)
2470 exponentChange = toSemantics.
minExponent - exponent;
2471 exponentChange = std::max(exponentChange, shift);
2472 if (exponentChange < 0) {
2473 shift -= exponentChange;
2474 exponent += exponentChange;
2475 }
else if (omsb <= -shift) {
2476 exponentChange = omsb + shift - 1;
2477 shift -= exponentChange;
2478 exponent += exponentChange;
2484 (category ==
fcNaN && semantics->nonFiniteBehavior !=
2489 if (newPartCount > oldPartCount) {
2497 significand.parts = newParts;
2498 }
else if (newPartCount == 1 && oldPartCount != 1) {
2502 newPart = significandParts()[0];
2504 significand.part = newPart;
2508 semantics = &toSemantics;
2517 *losesInfo = (
fs !=
opOK);
2518 }
else if (category ==
fcNaN) {
2536 if (!X86SpecialNan && semantics == &APFloatBase::semX87DoubleExtended)
2553 }
else if (category ==
fcZero &&
2566 if (category ==
fcZero && !semantics->hasZero)
2591 assert(dstPartsCount <= parts.
size() &&
"Integer too big");
2593 if (category ==
fcZero) {
2602 unsigned truncatedBits;
2610 truncatedBits = semantics->
precision -1U - exponent;
2614 unsigned int bits = exponent + 1U;
2620 if (bits < semantics->precision) {
2622 truncatedBits = semantics->
precision - bits;
2629 bits - semantics->precision);
2637 if (truncatedBits) {
2641 roundAwayFromZero(rounding_mode, lost_fraction, truncatedBits)) {
2661 if (omsb == width &&
2697 rounding_mode, isExact);
2700 unsigned int bits, dstPartsCount;
2703 assert(dstPartsCount <= parts.
size() &&
"Integer too big");
2705 if (category ==
fcNaN)
2728 unsigned dstCount = partCount();
2729 unsigned precision = semantics->
precision;
2734 if (precision <= omsb) {
2735 exponent = omsb - 1;
2740 exponent = precision - 1;
2745 return normalize(rounding_mode, lost_fraction);
2759 return convertFromUnsignedParts(api.
getRawData(), partCount, rounding_mode);
2763IEEEFloat::convertFromHexadecimalString(
StringRef s,
2772 unsigned partsCount = partCount();
2774 bool computedTrailingFraction =
false;
2782 return PtrOrErr.takeError();
2791 return createError(
"String contains multiple dots");
2797 if (hex_value == UINT_MAX)
2807 }
else if (!computedTrailingFraction) {
2810 return FractOrErr.takeError();
2811 lost_fraction = *FractOrErr;
2812 computedTrailingFraction =
true;
2818 return createError(
"Hex strings require an exponent");
2819 if (*p !=
'p' && *p !=
'P')
2820 return createError(
"Invalid character in significand");
2823 if (dot != end && p - begin == 1)
2827 if (p != firstSignificantDigit) {
2836 expAdjustment =
static_cast<int>(
dot - firstSignificantDigit);
2837 if (expAdjustment < 0)
2839 expAdjustment = expAdjustment * 4 - 1;
2843 expAdjustment += semantics->precision;
2849 return ExpOrErr.takeError();
2850 exponent = *ExpOrErr;
2853 return normalize(rounding_mode, lost_fraction);
2857IEEEFloat::roundSignificandWithExponent(
const integerPart *decSigParts,
2858 unsigned sigPartCount,
int exp,
2860 fltSemantics calcSemantics = { 32767, -32767, 0, 0 };
2871 for (;; parts *= 2) {
2872 unsigned int excessPrecision, truncatedBits;
2875 excessPrecision = calcSemantics.
precision - semantics->precision;
2876 truncatedBits = excessPrecision;
2879 decSig.makeZero(sign);
2882 opStatus sigStatus = decSig.convertFromUnsignedParts(
2884 opStatus powStatus = pow5.convertFromUnsignedParts(pow5Parts, pow5PartCount,
2887 decSig.exponent +=
exp;
2891 unsigned int powHUerr;
2895 calcLostFraction = decSig.multiplySignificand(pow5);
2896 powHUerr = powStatus !=
opOK;
2898 calcLostFraction = decSig.divideSignificand(pow5);
2900 if (decSig.exponent < semantics->minExponent) {
2901 excessPrecision += (semantics->minExponent - decSig.exponent);
2902 truncatedBits = excessPrecision;
2903 excessPrecision = std::min(excessPrecision, calcSemantics.
precision);
2912 (decSig.significandParts(), calcSemantics.
precision - 1) == 1);
2917 excessPrecision, isNearest);
2920 if (HUdistance >= HUerr) {
2921 APInt::tcExtract(significandParts(), partCount(), decSig.significandParts(),
2922 calcSemantics.
precision - excessPrecision,
2927 exponent = (decSig.exponent + semantics->precision
2928 - (calcSemantics.
precision - excessPrecision));
2932 return static_cast<opStatus>(normalize(rounding_mode, calcLostFraction) |
2938Expected<APFloat::opStatus>
2939IEEEFloat::convertFromDecimalString(StringRef str,
roundingMode rounding_mode) {
2946 return std::move(Err);
2977 if (!semantics->hasZero)
2982 }
else if (
D.normalizedExponent - 1 > INT_MAX / 42039) {
2983 fs = handleOverflow(rounding_mode);
2989 }
else if (
D.normalizedExponent - 1 < INT_MIN / 42039 ||
2990 (
D.normalizedExponent + 1) * 28738 <=
2991 8651 * (semantics->minExponent - (
int) semantics->precision)) {
2998 }
else if ((
D.normalizedExponent - 1) * 42039
2999 >= 12655 * semantics->maxExponent) {
3001 fs = handleOverflow(rounding_mode);
3004 unsigned int partCount;
3010 partCount =
static_cast<unsigned int>(
D.lastSigDigit -
D.firstSigDigit) + 1;
3028 if (p == str.
end()) {
3033 if (decValue >= 10U) {
3034 delete[] decSignificand;
3035 return createError(
"Invalid character in significand");
3038 val = val * 10 + decValue;
3041 }
while (p <=
D.lastSigDigit && multiplier <= (~ (
integerPart) 0 - 9) / 10);
3045 partCount, partCount + 1,
false);
3049 if (decSignificand[partCount])
3051 }
while (p <=
D.lastSigDigit);
3054 fs = roundSignificandWithExponent(decSignificand, partCount,
3055 D.exponent, rounding_mode);
3057 delete [] decSignificand;
3063bool IEEEFloat::convertFromStringSpecials(StringRef str) {
3064 const size_t MIN_NAME_SIZE = 3;
3066 if (str.
size() < MIN_NAME_SIZE)
3069 if (str ==
"inf" || str ==
"INFINITY" || str ==
"+Inf" || str ==
"+inf") {
3076 if (str.
size() < MIN_NAME_SIZE)
3079 if (str ==
"inf" || str ==
"INFINITY" || str ==
"Inf") {
3088 if (str.
size() < MIN_NAME_SIZE)
3095 makeNaN(IsSignaling, IsNegative);
3100 if (str.
front() ==
'(') {
3102 if (str.
size() <= 2 || str.
back() !=
')')
3109 unsigned Radix = 10;
3110 if (str[0] ==
'0') {
3111 if (str.
size() > 1 && tolower(str[1]) ==
'x') {
3122 makeNaN(IsSignaling, IsNegative, &Payload);
3130Expected<APFloat::opStatus>
3136 if (convertFromStringSpecials(str))
3141 size_t slen = str.
size();
3142 sign = *p ==
'-' ? 1 : 0;
3143 if (sign && !semantics->hasSignedRepr)
3145 "This floating point format does not support signed values");
3147 if (*p ==
'-' || *p ==
'+') {
3154 if (slen >= 2 && p[0] ==
'0' && (p[1] ==
'x' || p[1] ==
'X')) {
3157 return convertFromHexadecimalString(
StringRef(p + 2, slen - 2),
3161 return convertFromDecimalString(
StringRef(p, slen), rounding_mode);
3203 dst +=
sizeof NaNU - 1;
3208 *dst++ = upperCase ?
'X':
'x';
3210 if (hexDigits > 1) {
3212 memset (dst,
'0', hexDigits - 1);
3213 dst += hexDigits - 1;
3215 *dst++ = upperCase ?
'P':
'p';
3220 dst = convertNormalToHexString (dst, hexDigits, upperCase, rounding_mode);
3226 return static_cast<unsigned int>(dst - p);
3233char *IEEEFloat::convertNormalToHexString(
char *dst,
unsigned int hexDigits,
3237 *dst++ = upperCase ?
'X':
'x';
3239 bool roundUp =
false;
3242 const integerPart *significand = significandParts();
3243 unsigned partsCount = partCount();
3247 unsigned valueBits = semantics->
precision + 3;
3252 unsigned outputDigits = (valueBits - significandLSB() + 3) / 4;
3258 if (hexDigits < outputDigits) {
3264 bits = valueBits - hexDigits * 4;
3266 roundUp = roundAwayFromZero(rounding_mode, fraction, bits);
3268 outputDigits = hexDigits;
3278 while (outputDigits &&
count) {
3282 if (--
count == partsCount)
3285 part = significand[
count] << shift;
3293 curDigits = std::min(curDigits, outputDigits);
3294 dst +=
partAsHex (dst, part, curDigits, hexDigitChars);
3295 outputDigits -= curDigits;
3305 }
while (*q ==
'0');
3309 memset (dst,
'0', outputDigits);
3310 dst += outputDigits;
3323 *dst++ = upperCase ?
'P':
'p';
3339 Arg.significandParts(),
3340 Arg.significandParts() + Arg.partCount()));
3352APInt IEEEFloat::convertF80LongDoubleAPFloatToAPInt()
const {
3357 uint64_t myexponent, mysignificand;
3360 myexponent = exponent+16383;
3361 mysignificand = significandParts()[0];
3362 if (myexponent==1 && !(mysignificand & 0x8000000000000000ULL))
3364 }
else if (category==
fcZero) {
3368 myexponent = 0x7fff;
3369 mysignificand = 0x8000000000000000ULL;
3372 myexponent = 0x7fff;
3373 mysignificand = significandParts()[0];
3377 words[0] = mysignificand;
3378 words[1] = ((uint64_t)(sign & 1) << 15) |
3379 (myexponent & 0x7fffLL);
3380 return APInt(80, words);
3383APInt IEEEFloat::convertPPCDoubleDoubleLegacyAPFloatToAPInt()
const {
3385 (
const llvm::fltSemantics *)&APFloatBase::semPPCDoubleDoubleLegacy);
3397 fltSemantics extendedSemantics = *semantics;
3407 words[0] = *
u.convertDoubleAPFloatToAPInt().getRawData();
3413 if (
u.isFiniteNonZero() && losesInfo) {
3421 words[1] = *
v.convertDoubleAPFloatToAPInt().getRawData();
3426 return APInt(128, words);
3429template <const fltSemantics &S>
3430APInt IEEEFloat::convertIEEEFloatToAPInt()
const {
3432 const int bias = (semantics == &APFloatBase::semFloat8E8M0FNU)
3434 : -(S.minExponent - 1);
3435 constexpr unsigned int trailing_significand_bits = S.precision - 1;
3436 constexpr int integer_bit_part = trailing_significand_bits /
integerPartWidth;
3439 constexpr uint64_t significand_mask = integer_bit - 1;
3440 constexpr unsigned int exponent_bits =
3441 trailing_significand_bits ? (S.sizeInBits - 1 - trailing_significand_bits)
3443 static_assert(exponent_bits < 64);
3444 constexpr uint64_t exponent_mask = (uint64_t{1} << exponent_bits) - 1;
3446 uint64_t myexponent;
3451 myexponent = exponent + bias;
3452 std::copy_n(significandParts(), mysignificand.size(),
3453 mysignificand.begin());
3454 if (myexponent == 1 &&
3455 !(significandParts()[integer_bit_part] & integer_bit))
3457 }
else if (category ==
fcZero) {
3460 myexponent = ::exponentZero(S) + bias;
3461 mysignificand.fill(0);
3466 myexponent = ::exponentInf(S) + bias;
3467 mysignificand.fill(0);
3472 myexponent = ::exponentNaN(S) + bias;
3473 std::copy_n(significandParts(), mysignificand.size(),
3474 mysignificand.begin());
3476 std::array<uint64_t, (S.sizeInBits + 63) / 64> words;
3478 std::copy_n(mysignificand.begin(), mysignificand.size(), words.begin());
3479 if constexpr (significand_mask != 0 || trailing_significand_bits == 0) {
3481 words[mysignificand.size() - 1] &= significand_mask;
3483 std::fill(words_iter, words.end(), uint64_t{0});
3484 constexpr size_t last_word = words.size() - 1;
3485 uint64_t shifted_sign =
static_cast<uint64_t
>(sign & 1)
3486 << ((S.sizeInBits - 1) % 64);
3487 words[last_word] |= shifted_sign;
3488 uint64_t shifted_exponent = (myexponent & exponent_mask)
3489 << (trailing_significand_bits % 64);
3490 words[last_word] |= shifted_exponent;
3491 if constexpr (last_word == 0) {
3492 return APInt(S.sizeInBits, words[0]);
3494 return APInt(S.sizeInBits, words);
3497APInt IEEEFloat::convertQuadrupleAPFloatToAPInt()
const {
3498 assert(partCount() == 2);
3499 return convertIEEEFloatToAPInt<APFloatBase::semIEEEquad>();
3502APInt IEEEFloat::convertDoubleAPFloatToAPInt()
const {
3504 return convertIEEEFloatToAPInt<APFloatBase::semIEEEdouble>();
3507APInt IEEEFloat::convertFloatAPFloatToAPInt()
const {
3509 return convertIEEEFloatToAPInt<APFloatBase::semIEEEsingle>();
3512APInt IEEEFloat::convertBFloatAPFloatToAPInt()
const {
3513 assert(partCount() == 1);
3514 return convertIEEEFloatToAPInt<APFloatBase::semBFloat>();
3517APInt IEEEFloat::convertHalfAPFloatToAPInt()
const {
3519 return convertIEEEFloatToAPInt<APFloatBase::APFloatBase::semIEEEhalf>();
3522APInt IEEEFloat::convertFloat8E5M2APFloatToAPInt()
const {
3523 assert(partCount() == 1);
3524 return convertIEEEFloatToAPInt<APFloatBase::semFloat8E5M2>();
3527APInt IEEEFloat::convertFloat8E5M2FNUZAPFloatToAPInt()
const {
3528 assert(partCount() == 1);
3529 return convertIEEEFloatToAPInt<APFloatBase::semFloat8E5M2FNUZ>();
3532APInt IEEEFloat::convertFloat8E4M3APFloatToAPInt()
const {
3533 assert(partCount() == 1);
3534 return convertIEEEFloatToAPInt<APFloatBase::semFloat8E4M3>();
3537APInt IEEEFloat::convertFloat8E4M3FNAPFloatToAPInt()
const {
3538 assert(partCount() == 1);
3539 return convertIEEEFloatToAPInt<APFloatBase::semFloat8E4M3FN>();
3542APInt IEEEFloat::convertFloat8E4M3FNUZAPFloatToAPInt()
const {
3543 assert(partCount() == 1);
3544 return convertIEEEFloatToAPInt<APFloatBase::semFloat8E4M3FNUZ>();
3547APInt IEEEFloat::convertFloat8E4M3B11FNUZAPFloatToAPInt()
const {
3548 assert(partCount() == 1);
3549 return convertIEEEFloatToAPInt<APFloatBase::semFloat8E4M3B11FNUZ>();
3552APInt IEEEFloat::convertFloat8E3M4APFloatToAPInt()
const {
3553 assert(partCount() == 1);
3554 return convertIEEEFloatToAPInt<APFloatBase::semFloat8E3M4>();
3557APInt IEEEFloat::convertFloatTF32APFloatToAPInt()
const {
3558 assert(partCount() == 1);
3559 return convertIEEEFloatToAPInt<APFloatBase::semFloatTF32>();
3562APInt IEEEFloat::convertFloat8E8M0FNUAPFloatToAPInt()
const {
3563 assert(partCount() == 1);
3564 return convertIEEEFloatToAPInt<APFloatBase::semFloat8E8M0FNU>();
3567APInt IEEEFloat::convertFloat6E3M2FNAPFloatToAPInt()
const {
3568 assert(partCount() == 1);
3569 return convertIEEEFloatToAPInt<APFloatBase::semFloat6E3M2FN>();
3572APInt IEEEFloat::convertFloat6E2M3FNAPFloatToAPInt()
const {
3573 assert(partCount() == 1);
3574 return convertIEEEFloatToAPInt<APFloatBase::semFloat6E2M3FN>();
3577APInt IEEEFloat::convertFloat4E2M1FNAPFloatToAPInt()
const {
3578 assert(partCount() == 1);
3579 return convertIEEEFloatToAPInt<APFloatBase::semFloat4E2M1FN>();
3588 return convertHalfAPFloatToAPInt();
3591 return convertBFloatAPFloatToAPInt();
3594 return convertFloatAPFloatToAPInt();
3597 return convertDoubleAPFloatToAPInt();
3600 return convertQuadrupleAPFloatToAPInt();
3604 return convertPPCDoubleDoubleLegacyAPFloatToAPInt();
3607 return convertFloat8E5M2APFloatToAPInt();
3610 return convertFloat8E5M2FNUZAPFloatToAPInt();
3613 return convertFloat8E4M3APFloatToAPInt();
3616 return convertFloat8E4M3FNAPFloatToAPInt();
3619 return convertFloat8E4M3FNUZAPFloatToAPInt();
3623 return convertFloat8E4M3B11FNUZAPFloatToAPInt();
3626 return convertFloat8E3M4APFloatToAPInt();
3629 return convertFloatTF32APFloatToAPInt();
3632 return convertFloat8E8M0FNUAPFloatToAPInt();
3635 return convertFloat6E3M2FNAPFloatToAPInt();
3638 return convertFloat6E2M3FNAPFloatToAPInt();
3641 return convertFloat4E2M1FNAPFloatToAPInt();
3646 return convertF80LongDoubleAPFloatToAPInt();
3651 "Float semantics are not IEEEsingle");
3658 "Float semantics are not IEEEdouble");
3663#ifdef HAS_IEE754_FLOAT128
3664float128 IEEEFloat::convertToQuad()
const {
3666 "Float semantics are not IEEEquads");
3668 return api.bitsToQuad();
3679void IEEEFloat::initFromF80LongDoubleAPInt(
const APInt &api) {
3682 uint64_t myexponent = (i2 & 0x7fff);
3684 uint8_t myintegerbit = mysignificand >> 63;
3686 initialize(&APFloatBase::semX87DoubleExtended);
3689 sign =
static_cast<unsigned int>(i2>>15);
3690 if (myexponent == 0 && mysignificand == 0) {
3692 }
else if (myexponent==0x7fff && mysignificand==0x8000000000000000ULL) {
3694 }
else if ((myexponent == 0x7fff && mysignificand != 0x8000000000000000ULL) ||
3695 (myexponent != 0x7fff && myexponent != 0 && myintegerbit == 0)) {
3697 exponent = exponentNaN();
3698 significandParts()[0] = mysignificand;
3699 significandParts()[1] = 0;
3702 exponent = myexponent - 16383;
3703 significandParts()[0] = mysignificand;
3704 significandParts()[1] = 0;
3710void IEEEFloat::initFromPPCDoubleDoubleLegacyAPInt(
const APInt &api) {
3716 initFromDoubleAPInt(APInt(64, i1));
3717 [[maybe_unused]]
opStatus fs =
convert(APFloatBase::semPPCDoubleDoubleLegacy,
3724 IEEEFloat v(APFloatBase::semIEEEdouble, APInt(64, i2));
3738void IEEEFloat::initFromFloat8E8M0FNUAPInt(
const APInt &api) {
3739 const uint64_t exponent_mask = 0xff;
3741 uint64_t myexponent = val & exponent_mask;
3743 initialize(&APFloatBase::semFloat8E8M0FNU);
3744 assert(partCount() == 1);
3752 uint64_t mysignificand = 1;
3753 significandParts()[0] = mysignificand;
3757 if (val == exponent_mask) {
3759 exponent = exponentNaN();
3764 exponent = myexponent - 127;
3767template <const fltSemantics &S>
3768void IEEEFloat::initFromIEEEAPInt(
const APInt &api) {
3772 constexpr uint64_t significand_mask = integer_bit - 1;
3773 constexpr unsigned int trailing_significand_bits = S.precision - 1;
3774 constexpr unsigned int stored_significand_parts =
3776 constexpr unsigned int exponent_bits =
3777 S.sizeInBits - 1 - trailing_significand_bits;
3778 static_assert(exponent_bits < 64);
3779 constexpr uint64_t exponent_mask = (uint64_t{1} << exponent_bits) - 1;
3780 constexpr int bias = -(S.minExponent - 1);
3784 std::array<integerPart, stored_significand_parts> mysignificand;
3785 std::copy_n(api.
getRawData(), mysignificand.size(), mysignificand.begin());
3786 if constexpr (significand_mask != 0) {
3787 mysignificand[mysignificand.size() - 1] &= significand_mask;
3793 uint64_t myexponent =
3794 (last_word >> (trailing_significand_bits % 64)) & exponent_mask;
3797 assert(partCount() == mysignificand.size());
3799 sign =
static_cast<unsigned int>(last_word >> ((S.sizeInBits - 1) % 64));
3803 bool is_zero = myexponent == 0 && all_zero_significand;
3806 if (myexponent - bias == ::exponentInf(S) && all_zero_significand) {
3812 bool is_nan =
false;
3815 is_nan = myexponent - bias == ::exponentNaN(S) && !all_zero_significand;
3817 bool all_ones_significand =
3818 std::all_of(mysignificand.begin(), mysignificand.end() - 1,
3819 [](
integerPart bits) { return bits == ~integerPart{0}; }) &&
3820 (!significand_mask ||
3821 mysignificand[mysignificand.size() - 1] == significand_mask);
3822 is_nan = myexponent - bias == ::exponentNaN(S) && all_ones_significand;
3824 is_nan = is_zero && sign;
3830 std::copy_n(mysignificand.begin(), mysignificand.size(),
3831 significandParts());
3841 exponent = myexponent - bias;
3842 std::copy_n(mysignificand.begin(), mysignificand.size(), significandParts());
3843 if (myexponent == 0)
3844 exponent = S.minExponent;
3846 significandParts()[mysignificand.size()-1] |= integer_bit;
3849void IEEEFloat::initFromQuadrupleAPInt(
const APInt &api) {
3850 initFromIEEEAPInt<APFloatBase::semIEEEquad>(api);
3853void IEEEFloat::initFromDoubleAPInt(
const APInt &api) {
3854 initFromIEEEAPInt<APFloatBase::semIEEEdouble>(api);
3857void IEEEFloat::initFromFloatAPInt(
const APInt &api) {
3858 initFromIEEEAPInt<APFloatBase::semIEEEsingle>(api);
3861void IEEEFloat::initFromBFloatAPInt(
const APInt &api) {
3862 initFromIEEEAPInt<APFloatBase::semBFloat>(api);
3865void IEEEFloat::initFromHalfAPInt(
const APInt &api) {
3866 initFromIEEEAPInt<APFloatBase::semIEEEhalf>(api);
3869void IEEEFloat::initFromFloat8E5M2APInt(
const APInt &api) {
3870 initFromIEEEAPInt<APFloatBase::semFloat8E5M2>(api);
3873void IEEEFloat::initFromFloat8E5M2FNUZAPInt(
const APInt &api) {
3874 initFromIEEEAPInt<APFloatBase::semFloat8E5M2FNUZ>(api);
3877void IEEEFloat::initFromFloat8E4M3APInt(
const APInt &api) {
3878 initFromIEEEAPInt<APFloatBase::semFloat8E4M3>(api);
3881void IEEEFloat::initFromFloat8E4M3FNAPInt(
const APInt &api) {
3882 initFromIEEEAPInt<APFloatBase::semFloat8E4M3FN>(api);
3885void IEEEFloat::initFromFloat8E4M3FNUZAPInt(
const APInt &api) {
3886 initFromIEEEAPInt<APFloatBase::semFloat8E4M3FNUZ>(api);
3889void IEEEFloat::initFromFloat8E4M3B11FNUZAPInt(
const APInt &api) {
3890 initFromIEEEAPInt<APFloatBase::semFloat8E4M3B11FNUZ>(api);
3893void IEEEFloat::initFromFloat8E3M4APInt(
const APInt &api) {
3894 initFromIEEEAPInt<APFloatBase::semFloat8E3M4>(api);
3897void IEEEFloat::initFromFloatTF32APInt(
const APInt &api) {
3898 initFromIEEEAPInt<APFloatBase::semFloatTF32>(api);
3901void IEEEFloat::initFromFloat6E3M2FNAPInt(
const APInt &api) {
3902 initFromIEEEAPInt<APFloatBase::semFloat6E3M2FN>(api);
3905void IEEEFloat::initFromFloat6E2M3FNAPInt(
const APInt &api) {
3906 initFromIEEEAPInt<APFloatBase::semFloat6E2M3FN>(api);
3909void IEEEFloat::initFromFloat4E2M1FNAPInt(
const APInt &api) {
3910 initFromIEEEAPInt<APFloatBase::semFloat4E2M1FN>(api);
3916 if (Sem == &APFloatBase::semIEEEhalf)
3917 return initFromHalfAPInt(api);
3918 if (Sem == &APFloatBase::semBFloat)
3919 return initFromBFloatAPInt(api);
3920 if (Sem == &APFloatBase::semIEEEsingle)
3921 return initFromFloatAPInt(api);
3922 if (Sem == &APFloatBase::semIEEEdouble)
3923 return initFromDoubleAPInt(api);
3924 if (Sem == &APFloatBase::semX87DoubleExtended)
3925 return initFromF80LongDoubleAPInt(api);
3926 if (Sem == &APFloatBase::semIEEEquad)
3927 return initFromQuadrupleAPInt(api);
3928 if (Sem == &APFloatBase::semPPCDoubleDoubleLegacy)
3929 return initFromPPCDoubleDoubleLegacyAPInt(api);
3930 if (Sem == &APFloatBase::semFloat8E5M2)
3931 return initFromFloat8E5M2APInt(api);
3932 if (Sem == &APFloatBase::semFloat8E5M2FNUZ)
3933 return initFromFloat8E5M2FNUZAPInt(api);
3934 if (Sem == &APFloatBase::semFloat8E4M3)
3935 return initFromFloat8E4M3APInt(api);
3936 if (Sem == &APFloatBase::semFloat8E4M3FN)
3937 return initFromFloat8E4M3FNAPInt(api);
3938 if (Sem == &APFloatBase::semFloat8E4M3FNUZ)
3939 return initFromFloat8E4M3FNUZAPInt(api);
3940 if (Sem == &APFloatBase::semFloat8E4M3B11FNUZ)
3941 return initFromFloat8E4M3B11FNUZAPInt(api);
3942 if (Sem == &APFloatBase::semFloat8E3M4)
3943 return initFromFloat8E3M4APInt(api);
3944 if (Sem == &APFloatBase::semFloatTF32)
3945 return initFromFloatTF32APInt(api);
3946 if (Sem == &APFloatBase::semFloat8E8M0FNU)
3947 return initFromFloat8E8M0FNUAPInt(api);
3948 if (Sem == &APFloatBase::semFloat6E3M2FN)
3949 return initFromFloat6E3M2FNAPInt(api);
3950 if (Sem == &APFloatBase::semFloat6E2M3FN)
3951 return initFromFloat6E2M3FNAPInt(api);
3952 if (Sem == &APFloatBase::semFloat4E2M1FN)
3953 return initFromFloat4E2M1FNAPInt(api);
3961 if (Negative && !semantics->hasSignedRepr)
3963 "This floating point format does not support signed values");
3970 exponent = semantics->maxExponent;
3974 unsigned PartCount = partCount();
3975 memset(significand, 0xFF,
sizeof(
integerPart)*(PartCount - 1));
3979 const unsigned NumUnusedHighBits =
3986 (semantics->precision > 1))
3993 if (Negative && !semantics->hasSignedRepr)
3995 "This floating point format does not support signed values");
4002 exponent = semantics->minExponent;
4007 if (Negative && !semantics->hasSignedRepr)
4009 "This floating point format does not support signed values");
4018 exponent = semantics->minExponent;
4023 initFromAPInt(&Sem, API);
4036 Buffer.
append(Str.begin(), Str.end());
4041 void AdjustToPrecision(
APInt &significand,
4042 int &
exp,
unsigned FormatPrecision) {
4046 unsigned bitsRequired = (FormatPrecision * 196 + 58) / 59;
4048 if (bits <= bitsRequired)
return;
4050 unsigned tensRemovable = (bits - bitsRequired) * 59 / 196;
4051 if (!tensRemovable)
return;
4053 exp += tensRemovable;
4058 if (tensRemovable & 1)
4060 tensRemovable >>= 1;
4061 if (!tensRemovable)
break;
4065 significand = significand.
udiv(divisor);
4073 int &
exp,
unsigned FormatPrecision) {
4074 unsigned N = buffer.
size();
4075 if (
N <= FormatPrecision)
return;
4078 unsigned FirstSignificant =
N - FormatPrecision;
4085 if (buffer[FirstSignificant - 1] <
'5') {
4086 while (FirstSignificant <
N && buffer[FirstSignificant] ==
'0')
4089 exp += FirstSignificant;
4090 buffer.
erase(&buffer[0], &buffer[FirstSignificant]);
4096 for (
unsigned I = FirstSignificant;
I !=
N; ++
I) {
4097 if (buffer[
I] ==
'9') {
4106 if (FirstSignificant ==
N) {
4107 exp += FirstSignificant;
4113 exp += FirstSignificant;
4114 buffer.
erase(&buffer[0], &buffer[FirstSignificant]);
4118 APInt significand,
unsigned FormatPrecision,
4119 unsigned FormatMaxPadding,
bool TruncateZero) {
4120 const int semanticsPrecision = significand.
getBitWidth();
4127 if (!FormatPrecision) {
4135 FormatPrecision = 2 + semanticsPrecision * 59 / 196;
4140 exp += trailingZeros;
4146 }
else if (
exp > 0) {
4148 significand = significand.
zext(semanticsPrecision +
exp);
4149 significand <<=
exp;
4163 unsigned precision = semanticsPrecision + (137 * texp + 136) / 59;
4167 significand = significand.
zext(precision);
4168 APInt five_to_the_i(precision, 5);
4171 significand *= five_to_the_i;
4176 five_to_the_i *= five_to_the_i;
4180 AdjustToPrecision(significand,
exp, FormatPrecision);
4185 unsigned precision = significand.getBitWidth();
4186 if (precision < 4) {
4189 significand = significand.zext(precision);
4191 APInt ten(precision, 10);
4192 APInt digit(precision, 0);
4194 bool inTrail =
true;
4195 while (significand != 0) {
4200 unsigned d = digit.getZExtValue();
4211 assert(!buffer.
empty() &&
"no characters in buffer!");
4215 AdjustToPrecision(buffer,
exp, FormatPrecision);
4217 unsigned NDigits = buffer.
size();
4220 bool FormatScientific;
4221 if (!FormatMaxPadding) {
4222 FormatScientific =
true;
4228 FormatScientific = ((unsigned)
exp > FormatMaxPadding ||
4229 NDigits + (unsigned)
exp > FormatPrecision);
4232 int MSD =
exp + (int) (NDigits - 1);
4235 FormatScientific =
false;
4239 FormatScientific = ((unsigned) -MSD) > FormatMaxPadding;
4245 if (FormatScientific) {
4246 exp += (NDigits - 1);
4248 Str.push_back(buffer[NDigits-1]);
4250 if (NDigits == 1 && TruncateZero)
4253 for (
unsigned I = 1;
I != NDigits; ++
I)
4254 Str.push_back(buffer[NDigits-1-
I]);
4256 if (!TruncateZero && FormatPrecision > NDigits - 1)
4257 Str.append(FormatPrecision - NDigits + 1,
'0');
4259 Str.push_back(TruncateZero ?
'E' :
'e');
4261 Str.push_back(
exp >= 0 ?
'+' :
'-');
4270 if (!TruncateZero && expbuf.
size() < 2)
4272 for (
unsigned I = 0,
E = expbuf.
size();
I !=
E; ++
I)
4273 Str.push_back(expbuf[
E-1-
I]);
4279 for (
unsigned I = 0;
I != NDigits; ++
I)
4280 Str.push_back(buffer[NDigits-1-
I]);
4281 for (
unsigned I = 0;
I != (unsigned)
exp; ++
I)
4289 int NWholeDigits =
exp + (int) NDigits;
4292 if (NWholeDigits > 0) {
4293 for (;
I != (unsigned) NWholeDigits; ++
I)
4294 Str.push_back(buffer[NDigits-
I-1]);
4297 unsigned NZeros = 1 + (unsigned) -NWholeDigits;
4301 for (
unsigned Z = 1;
Z != NZeros; ++
Z)
4305 for (;
I != NDigits; ++
I)
4306 Str.push_back(buffer[NDigits-
I-1]);
4312 unsigned FormatMaxPadding,
bool TruncateZero)
const {
4316 return append(Str,
"-Inf");
4318 return append(Str,
"+Inf");
4320 case fcNaN:
return append(Str,
"NaN");
4326 if (!FormatMaxPadding) {
4328 append(Str,
"0.0E+0");
4331 if (FormatPrecision > 1)
4332 Str.append(FormatPrecision - 1,
'0');
4333 append(Str,
"e+00");
4345 int exp = exponent - ((int) semantics->precision - 1);
4347 semantics->precision,
4350 toStringImpl(Str,
isNegative(),
exp, significand, FormatPrecision,
4351 FormatMaxPadding, TruncateZero);
4363 for (
int i = 0; i < PartCount; ++i) {
4369 if (exponent != semantics->minExponent)
4372 int CountrParts = 0;
4373 for (
int i = 0; i < PartCount;
4375 if (Parts[i] != 0) {
4376 return exponent - semantics->precision + CountrParts +
4439 if (!semantics->hasZero)
4449 }
else if (semantics->nonFiniteBehavior ==
4457 exponent = semantics->maxExponent + 1;
4471 bool WillCrossBinadeBoundary =
4472 exponent != semantics->minExponent && isSignificandAllZeros();
4490 if (WillCrossBinadeBoundary) {
4511 if (WillCrossBinadeBoundary) {
4515 assert(exponent != semantics->maxExponent &&
4516 "We can not increment an exponent beyond the maxExponent allowed"
4517 " by the given floating point semantics.");
4520 incrementSignificand();
4534 assert(
isNaN() &&
"Can only be called on NaN values");
4536 unsigned Bits = semantics->precision - 1;
4541 return ::exponentNaN(*semantics);
4545 return ::exponentInf(*semantics);
4549 return ::exponentZero(*semantics);
4568 if (!semantics->hasZero)
4595 return Arg.exponent;
4600 Normalized.exponent += SignificandBits;
4602 return Normalized.exponent - SignificandBits;
4606 auto MaxExp =
X.getSemantics().maxExponent;
4607 auto MinExp =
X.getSemantics().minExponent;
4615 int SignificandBits =
X.getSemantics().precision - 1;
4616 int MaxIncrement = MaxExp - (MinExp - SignificandBits) + 1;
4619 X.exponent += std::clamp(Exp, -MaxIncrement - 1, MaxIncrement);
4642 return scalbn(Val, -Exp, RM);
4648 APFloat(APFloatBase::semIEEEdouble)}) {
4649 assert(Semantics == &APFloatBase::semPPCDoubleDouble);
4653 : Semantics(&S), Floats(new
APFloat[2]{
4656 assert(Semantics == &APFloatBase::semPPCDoubleDouble);
4662 APFloat(APFloatBase::semIEEEdouble)}) {
4663 assert(Semantics == &APFloatBase::semPPCDoubleDouble);
4669 APFloat(APFloatBase::semIEEEdouble,
APInt(64,
I.getRawData()[0])),
4670 APFloat(APFloatBase::semIEEEdouble,
APInt(64,
I.getRawData()[1]))}) {
4671 assert(Semantics == &APFloatBase::semPPCDoubleDouble);
4677 Floats(new
APFloat[2]{std::move(
First), std::move(Second)}) {
4678 assert(Semantics == &APFloatBase::semPPCDoubleDouble);
4679 assert(&Floats[0].getSemantics() == &APFloatBase::semIEEEdouble);
4680 assert(&Floats[1].getSemantics() == &APFloatBase::semIEEEdouble);
4684 : Semantics(RHS.Semantics),
4688 assert(Semantics == &APFloatBase::semPPCDoubleDouble);
4692 : Semantics(RHS.Semantics), Floats(RHS.Floats) {
4693 RHS.Semantics = &APFloatBase::semBogus;
4694 RHS.Floats =
nullptr;
4695 assert(Semantics == &APFloatBase::semPPCDoubleDouble);
4699 if (Semantics == RHS.Semantics && RHS.Floats) {
4700 Floats[0] = RHS.Floats[0];
4701 Floats[1] = RHS.Floats[1];
4702 }
else if (
this != &RHS) {
4735 Floats[0] = std::move(z);
4736 Floats[1].makeZero(
false);
4749 Status |= z.
add(a, RM);
4750 Status |= z.
add(c, RM);
4753 Floats[0] = std::move(z);
4754 Floats[1].makeZero(
false);
4759 Status |= zz.
add(cc, RM);
4763 Status |= Floats[1].subtract(z, RM);
4764 Status |= Floats[1].add(c, RM);
4765 Status |= Floats[1].add(zz, RM);
4769 Status |= Floats[1].subtract(z, RM);
4770 Status |= Floats[1].add(a, RM);
4771 Status |= Floats[1].add(zz, RM);
4776 Status |=
q.subtract(z, RM);
4781 Status |= zz.
add(c, RM);
4782 Status |=
q.add(z, RM);
4783 Status |=
q.subtract(a, RM);
4785 Status |= zz.
add(q, RM);
4786 Status |= zz.
add(
aa, RM);
4787 Status |= zz.
add(cc, RM);
4789 Floats[0] = std::move(z);
4790 Floats[1].makeZero(
false);
4794 Status |= Floats[0].add(zz, RM);
4796 Floats[1].makeZero(
false);
4799 Floats[1] = std::move(z);
4800 Status |= Floats[1].subtract(Floats[0], RM);
4801 Status |= Floats[1].add(zz, RM);
4827 LHS.isNegative() !=
RHS.isNegative()) {
4828 Out.makeNaN(
false, Out.isNegative(),
nullptr);
4843 assert(&
A.getSemantics() == &APFloatBase::semIEEEdouble);
4844 assert(&AA.getSemantics() == &APFloatBase::semIEEEdouble);
4845 assert(&
C.getSemantics() == &APFloatBase::semIEEEdouble);
4846 assert(&CC.getSemantics() == &APFloatBase::semIEEEdouble);
4847 assert(&Out.Floats[0].getSemantics() == &APFloatBase::semIEEEdouble);
4848 assert(&Out.Floats[1].getSemantics() == &APFloatBase::semIEEEdouble);
4849 return Out.addImpl(
A, AA,
C, CC, RM);
4854 return addWithSpecial(*
this, RHS, *
this, RM);
4860 auto Ret =
add(RHS, RM);
4867 const auto &LHS = *
this;
4884 if (LHS.getCategory() ==
fcNaN) {
4888 if (RHS.getCategory() ==
fcNaN) {
4894 Out.makeNaN(
false,
false,
nullptr);
4906 "Special cases not handled exhaustively");
4909 APFloat A = Floats[0],
B = Floats[1],
C = RHS.Floats[0],
D = RHS.Floats[1];
4913 if (!
T.isFiniteNonZero()) {
4914 Floats[0] = std::move(
T);
4915 Floats[1].makeZero(
false);
4937 Status |= U.add(Tau, RM);
4940 if (!U.isFinite()) {
4941 Floats[1].makeZero(
false);
4946 Floats[1] = std::move(
T);
4953 assert(Semantics == &APFloatBase::semPPCDoubleDouble &&
4954 "Unexpected Semantics");
4957 APFloat(APFloatBase::semPPCDoubleDoubleLegacy, RHS.bitcastToAPInt()), RM);
4963 assert(Semantics == &APFloatBase::semPPCDoubleDouble &&
4964 "Unexpected Semantics");
4967 APFloat(APFloatBase::semPPCDoubleDoubleLegacy, RHS.bitcastToAPInt()));
4973 assert(Semantics == &APFloatBase::semPPCDoubleDouble &&
4974 "Unexpected Semantics");
4977 APFloat(APFloatBase::semPPCDoubleDoubleLegacy, RHS.bitcastToAPInt()));
4986 assert(Semantics == &APFloatBase::semPPCDoubleDouble &&
4987 "Unexpected Semantics");
4990 APFloat(APFloatBase::semPPCDoubleDoubleLegacy,
4999 assert(Semantics == &APFloatBase::semPPCDoubleDouble &&
5000 "Unexpected Semantics");
5010 if (!
Hi.isFiniteNonZero() ||
Lo.isZero()) {
5011 Floats[0] = std::move(RoundedHi);
5012 Floats[1].makeZero(
false);
5024 const APFloat RoundingError = Rounded - ToRound;
5025 if (TieBreaker.isNonZero() &&
5026 TieBreaker.isNegative() != RoundingError.
isNegative() &&
5027 abs(RoundingError).isExactlyValue(0.5))
5036 if (RoundedHi !=
Hi) {
5041 RoundedHi = RoundToNearestHelper(
Hi, RoundedHi,
Lo);
5043 Floats[0] = std::move(RoundedHi);
5044 Floats[1].makeZero(
false);
5057 LoRoundingMode = RM;
5065 RoundedLo = RoundToNearestHelper(
Lo, RoundedLo,
Hi);
5068 std::tie(RoundedHi, RoundedLo) =
fastTwoSum(RoundedHi, RoundedLo);
5070 Floats[0] = std::move(RoundedHi);
5071 Floats[1] = std::move(RoundedLo);
5076 Floats[0].changeSign();
5077 Floats[1].changeSign();
5083 const cmpResult HiPartCmp = Floats[0].compareAbsoluteValue(RHS.Floats[0]);
5088 if (Floats[1].
isZero() && RHS.Floats[1].isZero())
5094 const bool ThisIsSubtractive =
5095 Floats[0].isNegative() != Floats[1].isNegative();
5096 const bool RHSIsSubtractive =
5097 RHS.Floats[0].isNegative() != RHS.Floats[1].isNegative();
5107 if (RHS.Floats[1].isZero())
5114 if (ThisIsSubtractive != RHSIsSubtractive)
5119 const cmpResult LoPartCmp = Floats[1].compareAbsoluteValue(RHS.Floats[1]);
5121 if (ThisIsSubtractive) {
5135 return Floats[0].getCategory();
5141 Floats[0].makeInf(Neg);
5142 Floats[1].makeZero(
false);
5146 Floats[0].makeZero(Neg);
5147 Floats[1].makeZero(
false);
5151 assert(Semantics == &APFloatBase::semPPCDoubleDouble &&
5152 "Unexpected Semantics");
5154 APFloat(APFloatBase::semIEEEdouble,
APInt(64, 0x7fefffffffffffffull));
5156 APFloat(APFloatBase::semIEEEdouble,
APInt(64, 0x7c8ffffffffffffeull));
5162 assert(Semantics == &APFloatBase::semPPCDoubleDouble &&
5163 "Unexpected Semantics");
5164 Floats[0].makeSmallest(Neg);
5165 Floats[1].makeZero(
false);
5169 assert(Semantics == &APFloatBase::semPPCDoubleDouble &&
5170 "Unexpected Semantics");
5172 APFloat(APFloatBase::semIEEEdouble,
APInt(64, 0x0360000000000000ull));
5174 Floats[0].changeSign();
5175 Floats[1].makeZero(
false);
5179 Floats[0].makeNaN(SNaN, Neg,
fill);
5180 Floats[1].makeZero(
false);
5184 auto Result = Floats[0].compare(RHS.Floats[0]);
5187 return Floats[1].compare(RHS.Floats[1]);
5192 return Floats[0].bitwiseIsEqual(RHS.Floats[0]) &&
5193 Floats[1].bitwiseIsEqual(RHS.Floats[1]);
5203 assert(Semantics == &APFloatBase::semPPCDoubleDouble &&
5204 "Unexpected Semantics");
5206 Floats[0].bitcastToAPInt().getRawData()[0],
5207 Floats[1].bitcastToAPInt().getRawData()[0],
5214 assert(Semantics == &APFloatBase::semPPCDoubleDouble &&
5215 "Unexpected Semantics");
5216 APFloat Tmp(APFloatBase::semPPCDoubleDoubleLegacy);
5229 assert(Semantics == &APFloatBase::semPPCDoubleDouble &&
5230 "Unexpected Semantics");
5280 if (InLattice(HiOld, NextLo)) {
5282 Floats[1] = std::move(NextLo);
5319 if (!InLattice(NextHi, NextLo))
5323 Floats[0] = std::move(NextHi);
5324 Floats[1] = std::move(NextLo);
5332 assert(Semantics == &APFloatBase::semPPCDoubleDouble &&
5333 "Unexpected Semantics");
5375 const unsigned PositiveOverflowWidth = IsSigned ? Width - 1 : Width;
5376 if (HiExactLog2 >= 0 &&
5377 static_cast<unsigned>(HiExactLog2) == PositiveOverflowWidth) {
5387 Input, Width,
true, RM, &LoIsExact);
5400 *IsExact = RoundStatus ==
opOK;
5412 APSInt LoResult{Width, !IsSigned};
5424 *IsExact = RoundStatus ==
opOK;
5430 unsigned int Width,
bool IsSigned,
5433 convertToSignExtendedInteger(
Input, Width, IsSigned, RM, IsExact);
5437 assert(DstPartsCount <=
Input.size() &&
"Integer too big");
5445 Bits = Width - IsSigned;
5490 if (SrcMSB == UINT_MAX) {
5497 const unsigned SrcBitWidth = SrcMSB + 1;
5513 return handleOverflow(RM);
5519 bool HiAsIntIsExact;
5536 if (
Error.isNegative()) {
5544 const unsigned ErrorActiveBits =
Error.getSignificantBits() - 1;
5546 if (ErrorActiveBits > LoPrecision) {
5547 const unsigned RoundingBoundary = ErrorActiveBits - LoPrecision;
5551 if (
Error.countTrailingZeros() == RoundingBoundary - 1)
5570 Floats[0] = std::move(
Hi);
5571 Floats[1] = std::move(
Lo);
5576 return handleOverflow(RM);
5582 Largest.makeLargest(
false);
5584 return handleOverflow(RM);
5596 const bool NegateInput = IsSigned &&
Input.isNegative();
5609 unsigned int HexDigits,
5612 assert(Semantics == &APFloatBase::semPPCDoubleDouble &&
5613 "Unexpected Semantics");
5620 (Floats[0].isDenormal() || Floats[1].
isDenormal() ||
5622 Floats[0] != Floats[0] + Floats[1]);
5651 assert(Semantics == &APFloatBase::semPPCDoubleDouble &&
5652 "Unexpected Semantics");
5653 return Floats[0].isInteger() && Floats[1].isInteger();
5657 unsigned FormatPrecision,
5658 unsigned FormatMaxPadding,
5659 bool TruncateZero)
const {
5660 assert(Semantics == &APFloatBase::semPPCDoubleDouble &&
5661 "Unexpected Semantics");
5663 .
toString(Str, FormatPrecision, FormatMaxPadding, TruncateZero);
5683 if (
Lo.isZero() ||
Hi.isNegative() ==
Lo.isNegative())
5685 if (
Hi.getExactLog2Abs() == INT_MIN)
5689 return IlogbResult - 1;
5695 "Unexpected Semantics");
5697 scalbn(Arg.Floats[0], Exp, RM),
5698 scalbn(Arg.Floats[1], Exp, RM));
5704 "Unexpected Semantics");
5714 Quiet.getFirst() =
Quiet.getFirst().makeQuiet();
5736 const bool SignsDisagree =
Hi.isNegative() !=
Lo.isNegative();
5753 LoRoundingMode = RM;
5754 Second =
scalbn(
Lo, -Exp, LoRoundingMode);
5762 if (RecomposedLo !=
Lo) {
5766 const APFloat RoundingError = RecomposedLo -
Lo;
5771 const APFloat ScaledUlpOfSecond =
5773 const bool IsMidpoint =
abs(RoundingError) == ScaledUlpOfSecond;
5774 const bool RoundedLoAway =
5779 if (IsMidpoint && RoundedLoAway)
5795 if (Second.
isZero() && SignsDisagree &&
Hi.getExactLog2Abs() != INT_MIN)
5807APFloat::Storage::Storage(IEEEFloat
F,
const fltSemantics &Semantics) {
5812 if (usesLayout<DoubleAPFloat>(
Semantics)) {
5827 if (APFloat::usesLayout<detail::IEEEFloat>(Arg.
getSemantics()))
5829 if (APFloat::usesLayout<detail::DoubleAPFloat>(Arg.
getSemantics()))
5837 assert(StatusOrErr &&
"Invalid floating point representation");
5889 APFloat Reciprocal =
5907 *Inv = std::move(Reciprocal);
5919 usesLayout<IEEEFloat>(ToSemantics))
5920 return U.IEEE.convert(ToSemantics, RM, losesInfo);
5922 usesLayout<DoubleAPFloat>(ToSemantics)) {
5923 assert(&ToSemantics == &APFloatBase::semPPCDoubleDouble);
5925 U.IEEE.convert(APFloatBase::semPPCDoubleDoubleLegacy, RM, losesInfo);
5926 *
this =
APFloat(ToSemantics, U.IEEE.bitcastToAPInt());
5930 usesLayout<IEEEFloat>(ToSemantics)) {
5931 auto Ret = getIEEE().convert(ToSemantics, RM, losesInfo);
5932 *
this =
APFloat(std::move(getIEEE()), ToSemantics);
5948#if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
5961 bool *isExact)
const {
5965 rounding_mode, isExact);
5967 result =
APInt(bitWidth, parts);
5973 return getIEEE().convertToDouble();
5975 "Float semantics is not representable by IEEEdouble");
5976 APFloat Temp = *
this;
5984#ifdef HAS_IEE754_FLOAT128
5985float128 APFloat::convertToQuad()
const {
5987 return getIEEE().convertToQuad();
5989 "Float semantics is not representable by IEEEquad");
5995 return Temp.getIEEE().convertToQuad();
6001 return getIEEE().convertToFloat();
6003 "Float semantics is not representable by IEEEsingle");
6004 APFloat Temp = *
this;
6014 "Float8E5M2",
"Float8E5M2FNUZ",
"Float8E4M3",
"Float8E4M3FN",
6015 "Float8E4M3FNUZ",
"Float8E4M3B11FNUZ",
"Float8E3M4",
"Float8E8M0FNU",
6016 "Float6E3M2FN",
"Float6E2M3FN",
"Float4E2M1FN"};
6024 .
Case(
"Float8E5M2", &semFloat8E5M2)
6025 .
Case(
"Float8E4M3FN", &semFloat8E4M3FN)
6026 .
Case(
"Float4E2M1FN", &semFloat4E2M1FN)
6027 .
Case(
"Float6E3M2FN", &semFloat6E3M2FN)
6028 .
Case(
"Float6E2M3FN", &semFloat6E2M3FN)
6032APFloat::Storage::~Storage() {
6033 if (usesLayout<IEEEFloat>(*semantics)) {
6037 if (usesLayout<DoubleAPFloat>(*semantics)) {
6044APFloat::Storage::Storage(
const APFloat::Storage &
RHS) {
6045 if (usesLayout<IEEEFloat>(*
RHS.semantics)) {
6049 if (usesLayout<DoubleAPFloat>(*
RHS.semantics)) {
6056APFloat::Storage::Storage(APFloat::Storage &&
RHS) {
6057 if (usesLayout<IEEEFloat>(*
RHS.semantics)) {
6061 if (usesLayout<DoubleAPFloat>(*
RHS.semantics)) {
6068APFloat::Storage &APFloat::Storage::operator=(
const APFloat::Storage &
RHS) {
6069 if (usesLayout<IEEEFloat>(*semantics) &&
6070 usesLayout<IEEEFloat>(*
RHS.semantics)) {
6072 }
else if (usesLayout<DoubleAPFloat>(*semantics) &&
6073 usesLayout<DoubleAPFloat>(*
RHS.semantics)) {
6075 }
else if (
this != &
RHS) {
6077 new (
this) Storage(
RHS);
6082APFloat::Storage &APFloat::Storage::operator=(APFloat::Storage &&
RHS) {
6083 if (usesLayout<IEEEFloat>(*semantics) &&
6084 usesLayout<IEEEFloat>(*
RHS.semantics)) {
6086 }
else if (usesLayout<DoubleAPFloat>(*semantics) &&
6087 usesLayout<DoubleAPFloat>(*
RHS.semantics)) {
6089 }
else if (
this != &
RHS) {
6091 new (
this) Storage(std::move(
RHS));
6102 float result = LIBC_NAMESPACE::shared::expf(
X.convertToFloat());
6107 double result = LIBC_NAMESPACE::shared::exp(
X.convertToDouble());
6116#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.
static bool isSigned(unsigned 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)
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)
Expected< opStatus > convertFromString(StringRef, roundingMode)
Fill this APFloat with the result of a string conversion.
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.
Represent a constant reference to an array (0 or more elements consecutively in memory),...
size_t size() const
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.
This class is used to gather all the unique data bits of a node.
Represent a mutable reference to an array (0 or more elements consecutively in memory),...
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...
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
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
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
Get the string size.
char front() const
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)
APInt getNaNPayload() const
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)
APInt getNaNPayload() const
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.
LLVM_READONLY APFloat exp(const APFloat &X, RoundingMode RM=APFloat::rmNearestTiesToEven)
Implement IEEE 754-2019 exp functions.
@ 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