23#include "llvm/Config/llvm-config.h"
31#define APFLOAT_DISPATCH_ON_SEMANTICS(METHOD_CALL) \
33 if (usesLayout<IEEEFloat>(getSemantics())) \
34 return U.IEEE.METHOD_CALL; \
35 if (usesLayout<DoubleAPFloat>(getSemantics())) \
36 return U.Double.METHOD_CALL; \
37 llvm_unreachable("Unexpected semantics"); \
48#define PackCategoriesIntoKey(_lhs, _rhs) ((_lhs) * 4 + (_rhs))
357 if (Src.maxExponent >= Dst.maxExponent || Src.minExponent <= Dst.minExponent)
365 return Dst.precision >= Src.precision;
403static inline unsigned int
417 unsigned int absExponent;
418 const unsigned int overlargeExponent = 24000;
422 if (p == end || ((*p ==
'-' || *p ==
'+') && (p + 1) == end)) {
426 isNegative = (*p ==
'-');
427 if (*p ==
'-' || *p ==
'+') {
434 if (absExponent >= 10U)
435 return createError(
"Invalid character in exponent");
437 for (; p != end; ++p) {
442 return createError(
"Invalid character in exponent");
444 absExponent = absExponent * 10U +
value;
445 if (absExponent >= overlargeExponent) {
446 absExponent = overlargeExponent;
452 return -(int) absExponent;
454 return (
int) absExponent;
461 int exponentAdjustment) {
462 int unsignedExponent;
463 bool negative, overflow;
469 negative = *p ==
'-';
470 if (*p ==
'-' || *p ==
'+') {
476 unsignedExponent = 0;
478 for (; p != end; ++p) {
483 return createError(
"Invalid character in exponent");
485 unsignedExponent = unsignedExponent * 10 +
value;
486 if (unsignedExponent > 32767) {
492 if (exponentAdjustment > 32767 || exponentAdjustment < -32768)
496 exponent = unsignedExponent;
498 exponent = -exponent;
499 exponent += exponentAdjustment;
500 if (exponent > 32767 || exponent < -32768)
505 exponent = negative ? -32768: 32767;
515 while (p != end && *p ==
'0')
518 if (p != end && *p ==
'.') {
521 if (end - begin == 1)
524 while (p != end && *p ==
'0')
557 return PtrOrErr.takeError();
560 D->firstSigDigit = p;
562 D->normalizedExponent = 0;
564 for (; p != end; ++p) {
567 return createError(
"String contains multiple dots");
577 if (*p !=
'e' && *p !=
'E')
578 return createError(
"Invalid character in significand");
581 if (dot != end && p - begin == 1)
587 return ExpOrErr.takeError();
588 D->exponent = *ExpOrErr;
596 if (p !=
D->firstSigDigit) {
602 while (p != begin && *p ==
'0');
603 while (p != begin && *p ==
'.');
608 D->normalizedExponent = (
D->exponent +
610 - (dot >
D->firstSigDigit && dot < p)));
622 unsigned int digitValue) {
623 unsigned int hexDigit;
629 else if (digitValue < 8 && digitValue > 0)
633 while (p != end && (*p ==
'0' || *p ==
'.'))
637 return createError(
"Invalid trailing hexadecimal fraction!");
639 hexDigit = hexDigitValue(*p);
643 if (hexDigit == UINT_MAX)
653 unsigned int partCount,
682 return lost_fraction;
697 return moreSignificant;
708HUerrBound(
bool inexactMultiply,
unsigned int HUerr1,
unsigned int HUerr2)
710 assert(HUerr1 < 2 || HUerr2 < 2 || (HUerr1 + HUerr2 < 8));
712 if (HUerr1 + HUerr2 == 0)
713 return inexactMultiply * 2;
715 return inexactMultiply + 2 * (HUerr1 + HUerr2);
724 unsigned int count, partBits;
741 if (part - boundary <= boundary - part)
742 return part - boundary;
744 return boundary - part;
747 if (part == boundary) {
753 }
else if (part == boundary - 1) {
770 pow5s[0] = 78125 * 5;
772 unsigned int partsCount = 1;
780 *p1 = firstEightPowers[power & 7];
786 for (
unsigned int n = 0; power; power >>= 1, n++) {
790 partsCount, partsCount);
792 if (pow5[partsCount - 1] == 0)
800 result += partsCount;
801 if (p2[result - 1] == 0)
826static const char NaNL[] =
"nan";
827static const char NaNU[] =
"NAN";
834 const char *hexDigitChars)
836 unsigned int result =
count;
842 dst[
count] = hexDigitChars[part & 0xf];
882void IEEEFloat::initialize(
const fltSemantics *ourSemantics) {
885 semantics = ourSemantics;
891void IEEEFloat::freeSignificand() {
893 delete [] significand.parts;
896void IEEEFloat::assign(
const IEEEFloat &rhs) {
897 assert(semantics == rhs.semantics);
900 category = rhs.category;
901 exponent = rhs.exponent;
903 copySignificand(rhs);
906void IEEEFloat::copySignificand(
const IEEEFloat &rhs) {
908 assert(rhs.partCount() >= partCount());
923 exponent = exponentNaN();
926 unsigned numParts = partCount();
939 fill = &fill_storage;
950 unsigned bitsToPreserve = semantics->
precision - 1;
951 unsigned part = bitsToPreserve / 64;
952 bitsToPreserve %= 64;
953 significand[part] &= ((1ULL << bitsToPreserve) - 1);
954 for (part++; part != numParts; ++part)
955 significand[part] = 0;
958 unsigned QNaNBit = semantics->
precision - 2;
986 if (semantics != rhs.semantics) {
988 initialize(rhs.semantics);
999 semantics = rhs.semantics;
1000 significand = rhs.significand;
1001 exponent = rhs.exponent;
1002 category = rhs.category;
1020 significandMSB() == 0;
1025 isSignificandAllZerosExceptMSB();
1028bool IEEEFloat::isSignificandAllOnes()
const {
1033 for (
unsigned i = 0; i < PartCount - 1; i++)
1038 const unsigned NumHighBits =
1040 assert(NumHighBits <= integerPartWidth && NumHighBits > 0 &&
1041 "Can not have more high bits to fill than integerPartWidth");
1044 if (~(Parts[PartCount - 1] | HighBitFill))
1050bool IEEEFloat::isSignificandAllOnesExceptLSB()
const {
1059 for (
unsigned i = 0; i < PartCount - 1; i++) {
1060 if (~Parts[i] & ~
unsigned{!i})
1065 const unsigned NumHighBits =
1067 assert(NumHighBits <= integerPartWidth && NumHighBits > 0 &&
1068 "Can not have more high bits to fill than integerPartWidth");
1071 if (~(Parts[PartCount - 1] | HighBitFill | 0x1))
1077bool IEEEFloat::isSignificandAllZeros()
const {
1083 for (
unsigned i = 0; i < PartCount - 1; i++)
1088 const unsigned NumHighBits =
1091 "clear than integerPartWidth");
1092 const integerPart HighBitMask = ~integerPart(0) >> NumHighBits;
1094 if (Parts[PartCount - 1] & HighBitMask)
1100bool IEEEFloat::isSignificandAllZerosExceptMSB()
const {
1104 for (
unsigned i = 0; i < PartCount - 1; i++) {
1109 const unsigned NumHighBits =
1122 isSignificandAllOnesExceptLSB();
1127 isSignificandAllOnes();
1142 if (semantics != rhs.semantics ||
1143 category != rhs.category ||
1152 return std::equal(significandParts(), significandParts() + partCount(),
1153 rhs.significandParts());
1157 initialize(&ourSemantics);
1162 significandParts()[0] =
value;
1167 initialize(&ourSemantics);
1177 initialize(rhs.semantics);
1182 *
this = std::move(rhs);
1187unsigned int IEEEFloat::partCount()
const {
1192 return const_cast<IEEEFloat *
>(
this)->significandParts();
1196 if (partCount() > 1)
1197 return significand.parts;
1199 return &significand.part;
1202void IEEEFloat::zeroSignificand() {
1207void IEEEFloat::incrementSignificand() {
1221 parts = significandParts();
1223 assert(semantics == rhs.semantics);
1224 assert(exponent == rhs.exponent);
1226 return APInt::tcAdd(parts, rhs.significandParts(), 0, partCount());
1232 integerPart borrow) {
1235 parts = significandParts();
1237 assert(semantics == rhs.semantics);
1238 assert(exponent == rhs.exponent);
1247lostFraction IEEEFloat::multiplySignificand(
const IEEEFloat &rhs,
1250 unsigned int partsCount, newPartsCount, precision;
1257 assert(semantics == rhs.semantics);
1265 if (newPartsCount > 4)
1268 fullSignificand = scratch;
1270 lhsSignificand = significandParts();
1271 partsCount = partCount();
1274 rhs.significandParts(), partsCount, partsCount);
1277 omsb =
APInt::tcMSB(fullSignificand, newPartsCount) + 1;
1278 exponent += rhs.exponent;
1292 if (addend.isNonZero()) {
1296 Significand savedSignificand = significand;
1300 unsigned int extendedPrecision;
1303 extendedPrecision = 2 * precision + 1;
1304 if (omsb != extendedPrecision - 1) {
1305 assert(extendedPrecision > omsb);
1307 (extendedPrecision - 1) - omsb);
1308 exponent -= (extendedPrecision - 1) - omsb;
1312 extendedSemantics = *semantics;
1313 extendedSemantics.
precision = extendedPrecision;
1315 if (newPartsCount == 1)
1316 significand.part = fullSignificand[0];
1318 significand.parts = fullSignificand;
1319 semantics = &extendedSemantics;
1332 lost_fraction = extendedAddend.shiftSignificandRight(1);
1334 "Lost precision while shifting addend for fused-multiply-add.");
1336 lost_fraction = addOrSubtractSignificand(extendedAddend,
false);
1339 if (newPartsCount == 1)
1340 fullSignificand[0] = significand.part;
1341 significand = savedSignificand;
1342 semantics = savedSemantics;
1344 omsb =
APInt::tcMSB(fullSignificand, newPartsCount) + 1;
1351 exponent -= precision + 1;
1360 if (omsb > precision) {
1361 unsigned int bits, significantParts;
1364 bits = omsb - precision;
1366 lf =
shiftRight(fullSignificand, significantParts, bits);
1373 if (newPartsCount > 4)
1374 delete [] fullSignificand;
1376 return lost_fraction;
1379lostFraction IEEEFloat::multiplySignificand(
const IEEEFloat &rhs) {
1380 return multiplySignificand(rhs,
IEEEFloat(*semantics));
1384lostFraction IEEEFloat::divideSignificand(
const IEEEFloat &rhs) {
1385 unsigned int bit, i, partsCount;
1391 assert(semantics == rhs.semantics);
1393 lhsSignificand = significandParts();
1394 rhsSignificand = rhs.significandParts();
1395 partsCount = partCount();
1402 divisor = dividend + partsCount;
1405 for (i = 0; i < partsCount; i++) {
1406 dividend[i] = lhsSignificand[i];
1407 divisor[i] = rhsSignificand[i];
1408 lhsSignificand[i] = 0;
1411 exponent -= rhs.exponent;
1413 unsigned int precision = semantics->
precision;
1416 bit = precision -
APInt::tcMSB(divisor, partsCount) - 1;
1423 bit = precision -
APInt::tcMSB(dividend, partsCount) - 1;
1439 for (bit = precision; bit; bit -= 1) {
1463 return lost_fraction;
1466unsigned int IEEEFloat::significandMSB()
const {
1470unsigned int IEEEFloat::significandLSB()
const {
1475lostFraction IEEEFloat::shiftSignificandRight(
unsigned int bits) {
1481 return shiftRight(significandParts(), partCount(), bits);
1485void IEEEFloat::shiftSignificandLeft(
unsigned int bits) {
1486 assert(bits < semantics->precision);
1489 unsigned int partsCount = partCount();
1502 assert(semantics == rhs.semantics);
1506 compare = exponent - rhs.exponent;
1573bool IEEEFloat::roundAwayFromZero(roundingMode rounding_mode,
1575 unsigned int bit)
const {
1582 switch (rounding_mode) {
1620 omsb = significandMSB() + 1;
1626 exponentChange = omsb - semantics->
precision;
1630 if (exponent + exponentChange > semantics->
maxExponent)
1631 return handleOverflow(rounding_mode);
1635 if (exponent + exponentChange < semantics->minExponent)
1636 exponentChange = semantics->
minExponent - exponent;
1639 if (exponentChange < 0) {
1642 shiftSignificandLeft(-exponentChange);
1647 if (exponentChange > 0) {
1651 lf = shiftSignificandRight(exponentChange);
1656 if (omsb > (
unsigned) exponentChange)
1657 omsb -= exponentChange;
1667 exponent == semantics->
maxExponent && isSignificandAllOnes())
1668 return handleOverflow(rounding_mode);
1687 if (roundAwayFromZero(rounding_mode, lost_fraction, 0)) {
1691 incrementSignificand();
1692 omsb = significandMSB() + 1;
1695 if (omsb == (
unsigned) semantics->
precision + 1) {
1706 shiftSignificandRight(1);
1715 exponent == semantics->
maxExponent && isSignificandAllOnes())
1716 return handleOverflow(rounding_mode);
1725 assert(omsb < semantics->precision);
1795lostFraction IEEEFloat::addOrSubtractSignificand(
const IEEEFloat &rhs,
1803 subtract ^=
static_cast<bool>(sign ^ rhs.sign);
1806 bits = exponent - rhs.exponent;
1814 else if (bits > 0) {
1815 lost_fraction = temp_rhs.shiftSignificandRight(bits - 1);
1816 shiftSignificandLeft(1);
1818 lost_fraction = shiftSignificandRight(-bits - 1);
1819 temp_rhs.shiftSignificandLeft(1);
1824 carry = temp_rhs.subtractSignificand
1826 copySignificand(temp_rhs);
1829 carry = subtractSignificand
1848 lost_fraction = temp_rhs.shiftSignificandRight(bits);
1849 carry = addSignificand(temp_rhs);
1851 lost_fraction = shiftSignificandRight(-bits);
1852 carry = addSignificand(rhs);
1860 return lost_fraction;
2045 roundingMode rounding_mode,
2049 fs = addOrSubtractSpecials(rhs,
subtract);
2055 lost_fraction = addOrSubtractSignificand(rhs,
subtract);
2056 fs = normalize(rounding_mode, lost_fraction);
2065 if (category ==
fcZero) {
2079 return addOrSubtract(rhs, rounding_mode,
false);
2085 return addOrSubtract(rhs, rounding_mode,
true);
2094 fs = multiplySpecials(rhs);
2100 fs = normalize(rounding_mode, lost_fraction);
2114 fs = divideSpecials(rhs);
2120 fs = normalize(rounding_mode, lost_fraction);
2131 unsigned int origSign = sign;
2134 fs = remainderSpecials(rhs);
2241 fs = modSpecials(rhs);
2242 unsigned int origSign = sign;
2272 sign ^= multiplicand.sign;
2281 lost_fraction = multiplySignificand(multiplicand, addend);
2282 fs = normalize(rounding_mode, lost_fraction);
2295 fs = multiplySpecials(multiplicand);
2305 fs = addOrSubtract(addend, rounding_mode,
false);
2378 MagicConstant.sign = sign;
2384 fs =
add(MagicConstant, rounding_mode);
2388 subtract(MagicConstant, rounding_mode);
2402 assert(semantics == rhs.semantics);
2434 if (sign == rhs.sign)
2449 if (sign != rhs.sign) {
2480 unsigned int newPartCount, oldPartCount;
2488 oldPartCount = partCount();
2491 bool X86SpecialNan =
false;
2494 (!(*significandParts() & 0x8000000000000000ULL) ||
2495 !(*significandParts() & 0x4000000000000000ULL))) {
2498 X86SpecialNan =
true;
2509 int omsb = significandMSB() + 1;
2510 int exponentChange = omsb - fromSemantics.
precision;
2511 if (exponent + exponentChange < toSemantics.
minExponent)
2512 exponentChange = toSemantics.
minExponent - exponent;
2513 if (exponentChange < shift)
2514 exponentChange = shift;
2515 if (exponentChange < 0) {
2516 shift -= exponentChange;
2517 exponent += exponentChange;
2518 }
else if (omsb <= -shift) {
2519 exponentChange = omsb + shift - 1;
2520 shift -= exponentChange;
2521 exponent += exponentChange;
2532 if (newPartCount > oldPartCount) {
2540 significand.parts = newParts;
2541 }
else if (newPartCount == 1 && oldPartCount != 1) {
2545 newPart = significandParts()[0];
2547 significand.part = newPart;
2551 semantics = &toSemantics;
2560 *losesInfo = (fs !=
opOK);
2561 }
else if (category ==
fcNaN) {
2596 }
else if (category ==
fcZero &&
2624 roundingMode rounding_mode,
bool *isExact)
const {
2627 unsigned int dstPartsCount, truncatedBits;
2636 assert(dstPartsCount <= parts.
size() &&
"Integer too big");
2638 if (category ==
fcZero) {
2645 src = significandParts();
2654 truncatedBits = semantics->
precision -1U - exponent;
2658 unsigned int bits = exponent + 1U;
2664 if (bits < semantics->precision) {
2666 truncatedBits = semantics->
precision - bits;
2680 if (truncatedBits) {
2684 roundAwayFromZero(rounding_mode, lost_fraction, truncatedBits)) {
2704 if (omsb == width &&
2741 fs = convertToSignExtendedInteger(parts, width,
isSigned, rounding_mode,
2745 unsigned int bits, dstPartsCount;
2748 assert(dstPartsCount <= parts.
size() &&
"Integer too big");
2750 if (category ==
fcNaN)
2769 const integerPart *src,
unsigned int srcCount, roundingMode rounding_mode) {
2770 unsigned int omsb, precision, dstCount;
2776 dst = significandParts();
2777 dstCount = partCount();
2782 if (precision <= omsb) {
2783 exponent = omsb - 1;
2788 exponent = precision - 1;
2793 return normalize(rounding_mode, lost_fraction);
2807 return convertFromUnsignedParts(api.
getRawData(), partCount, rounding_mode);
2815 unsigned int srcCount,
bool isSigned,
2828 status = convertFromUnsignedParts(
copy, srcCount, rounding_mode);
2832 status = convertFromUnsignedParts(src, srcCount, rounding_mode);
2852 return convertFromUnsignedParts(api.
getRawData(), partCount, rounding_mode);
2856IEEEFloat::convertFromHexadecimalString(
StringRef s,
2857 roundingMode rounding_mode) {
2865 unsigned partsCount = partCount();
2867 bool computedTrailingFraction =
false;
2875 return PtrOrErr.takeError();
2884 return createError(
"String contains multiple dots");
2889 hex_value = hexDigitValue(*p);
2890 if (hex_value == UINT_MAX)
2900 }
else if (!computedTrailingFraction) {
2903 return FractOrErr.takeError();
2904 lost_fraction = *FractOrErr;
2905 computedTrailingFraction =
true;
2911 return createError(
"Hex strings require an exponent");
2912 if (*p !=
'p' && *p !=
'P')
2913 return createError(
"Invalid character in significand");
2916 if (dot != end && p - begin == 1)
2920 if (p != firstSignificantDigit) {
2929 expAdjustment =
static_cast<int>(
dot - firstSignificantDigit);
2930 if (expAdjustment < 0)
2932 expAdjustment = expAdjustment * 4 - 1;
2942 return ExpOrErr.takeError();
2943 exponent = *ExpOrErr;
2946 return normalize(rounding_mode, lost_fraction);
2950IEEEFloat::roundSignificandWithExponent(
const integerPart *decSigParts,
2951 unsigned sigPartCount,
int exp,
2952 roundingMode rounding_mode) {
2953 unsigned int parts, pow5PartCount;
2964 pow5PartCount =
powerOf5(pow5Parts, exp >= 0 ? exp: -exp);
2966 for (;; parts *= 2) {
2968 unsigned int excessPrecision, truncatedBits;
2972 truncatedBits = excessPrecision;
2975 decSig.makeZero(sign);
2978 sigStatus = decSig.convertFromUnsignedParts(decSigParts, sigPartCount,
2980 powStatus = pow5.convertFromUnsignedParts(pow5Parts, pow5PartCount,
2983 decSig.exponent += exp;
2987 unsigned int powHUerr;
2991 calcLostFraction = decSig.multiplySignificand(pow5);
2992 powHUerr = powStatus !=
opOK;
2994 calcLostFraction = decSig.divideSignificand(pow5);
2997 excessPrecision += (semantics->
minExponent - decSig.exponent);
2998 truncatedBits = excessPrecision;
2999 if (excessPrecision > calcSemantics.
precision)
3000 excessPrecision = calcSemantics.
precision;
3009 (decSig.significandParts(), calcSemantics.
precision - 1) == 1);
3014 excessPrecision, isNearest);
3017 if (HUdistance >= HUerr) {
3018 APInt::tcExtract(significandParts(), partCount(), decSig.significandParts(),
3019 calcSemantics.
precision - excessPrecision,
3024 exponent = (decSig.exponent + semantics->
precision
3025 - (calcSemantics.
precision - excessPrecision));
3029 return normalize(rounding_mode, calcLostFraction);
3035IEEEFloat::convertFromDecimalString(
StringRef str, roundingMode rounding_mode) {
3042 return std::move(Err);
3076 }
else if (
D.normalizedExponent - 1 > INT_MAX / 42039) {
3077 fs = handleOverflow(rounding_mode);
3083 }
else if (
D.normalizedExponent - 1 < INT_MIN / 42039 ||
3084 (
D.normalizedExponent + 1) * 28738 <=
3092 }
else if ((
D.normalizedExponent - 1) * 42039
3095 fs = handleOverflow(rounding_mode);
3098 unsigned int partCount;
3104 partCount =
static_cast<unsigned int>(
D.lastSigDigit -
D.firstSigDigit) + 1;
3122 if (p == str.
end()) {
3127 if (decValue >= 10U) {
3128 delete[] decSignificand;
3129 return createError(
"Invalid character in significand");
3132 val = val * 10 + decValue;
3135 }
while (p <=
D.lastSigDigit && multiplier <= (~ (
integerPart) 0 - 9) / 10);
3139 partCount, partCount + 1,
false);
3143 if (decSignificand[partCount])
3145 }
while (p <=
D.lastSigDigit);
3148 fs = roundSignificandWithExponent(decSignificand, partCount,
3149 D.exponent, rounding_mode);
3151 delete [] decSignificand;
3157bool IEEEFloat::convertFromStringSpecials(
StringRef str) {
3158 const size_t MIN_NAME_SIZE = 3;
3160 if (str.
size() < MIN_NAME_SIZE)
3163 if (str ==
"inf" || str ==
"INFINITY" || str ==
"+Inf") {
3168 bool IsNegative = str.
front() ==
'-';
3171 if (str.
size() < MIN_NAME_SIZE)
3174 if (str ==
"inf" || str ==
"INFINITY" || str ==
"Inf") {
3181 bool IsSignaling = str.
front() ==
's' || str.
front() ==
'S';
3184 if (str.
size() < MIN_NAME_SIZE)
3193 makeNaN(IsSignaling, IsNegative);
3198 if (str.
front() ==
'(') {
3200 if (str.
size() <= 2 || str.
back() !=
')')
3207 unsigned Radix = 10;
3208 if (str[0] ==
'0') {
3209 if (str.
size() > 1 && tolower(str[1]) ==
'x') {
3219 makeNaN(IsSignaling, IsNegative, &Payload);
3233 if (convertFromStringSpecials(str))
3238 size_t slen = str.
size();
3239 sign = *p ==
'-' ? 1 : 0;
3240 if (*p ==
'-' || *p ==
'+') {
3247 if (slen >= 2 && p[0] ==
'0' && (p[1] ==
'x' || p[1] ==
'X')) {
3250 return convertFromHexadecimalString(
StringRef(p + 2, slen - 2),
3254 return convertFromDecimalString(
StringRef(p, slen), rounding_mode);
3298 dst +=
sizeof NaNU - 1;
3303 *dst++ = upperCase ?
'X':
'x';
3305 if (hexDigits > 1) {
3307 memset (dst,
'0', hexDigits - 1);
3308 dst += hexDigits - 1;
3310 *dst++ = upperCase ?
'P':
'p';
3315 dst = convertNormalToHexString (dst, hexDigits, upperCase, rounding_mode);
3321 return static_cast<unsigned int>(dst - p);
3328char *IEEEFloat::convertNormalToHexString(
char *dst,
unsigned int hexDigits,
3330 roundingMode rounding_mode)
const {
3331 unsigned int count, valueBits, shift, partsCount, outputDigits;
3332 const char *hexDigitChars;
3338 *dst++ = upperCase ?
'X':
'x';
3343 significand = significandParts();
3344 partsCount = partCount();
3353 outputDigits = (valueBits - significandLSB () + 3) / 4;
3359 if (hexDigits < outputDigits) {
3365 bits = valueBits - hexDigits * 4;
3367 roundUp = roundAwayFromZero(rounding_mode, fraction, bits);
3369 outputDigits = hexDigits;
3379 while (outputDigits &&
count) {
3383 if (--
count == partsCount)
3386 part = significand[
count] << shift;
3394 if (curDigits > outputDigits)
3395 curDigits = outputDigits;
3396 dst +=
partAsHex (dst, part, curDigits, hexDigitChars);
3397 outputDigits -= curDigits;
3406 *
q = hexDigitChars[hexDigitValue (*q) + 1];
3407 }
while (*q ==
'0');
3411 memset (dst,
'0', outputDigits);
3412 dst += outputDigits;
3425 *dst++ = upperCase ?
'P':
'p';
3434 Arg.
isNaN() ? (uint8_t)0 : (uint8_t)Arg.sign,
3438 return hash_combine((uint8_t)Arg.category, (uint8_t)Arg.sign,
3441 Arg.significandParts(),
3442 Arg.significandParts() + Arg.partCount()));
3454APInt IEEEFloat::convertF80LongDoubleAPFloatToAPInt()
const {
3458 uint64_t myexponent, mysignificand;
3461 myexponent = exponent+16383;
3462 mysignificand = significandParts()[0];
3463 if (myexponent==1 && !(mysignificand & 0x8000000000000000ULL))
3465 }
else if (category==
fcZero) {
3469 myexponent = 0x7fff;
3470 mysignificand = 0x8000000000000000ULL;
3473 myexponent = 0x7fff;
3474 mysignificand = significandParts()[0];
3478 words[0] = mysignificand;
3479 words[1] = ((
uint64_t)(sign & 1) << 15) |
3480 (myexponent & 0x7fffLL);
3481 return APInt(80, words);
3484APInt IEEEFloat::convertPPCDoubleDoubleAPFloatToAPInt()
const {
3509 words[0] = *
u.convertDoubleAPFloatToAPInt().getRawData();
3515 if (
u.isFiniteNonZero() && losesInfo) {
3525 words[1] = *
v.convertDoubleAPFloatToAPInt().getRawData();
3530 return APInt(128, words);
3533template <const fltSemantics &S>
3534APInt IEEEFloat::convertIEEEFloatToAPInt()
const {
3537 constexpr int bias = -(S.minExponent - 1);
3538 constexpr unsigned int trailing_significand_bits = S.precision - 1;
3539 constexpr int integer_bit_part = trailing_significand_bits /
integerPartWidth;
3542 constexpr uint64_t significand_mask = integer_bit - 1;
3543 constexpr unsigned int exponent_bits =
3544 S.sizeInBits - 1 - trailing_significand_bits;
3545 static_assert(exponent_bits < 64);
3553 myexponent = exponent + bias;
3554 std::copy_n(significandParts(), mysignificand.size(),
3555 mysignificand.begin());
3556 if (myexponent == 1 &&
3557 !(significandParts()[integer_bit_part] & integer_bit))
3559 }
else if (category ==
fcZero) {
3560 myexponent = ::exponentZero(S) + bias;
3561 mysignificand.fill(0);
3566 myexponent = ::exponentInf(S) + bias;
3567 mysignificand.fill(0);
3572 myexponent = ::exponentNaN(S) + bias;
3573 std::copy_n(significandParts(), mysignificand.size(),
3574 mysignificand.begin());
3576 std::array<
uint64_t, (S.sizeInBits + 63) / 64> words;
3578 std::copy_n(mysignificand.begin(), mysignificand.size(), words.begin());
3579 if constexpr (significand_mask != 0) {
3581 words[mysignificand.size() - 1] &= significand_mask;
3583 std::fill(words_iter, words.end(),
uint64_t{0});
3584 constexpr size_t last_word = words.size() - 1;
3586 << ((S.sizeInBits - 1) % 64);
3587 words[last_word] |= shifted_sign;
3588 uint64_t shifted_exponent = (myexponent & exponent_mask)
3589 << (trailing_significand_bits % 64);
3590 words[last_word] |= shifted_exponent;
3591 if constexpr (last_word == 0) {
3592 return APInt(S.sizeInBits, words[0]);
3594 return APInt(S.sizeInBits, words);
3597APInt IEEEFloat::convertQuadrupleAPFloatToAPInt()
const {
3598 assert(partCount() == 2);
3599 return convertIEEEFloatToAPInt<semIEEEquad>();
3602APInt IEEEFloat::convertDoubleAPFloatToAPInt()
const {
3604 return convertIEEEFloatToAPInt<semIEEEdouble>();
3607APInt IEEEFloat::convertFloatAPFloatToAPInt()
const {
3609 return convertIEEEFloatToAPInt<semIEEEsingle>();
3612APInt IEEEFloat::convertBFloatAPFloatToAPInt()
const {
3613 assert(partCount() == 1);
3614 return convertIEEEFloatToAPInt<semBFloat>();
3617APInt IEEEFloat::convertHalfAPFloatToAPInt()
const {
3619 return convertIEEEFloatToAPInt<semIEEEhalf>();
3622APInt IEEEFloat::convertFloat8E5M2APFloatToAPInt()
const {
3623 assert(partCount() == 1);
3624 return convertIEEEFloatToAPInt<semFloat8E5M2>();
3627APInt IEEEFloat::convertFloat8E5M2FNUZAPFloatToAPInt()
const {
3628 assert(partCount() == 1);
3629 return convertIEEEFloatToAPInt<semFloat8E5M2FNUZ>();
3632APInt IEEEFloat::convertFloat8E4M3APFloatToAPInt()
const {
3633 assert(partCount() == 1);
3634 return convertIEEEFloatToAPInt<semFloat8E4M3>();
3637APInt IEEEFloat::convertFloat8E4M3FNAPFloatToAPInt()
const {
3638 assert(partCount() == 1);
3639 return convertIEEEFloatToAPInt<semFloat8E4M3FN>();
3642APInt IEEEFloat::convertFloat8E4M3FNUZAPFloatToAPInt()
const {
3643 assert(partCount() == 1);
3644 return convertIEEEFloatToAPInt<semFloat8E4M3FNUZ>();
3647APInt IEEEFloat::convertFloat8E4M3B11FNUZAPFloatToAPInt()
const {
3648 assert(partCount() == 1);
3649 return convertIEEEFloatToAPInt<semFloat8E4M3B11FNUZ>();
3652APInt IEEEFloat::convertFloat8E3M4APFloatToAPInt()
const {
3653 assert(partCount() == 1);
3654 return convertIEEEFloatToAPInt<semFloat8E3M4>();
3657APInt IEEEFloat::convertFloatTF32APFloatToAPInt()
const {
3658 assert(partCount() == 1);
3659 return convertIEEEFloatToAPInt<semFloatTF32>();
3662APInt IEEEFloat::convertFloat6E3M2FNAPFloatToAPInt()
const {
3663 assert(partCount() == 1);
3664 return convertIEEEFloatToAPInt<semFloat6E3M2FN>();
3667APInt IEEEFloat::convertFloat6E2M3FNAPFloatToAPInt()
const {
3668 assert(partCount() == 1);
3669 return convertIEEEFloatToAPInt<semFloat6E2M3FN>();
3672APInt IEEEFloat::convertFloat4E2M1FNAPFloatToAPInt()
const {
3673 assert(partCount() == 1);
3674 return convertIEEEFloatToAPInt<semFloat4E2M1FN>();
3683 return convertHalfAPFloatToAPInt();
3686 return convertBFloatAPFloatToAPInt();
3689 return convertFloatAPFloatToAPInt();
3692 return convertDoubleAPFloatToAPInt();
3695 return convertQuadrupleAPFloatToAPInt();
3698 return convertPPCDoubleDoubleAPFloatToAPInt();
3701 return convertFloat8E5M2APFloatToAPInt();
3704 return convertFloat8E5M2FNUZAPFloatToAPInt();
3707 return convertFloat8E4M3APFloatToAPInt();
3710 return convertFloat8E4M3FNAPFloatToAPInt();
3713 return convertFloat8E4M3FNUZAPFloatToAPInt();
3716 return convertFloat8E4M3B11FNUZAPFloatToAPInt();
3719 return convertFloat8E3M4APFloatToAPInt();
3722 return convertFloatTF32APFloatToAPInt();
3725 return convertFloat6E3M2FNAPFloatToAPInt();
3728 return convertFloat6E2M3FNAPFloatToAPInt();
3731 return convertFloat4E2M1FNAPFloatToAPInt();
3735 return convertF80LongDoubleAPFloatToAPInt();
3740 "Float semantics are not IEEEsingle");
3747 "Float semantics are not IEEEdouble");
3752#ifdef HAS_IEE754_FLOAT128
3753float128 IEEEFloat::convertToQuad()
const {
3755 "Float semantics are not IEEEquads");
3757 return api.bitsToQuad();
3768void IEEEFloat::initFromF80LongDoubleAPInt(
const APInt &api) {
3771 uint64_t myexponent = (i2 & 0x7fff);
3773 uint8_t myintegerbit = mysignificand >> 63;
3778 sign =
static_cast<unsigned int>(i2>>15);
3779 if (myexponent == 0 && mysignificand == 0) {
3781 }
else if (myexponent==0x7fff && mysignificand==0x8000000000000000ULL) {
3783 }
else if ((myexponent == 0x7fff && mysignificand != 0x8000000000000000ULL) ||
3784 (myexponent != 0x7fff && myexponent != 0 && myintegerbit == 0)) {
3786 exponent = exponentNaN();
3787 significandParts()[0] = mysignificand;
3788 significandParts()[1] = 0;
3791 exponent = myexponent - 16383;
3792 significandParts()[0] = mysignificand;
3793 significandParts()[1] = 0;
3799void IEEEFloat::initFromPPCDoubleDoubleAPInt(
const APInt &api) {
3806 initFromDoubleAPInt(
APInt(64, i1));
3822template <const fltSemantics &S>
3823void IEEEFloat::initFromIEEEAPInt(
const APInt &api) {
3827 constexpr uint64_t significand_mask = integer_bit - 1;
3828 constexpr unsigned int trailing_significand_bits = S.precision - 1;
3829 constexpr unsigned int stored_significand_parts =
3831 constexpr unsigned int exponent_bits =
3832 S.sizeInBits - 1 - trailing_significand_bits;
3833 static_assert(exponent_bits < 64);
3835 constexpr int bias = -(S.minExponent - 1);
3839 std::array<integerPart, stored_significand_parts> mysignificand;
3840 std::copy_n(api.
getRawData(), mysignificand.size(), mysignificand.begin());
3841 if constexpr (significand_mask != 0) {
3842 mysignificand[mysignificand.size() - 1] &= significand_mask;
3849 (last_word >> (trailing_significand_bits % 64)) & exponent_mask;
3852 assert(partCount() == mysignificand.size());
3854 sign =
static_cast<unsigned int>(last_word >> ((S.sizeInBits - 1) % 64));
3856 bool all_zero_significand =
3859 bool is_zero = myexponent == 0 && all_zero_significand;
3862 if (myexponent - bias == ::exponentInf(S) && all_zero_significand) {
3871 is_nan = myexponent - bias == ::exponentNaN(S) && !all_zero_significand;
3873 bool all_ones_significand =
3874 std::all_of(mysignificand.begin(), mysignificand.end() - 1,
3875 [](
integerPart bits) { return bits == ~integerPart{0}; }) &&
3876 (!significand_mask ||
3877 mysignificand[mysignificand.size() - 1] == significand_mask);
3878 is_nan = myexponent - bias == ::exponentNaN(S) && all_ones_significand;
3886 std::copy_n(mysignificand.begin(), mysignificand.size(),
3887 significandParts());
3897 exponent = myexponent - bias;
3898 std::copy_n(mysignificand.begin(), mysignificand.size(), significandParts());
3899 if (myexponent == 0)
3900 exponent = S.minExponent;
3902 significandParts()[mysignificand.size()-1] |= integer_bit;
3905void IEEEFloat::initFromQuadrupleAPInt(
const APInt &api) {
3906 initFromIEEEAPInt<semIEEEquad>(api);
3909void IEEEFloat::initFromDoubleAPInt(
const APInt &api) {
3910 initFromIEEEAPInt<semIEEEdouble>(api);
3913void IEEEFloat::initFromFloatAPInt(
const APInt &api) {
3914 initFromIEEEAPInt<semIEEEsingle>(api);
3917void IEEEFloat::initFromBFloatAPInt(
const APInt &api) {
3918 initFromIEEEAPInt<semBFloat>(api);
3921void IEEEFloat::initFromHalfAPInt(
const APInt &api) {
3922 initFromIEEEAPInt<semIEEEhalf>(api);
3925void IEEEFloat::initFromFloat8E5M2APInt(
const APInt &api) {
3926 initFromIEEEAPInt<semFloat8E5M2>(api);
3929void IEEEFloat::initFromFloat8E5M2FNUZAPInt(
const APInt &api) {
3930 initFromIEEEAPInt<semFloat8E5M2FNUZ>(api);
3933void IEEEFloat::initFromFloat8E4M3APInt(
const APInt &api) {
3934 initFromIEEEAPInt<semFloat8E4M3>(api);
3937void IEEEFloat::initFromFloat8E4M3FNAPInt(
const APInt &api) {
3938 initFromIEEEAPInt<semFloat8E4M3FN>(api);
3941void IEEEFloat::initFromFloat8E4M3FNUZAPInt(
const APInt &api) {
3942 initFromIEEEAPInt<semFloat8E4M3FNUZ>(api);
3945void IEEEFloat::initFromFloat8E4M3B11FNUZAPInt(
const APInt &api) {
3946 initFromIEEEAPInt<semFloat8E4M3B11FNUZ>(api);
3949void IEEEFloat::initFromFloat8E3M4APInt(
const APInt &api) {
3950 initFromIEEEAPInt<semFloat8E3M4>(api);
3953void IEEEFloat::initFromFloatTF32APInt(
const APInt &api) {
3954 initFromIEEEAPInt<semFloatTF32>(api);
3957void IEEEFloat::initFromFloat6E3M2FNAPInt(
const APInt &api) {
3958 initFromIEEEAPInt<semFloat6E3M2FN>(api);
3961void IEEEFloat::initFromFloat6E2M3FNAPInt(
const APInt &api) {
3962 initFromIEEEAPInt<semFloat6E2M3FN>(api);
3965void IEEEFloat::initFromFloat4E2M1FNAPInt(
const APInt &api) {
3966 initFromIEEEAPInt<semFloat4E2M1FN>(api);
3973 return initFromHalfAPInt(api);
3975 return initFromBFloatAPInt(api);
3977 return initFromFloatAPInt(api);
3979 return initFromDoubleAPInt(api);
3981 return initFromF80LongDoubleAPInt(api);
3983 return initFromQuadrupleAPInt(api);
3985 return initFromPPCDoubleDoubleAPInt(api);
3987 return initFromFloat8E5M2APInt(api);
3989 return initFromFloat8E5M2FNUZAPInt(api);
3991 return initFromFloat8E4M3APInt(api);
3993 return initFromFloat8E4M3FNAPInt(api);
3995 return initFromFloat8E4M3FNUZAPInt(api);
3997 return initFromFloat8E4M3B11FNUZAPInt(api);
3999 return initFromFloat8E3M4APInt(api);
4001 return initFromFloatTF32APInt(api);
4003 return initFromFloat6E3M2FNAPInt(api);
4005 return initFromFloat6E2M3FNAPInt(api);
4007 return initFromFloat4E2M1FNAPInt(api);
4014void IEEEFloat::makeLargest(
bool Negative) {
4021 exponent = semantics->maxExponent;
4025 unsigned PartCount = partCount();
4026 memset(significand, 0xFF,
sizeof(
integerPart)*(PartCount - 1));
4030 const unsigned NumUnusedHighBits =
4031 PartCount*integerPartWidth - semantics->precision;
4032 significand[PartCount - 1] = (NumUnusedHighBits < integerPartWidth)
4043void IEEEFloat::makeSmallest(
bool Negative) {
4050 exponent = semantics->minExponent;
4054void IEEEFloat::makeSmallestNormalized(
bool Negative) {
4063 exponent = semantics->minExponent;
4068 initFromAPInt(&Sem, API);
4071IEEEFloat::IEEEFloat(
float f) {
4075IEEEFloat::IEEEFloat(
double d) {
4081 Buffer.
append(Str.begin(), Str.end());
4086 void AdjustToPrecision(
APInt &significand,
4087 int &exp,
unsigned FormatPrecision) {
4091 unsigned bitsRequired = (FormatPrecision * 196 + 58) / 59;
4093 if (bits <= bitsRequired)
return;
4095 unsigned tensRemovable = (bits - bitsRequired) * 59 / 196;
4096 if (!tensRemovable)
return;
4098 exp += tensRemovable;
4103 if (tensRemovable & 1)
4105 tensRemovable >>= 1;
4106 if (!tensRemovable)
break;
4110 significand = significand.
udiv(divisor);
4118 int &exp,
unsigned FormatPrecision) {
4119 unsigned N = buffer.
size();
4120 if (
N <= FormatPrecision)
return;
4123 unsigned FirstSignificant =
N - FormatPrecision;
4130 if (buffer[FirstSignificant - 1] <
'5') {
4131 while (FirstSignificant <
N && buffer[FirstSignificant] ==
'0')
4134 exp += FirstSignificant;
4135 buffer.
erase(&buffer[0], &buffer[FirstSignificant]);
4141 for (
unsigned I = FirstSignificant;
I !=
N; ++
I) {
4142 if (buffer[
I] ==
'9') {
4151 if (FirstSignificant ==
N) {
4152 exp += FirstSignificant;
4158 exp += FirstSignificant;
4159 buffer.
erase(&buffer[0], &buffer[FirstSignificant]);
4163 APInt significand,
unsigned FormatPrecision,
4164 unsigned FormatMaxPadding,
bool TruncateZero) {
4165 const int semanticsPrecision = significand.
getBitWidth();
4172 if (!FormatPrecision) {
4180 FormatPrecision = 2 + semanticsPrecision * 59 / 196;
4185 exp += trailingZeros;
4191 }
else if (exp > 0) {
4193 significand = significand.
zext(semanticsPrecision + exp);
4194 significand <<= exp;
4208 unsigned precision = semanticsPrecision + (137 * texp + 136) / 59;
4212 significand = significand.
zext(precision);
4213 APInt five_to_the_i(precision, 5);
4216 significand *= five_to_the_i;
4221 five_to_the_i *= five_to_the_i;
4225 AdjustToPrecision(significand, exp, FormatPrecision);
4230 unsigned precision = significand.getBitWidth();
4231 if (precision < 4) {
4234 significand = significand.zext(precision);
4236 APInt ten(precision, 10);
4237 APInt digit(precision, 0);
4239 bool inTrail =
true;
4240 while (significand != 0) {
4245 unsigned d = digit.getZExtValue();
4256 assert(!buffer.
empty() &&
"no characters in buffer!");
4260 AdjustToPrecision(buffer, exp, FormatPrecision);
4262 unsigned NDigits = buffer.
size();
4265 bool FormatScientific;
4266 if (!FormatMaxPadding)
4267 FormatScientific =
true;
4273 FormatScientific = ((
unsigned) exp > FormatMaxPadding ||
4274 NDigits + (
unsigned) exp > FormatPrecision);
4277 int MSD = exp + (int) (NDigits - 1);
4280 FormatScientific =
false;
4284 FormatScientific = ((
unsigned) -MSD) > FormatMaxPadding;
4290 if (FormatScientific) {
4291 exp += (NDigits - 1);
4293 Str.push_back(buffer[NDigits-1]);
4295 if (NDigits == 1 && TruncateZero)
4298 for (
unsigned I = 1;
I != NDigits; ++
I)
4299 Str.push_back(buffer[NDigits-1-
I]);
4301 if (!TruncateZero && FormatPrecision > NDigits - 1)
4302 Str.append(FormatPrecision - NDigits + 1,
'0');
4304 Str.push_back(TruncateZero ?
'E' :
'e');
4306 Str.push_back(exp >= 0 ?
'+' :
'-');
4311 expbuf.
push_back((
char) (
'0' + (exp % 10)));
4315 if (!TruncateZero && expbuf.
size() < 2)
4317 for (
unsigned I = 0, E = expbuf.
size();
I != E; ++
I)
4318 Str.push_back(expbuf[E-1-
I]);
4324 for (
unsigned I = 0;
I != NDigits; ++
I)
4325 Str.push_back(buffer[NDigits-1-
I]);
4334 int NWholeDigits = exp + (int) NDigits;
4337 if (NWholeDigits > 0) {
4339 Str.push_back(buffer[NDigits-
I-1]);
4342 unsigned NZeros = 1 + (
unsigned) -NWholeDigits;
4346 for (
unsigned Z = 1;
Z != NZeros; ++
Z)
4350 for (;
I != NDigits; ++
I)
4351 Str.push_back(buffer[NDigits-
I-1]);
4357 unsigned FormatMaxPadding,
bool TruncateZero)
const {
4361 return append(Str,
"-Inf");
4363 return append(Str,
"+Inf");
4365 case fcNaN:
return append(Str,
"NaN");
4371 if (!FormatMaxPadding) {
4373 append(Str,
"0.0E+0");
4376 if (FormatPrecision > 1)
4377 Str.append(FormatPrecision - 1,
'0');
4378 append(Str,
"e+00");
4389 int exp = exponent - ((int) semantics->precision - 1);
4391 semantics->precision,
4394 toStringImpl(Str, isNegative(), exp, significand, FormatPrecision,
4395 FormatMaxPadding, TruncateZero);
4399bool IEEEFloat::getExactInverse(
APFloat *inv)
const {
4401 if (!isFiniteNonZero())
4406 if (significandLSB() != semantics->precision - 1)
4411 if (reciprocal.
divide(*
this, rmNearestTiesToEven) != opOK)
4420 reciprocal.significandLSB() == reciprocal.semantics->
precision - 1);
4423 *inv =
APFloat(reciprocal, *semantics);
4428int IEEEFloat::getExactLog2Abs()
const {
4436 for (
int i = 0; i < PartCount; ++i) {
4442 if (exponent != semantics->minExponent)
4445 int CountrParts = 0;
4446 for (
int i = 0; i < PartCount;
4448 if (Parts[i] != 0) {
4449 return exponent - semantics->precision + CountrParts +
4457bool IEEEFloat::isSignaling()
const {
4494 if (isSignaling()) {
4495 result = opInvalidOp;
4497 makeNaN(
false, isNegative(),
nullptr);
4502 makeSmallest(
false);
4506 if (isSmallest() && isNegative()) {
4515 if (isLargest() && !isNegative()) {
4520 }
else if (semantics->nonFiniteBehavior ==
4527 category = fcInfinity;
4528 exponent = semantics->maxExponent + 1;
4542 bool WillCrossBinadeBoundary =
4543 exponent != semantics->minExponent && isSignificandAllZeros();
4561 if (WillCrossBinadeBoundary) {
4577 bool WillCrossBinadeBoundary = !isDenormal() && isSignificandAllOnes();
4579 if (WillCrossBinadeBoundary) {
4583 assert(exponent != semantics->maxExponent &&
4584 "We can not increment an exponent beyond the maxExponent allowed"
4585 " by the given floating point semantics.");
4588 incrementSignificand();
4602 return ::exponentNaN(*semantics);
4606 return ::exponentInf(*semantics);
4610 return ::exponentZero(*semantics);
4613void IEEEFloat::makeInf(
bool Negative) {
4619 makeNaN(
false, Negative);
4622 category = fcInfinity;
4628void IEEEFloat::makeZero(
bool Negative) {
4639void IEEEFloat::makeQuiet() {
4647 return IEEEFloat::IEK_NaN;
4649 return IEEEFloat::IEK_Zero;
4651 return IEEEFloat::IEK_Inf;
4653 return Arg.exponent;
4658 Normalized.exponent += SignificandBits;
4659 Normalized.normalize(IEEEFloat::rmNearestTiesToEven,
lfExactlyZero);
4660 return Normalized.exponent - SignificandBits;
4664 auto MaxExp =
X.getSemantics().maxExponent;
4665 auto MinExp =
X.getSemantics().minExponent;
4673 int SignificandBits =
X.getSemantics().precision - 1;
4674 int MaxIncrement = MaxExp - (MinExp - SignificandBits) + 1;
4677 X.exponent += std::clamp(Exp, -MaxIncrement - 1, MaxIncrement);
4688 if (Exp == IEEEFloat::IEK_NaN) {
4694 if (Exp == IEEEFloat::IEK_Inf)
4699 Exp = Exp == IEEEFloat::IEK_Zero ? 0 : Exp + 1;
4700 return scalbn(Val, -Exp, RM);
4733 Floats(new
APFloat[2]{std::move(
First), std::move(Second)}) {
4755 Floats[0] =
RHS.Floats[0];
4756 Floats[1] =
RHS.Floats[1];
4757 }
else if (
this != &
RHS) {
4775 Floats[0] = std::move(z);
4776 Floats[1].makeZero(
false);
4780 auto AComparedToC = a.compareAbsoluteValue(c);
4793 Floats[0] = std::move(z);
4794 Floats[1].makeZero(
false);
4803 Status |= Floats[1].subtract(z, RM);
4804 Status |= Floats[1].add(c, RM);
4805 Status |= Floats[1].add(zz, RM);
4809 Status |= Floats[1].subtract(z, RM);
4810 Status |= Floats[1].add(a, RM);
4811 Status |= Floats[1].add(zz, RM);
4829 Floats[0] = std::move(z);
4830 Floats[1].makeZero(
false);
4834 Status |= Floats[0].add(zz, RM);
4836 Floats[1].makeZero(
false);
4839 Floats[1] = std::move(z);
4840 Status |= Floats[1].subtract(Floats[0], RM);
4841 Status |= Floats[1].add(zz, RM);
4847 const DoubleAPFloat &RHS,
4867 LHS.isNegative() !=
RHS.isNegative()) {
4868 Out.makeNaN(
false, Out.isNegative(),
nullptr);
4889 return Out.addImpl(
A, AA,
C,
CC, RM);
4894 return addWithSpecial(*
this,
RHS, *
this, RM);
4907 const auto &
LHS = *
this;
4934 Out.makeNaN(
false,
false,
nullptr);
4946 "Special cases not handled exhaustively");
4953 if (!
T.isFiniteNonZero()) {
4955 Floats[1].makeZero(
false);
4977 Status |= U.add(Tau, RM);
4980 if (!U.isFinite()) {
4981 Floats[1].makeZero(
false);
5040 Floats[0].changeSign();
5041 Floats[1].changeSign();
5046 auto Result = Floats[0].compareAbsoluteValue(
RHS.Floats[0]);
5049 Result = Floats[1].compareAbsoluteValue(
RHS.Floats[1]);
5051 auto Against = Floats[0].isNegative() ^ Floats[1].isNegative();
5052 auto RHSAgainst =
RHS.Floats[0].isNegative() ^
RHS.Floats[1].isNegative();
5053 if (Against && !RHSAgainst)
5055 if (!Against && RHSAgainst)
5057 if (!Against && !RHSAgainst)
5059 if (Against && RHSAgainst)
5066 return Floats[0].getCategory();
5072 Floats[0].makeInf(Neg);
5073 Floats[1].makeZero(
false);
5077 Floats[0].makeZero(Neg);
5078 Floats[1].makeZero(
false);
5091 Floats[0].makeSmallest(Neg);
5092 Floats[1].makeZero(
false);
5099 Floats[0].changeSign();
5100 Floats[1].makeZero(
false);
5104 Floats[0].makeNaN(SNaN, Neg, fill);
5105 Floats[1].makeZero(
false);
5109 auto Result = Floats[0].compare(
RHS.Floats[0]);
5112 return Floats[1].compare(
RHS.Floats[1]);
5117 return Floats[0].bitwiseIsEqual(
RHS.Floats[0]) &&
5118 Floats[1].bitwiseIsEqual(
RHS.Floats[1]);
5130 Floats[0].bitcastToAPInt().getRawData()[0],
5131 Floats[1].bitcastToAPInt().getRawData()[0],