llvm/llvm/lib/Support/APFloat.cpp

//===-- APFloat.cpp - Implement APFloat class -----------------------------===//
//
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
// See https://llvm.org/LICENSE.txt for license information.
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
//
//===----------------------------------------------------------------------===//
//
// This file implements a class to represent arbitrary precision floating
// point values and provide a variety of arithmetic operations on them.
//
//===----------------------------------------------------------------------===//

#include "llvm/ADT/APFloat.h"
#include "llvm/ADT/APSInt.h"
#include "llvm/ADT/ArrayRef.h"
#include "llvm/ADT/FloatingPointMode.h"
#include "llvm/ADT/FoldingSet.h"
#include "llvm/ADT/Hashing.h"
#include "llvm/ADT/STLExtras.h"
#include "llvm/ADT/StringExtras.h"
#include "llvm/ADT/StringRef.h"
#include "llvm/Config/llvm-config.h"
#include "llvm/Support/Debug.h"
#include "llvm/Support/Error.h"
#include "llvm/Support/MathExtras.h"
#include "llvm/Support/raw_ostream.h"
#include <cstring>
#include <limits.h>

#define APFLOAT_DISPATCH_ON_SEMANTICS

usingnamespacellvm;

/// A macro used to combine two fcCategory enums into one key which can be used
/// in a switch statement to classify how the interaction of two APFloat's
/// categories affects an operation.
///
/// TODO: If clang source code is ever allowed to use constexpr in its own
/// codebase, change this into a static inline function.
#define PackCategoriesIntoKey(_lhs, _rhs)

/* Assumed in hexadecimal significand parsing, and conversion to
   hexadecimal strings.  */
static_assert;

namespace llvm {

// How the nonfinite values Inf and NaN are represented.
enum class fltNonfiniteBehavior {};

// How NaN values are represented. This is curently only used in combination
// with fltNonfiniteBehavior::NanOnly, and using a variant other than IEEE
// while having IEEE non-finite behavior is liable to lead to unexpected
// results.
enum class fltNanEncoding {};

/* Represents floating point arithmetic semantics.  */
struct fltSemantics {};

static constexpr fltSemantics semIEEEhalf =;
static constexpr fltSemantics semBFloat =;
static constexpr fltSemantics semIEEEsingle =;
static constexpr fltSemantics semIEEEdouble =;
static constexpr fltSemantics semIEEEquad =;
static constexpr fltSemantics semFloat8E5M2 =;
static constexpr fltSemantics semFloat8E5M2FNUZ =;
static constexpr fltSemantics semFloat8E4M3 =;
static constexpr fltSemantics semFloat8E4M3FN =;
static constexpr fltSemantics semFloat8E4M3FNUZ =;
static constexpr fltSemantics semFloat8E4M3B11FNUZ =;
static constexpr fltSemantics semFloat8E3M4 =;
static constexpr fltSemantics semFloatTF32 =;
static constexpr fltSemantics semFloat8E8M0FNU =;

static constexpr fltSemantics semFloat6E3M2FN =;
static constexpr fltSemantics semFloat6E2M3FN =;
static constexpr fltSemantics semFloat4E2M1FN =;
static constexpr fltSemantics semX87DoubleExtended =;
static constexpr fltSemantics semBogus =;

/* The IBM double-double semantics. Such a number consists of a pair of IEEE
   64-bit doubles (Hi, Lo), where |Hi| > |Lo|, and if normal,
   (double)(Hi + Lo) == Hi. The numeric value it's modeling is Hi + Lo.
   Therefore it has two 53-bit mantissa parts that aren't necessarily adjacent
   to each other, and two 11-bit exponents.

   Note: we need to make the value different from semBogus as otherwise
   an unsafe optimization may collapse both values to a single address,
   and we heavily rely on them having distinct addresses.             */
static constexpr fltSemantics semPPCDoubleDouble =;

/* These are legacy semantics for the fallback, inaccrurate implementation of
   IBM double-double, if the accurate semPPCDoubleDouble doesn't handle the
   operation. It's equivalent to having an IEEE number with consecutive 106
   bits of mantissa and 11 bits of exponent.

   It's not equivalent to IBM double-double. For example, a legit IBM
   double-double, 1 + epsilon:

     1 + epsilon = 1 + (1 >> 1076)

   is not representable by a consecutive 106 bits of mantissa.

   Currently, these semantics are used in the following way:

     semPPCDoubleDouble -> (IEEEdouble, IEEEdouble) ->
     (64-bit APInt, 64-bit APInt) -> (128-bit APInt) ->
     semPPCDoubleDoubleLegacy -> IEEE operations

   We use bitcastToAPInt() to get the bit representation (in APInt) of the
   underlying IEEEdouble, then use the APInt constructor to construct the
   legacy IEEE float.

   TODO: Implement all operations in semPPCDoubleDouble, and delete these
   semantics.  */
static constexpr fltSemantics semPPCDoubleDoubleLegacy =;

const llvm::fltSemantics &APFloatBase::EnumToSemantics(Semantics S) {}

APFloatBase::Semantics
APFloatBase::SemanticsToEnum(const llvm::fltSemantics &Sem) {}

const fltSemantics &APFloatBase::IEEEhalf() {}
const fltSemantics &APFloatBase::BFloat() {}
const fltSemantics &APFloatBase::IEEEsingle() {}
const fltSemantics &APFloatBase::IEEEdouble() {}
const fltSemantics &APFloatBase::IEEEquad() {}
const fltSemantics &APFloatBase::PPCDoubleDouble() {}
const fltSemantics &APFloatBase::Float8E5M2() {}
const fltSemantics &APFloatBase::Float8E5M2FNUZ() {}
const fltSemantics &APFloatBase::Float8E4M3() {}
const fltSemantics &APFloatBase::Float8E4M3FN() {}
const fltSemantics &APFloatBase::Float8E4M3FNUZ() {}
const fltSemantics &APFloatBase::Float8E4M3B11FNUZ() {}
const fltSemantics &APFloatBase::Float8E3M4() {}
const fltSemantics &APFloatBase::FloatTF32() {}
const fltSemantics &APFloatBase::Float8E8M0FNU() {}
const fltSemantics &APFloatBase::Float6E3M2FN() {}
const fltSemantics &APFloatBase::Float6E2M3FN() {}
const fltSemantics &APFloatBase::Float4E2M1FN() {}
const fltSemantics &APFloatBase::x87DoubleExtended() {}
const fltSemantics &APFloatBase::Bogus() {}

constexpr RoundingMode APFloatBase::rmNearestTiesToEven;
constexpr RoundingMode APFloatBase::rmTowardPositive;
constexpr RoundingMode APFloatBase::rmTowardNegative;
constexpr RoundingMode APFloatBase::rmTowardZero;
constexpr RoundingMode APFloatBase::rmNearestTiesToAway;

/* A tight upper bound on number of parts required to hold the value
   pow(5, power) is

     power * 815 / (351 * integerPartWidth) + 1

   However, whilst the result may require only this many parts,
   because we are multiplying two values to get it, the
   multiplication may require an extra part with the excess part
   being zero (consider the trivial case of 1 * 1, tcFullMultiply
   requires two parts to hold the single-part result).  So we add an
   extra one to guarantee enough space whilst multiplying.  */
const unsigned int maxExponent =;
const unsigned int maxPrecision =;
const unsigned int maxPowerOfFiveExponent =;
const unsigned int maxPowerOfFiveParts =;

unsigned int APFloatBase::semanticsPrecision(const fltSemantics &semantics) {}
APFloatBase::ExponentType
APFloatBase::semanticsMaxExponent(const fltSemantics &semantics) {}
APFloatBase::ExponentType
APFloatBase::semanticsMinExponent(const fltSemantics &semantics) {}
unsigned int APFloatBase::semanticsSizeInBits(const fltSemantics &semantics) {}
unsigned int APFloatBase::semanticsIntSizeInBits(const fltSemantics &semantics,
                                                 bool isSigned) {}

bool APFloatBase::semanticsHasZero(const fltSemantics &semantics) {}

bool APFloatBase::semanticsHasSignedRepr(const fltSemantics &semantics) {}

bool APFloatBase::isRepresentableAsNormalIn(const fltSemantics &Src,
                                            const fltSemantics &Dst) {}

unsigned APFloatBase::getSizeInBits(const fltSemantics &Sem) {}

static constexpr APFloatBase::ExponentType
exponentZero(const fltSemantics &semantics) {}

static constexpr APFloatBase::ExponentType
exponentInf(const fltSemantics &semantics) {}

static constexpr APFloatBase::ExponentType
exponentNaN(const fltSemantics &semantics) {}

/* A bunch of private, handy routines.  */

static inline Error createError(const Twine &Err) {}

static constexpr inline unsigned int partCountForBits(unsigned int bits) {}

/* Returns 0U-9U.  Return values >= 10U are not digits.  */
static inline unsigned int
decDigitValue(unsigned int c)
{}

/* Return the value of a decimal exponent of the form
   [+-]ddddddd.

   If the exponent overflows, returns a large exponent with the
   appropriate sign.  */
static Expected<int> readExponent(StringRef::iterator begin,
                                  StringRef::iterator end) {}

/* This is ugly and needs cleaning up, but I don't immediately see
   how whilst remaining safe.  */
static Expected<int> totalExponent(StringRef::iterator p,
                                   StringRef::iterator end,
                                   int exponentAdjustment) {}

static Expected<StringRef::iterator>
skipLeadingZeroesAndAnyDot(StringRef::iterator begin, StringRef::iterator end,
                           StringRef::iterator *dot) {}

/* Given a normal decimal floating point number of the form

     dddd.dddd[eE][+-]ddd

   where the decimal point and exponent are optional, fill out the
   structure D.  Exponent is appropriate if the significand is
   treated as an integer, and normalizedExponent if the significand
   is taken to have the decimal point after a single leading
   non-zero digit.

   If the value is zero, V->firstSigDigit points to a non-digit, and
   the return exponent is zero.
*/
struct decimalInfo {};

static Error interpretDecimal(StringRef::iterator begin,
                              StringRef::iterator end, decimalInfo *D) {}

/* Return the trailing fraction of a hexadecimal number.
   DIGITVALUE is the first hex digit of the fraction, P points to
   the next digit.  */
static Expected<lostFraction>
trailingHexadecimalFraction(StringRef::iterator p, StringRef::iterator end,
                            unsigned int digitValue) {}

/* Return the fraction lost were a bignum truncated losing the least
   significant BITS bits.  */
static lostFraction
lostFractionThroughTruncation(const APFloatBase::integerPart *parts,
                              unsigned int partCount,
                              unsigned int bits)
{}

/* Shift DST right BITS bits noting lost fraction.  */
static lostFraction
shiftRight(APFloatBase::integerPart *dst, unsigned int parts, unsigned int bits)
{}

/* Combine the effect of two lost fractions.  */
static lostFraction
combineLostFractions(lostFraction moreSignificant,
                     lostFraction lessSignificant)
{}

/* The error from the true value, in half-ulps, on multiplying two
   floating point numbers, which differ from the value they
   approximate by at most HUE1 and HUE2 half-ulps, is strictly less
   than the returned value.

   See "How to Read Floating Point Numbers Accurately" by William D
   Clinger.  */
static unsigned int
HUerrBound(bool inexactMultiply, unsigned int HUerr1, unsigned int HUerr2)
{}

/* The number of ulps from the boundary (zero, or half if ISNEAREST)
   when the least significant BITS are truncated.  BITS cannot be
   zero.  */
static APFloatBase::integerPart
ulpsFromBoundary(const APFloatBase::integerPart *parts, unsigned int bits,
                 bool isNearest) {}

/* Place pow(5, power) in DST, and return the number of parts used.
   DST must be at least one part larger than size of the answer.  */
static unsigned int
powerOf5(APFloatBase::integerPart *dst, unsigned int power) {}

/* Zero at the end to avoid modular arithmetic when adding one; used
   when rounding up during hexadecimal output.  */
static const char hexDigitsLower[] =;
static const char hexDigitsUpper[] =;
static const char infinityL[] =;
static const char infinityU[] =;
static const char NaNL[] =;
static const char NaNU[] =;

/* Write out an integerPart in hexadecimal, starting with the most
   significant nibble.  Write out exactly COUNT hexdigits, return
   COUNT.  */
static unsigned int
partAsHex (char *dst, APFloatBase::integerPart part, unsigned int count,
           const char *hexDigitChars)
{}

/* Write out an unsigned decimal integer.  */
static char *
writeUnsignedDecimal (char *dst, unsigned int n)
{}

/* Write out a signed decimal integer.  */
static char *
writeSignedDecimal (char *dst, int value)
{}

namespace detail {
/* Constructors.  */
void IEEEFloat::initialize(const fltSemantics *ourSemantics) {}

void IEEEFloat::freeSignificand() {}

void IEEEFloat::assign(const IEEEFloat &rhs) {}

void IEEEFloat::copySignificand(const IEEEFloat &rhs) {}

/* Make this number a NaN, with an arbitrary but deterministic value
   for the significand.  If double or longer, this is a signalling NaN,
   which may not be ideal.  If float, this is QNaN(0).  */
void IEEEFloat::makeNaN(bool SNaN, bool Negative, const APInt *fill) {}

IEEEFloat &IEEEFloat::operator=(const IEEEFloat &rhs) {}

IEEEFloat &IEEEFloat::operator=(IEEEFloat &&rhs) {}

bool IEEEFloat::isDenormal() const {}

bool IEEEFloat::isSmallest() const {}

bool IEEEFloat::isSmallestNormalized() const {}

unsigned int IEEEFloat::getNumHighBits() const {}

bool IEEEFloat::isSignificandAllOnes() const {}

bool IEEEFloat::isSignificandAllOnesExceptLSB() const {}

bool IEEEFloat::isSignificandAllZeros() const {}

bool IEEEFloat::isSignificandAllZerosExceptMSB() const {}

bool IEEEFloat::isLargest() const {}

bool IEEEFloat::isInteger() const {}

bool IEEEFloat::bitwiseIsEqual(const IEEEFloat &rhs) const {}

IEEEFloat::IEEEFloat(const fltSemantics &ourSemantics, integerPart value) {}

IEEEFloat::IEEEFloat(const fltSemantics &ourSemantics) {}

// Delegate to the previous constructor, because later copy constructor may
// actually inspects category, which can't be garbage.
IEEEFloat::IEEEFloat(const fltSemantics &ourSemantics, uninitializedTag tag)
    :{}

IEEEFloat::IEEEFloat(const IEEEFloat &rhs) {}

IEEEFloat::IEEEFloat(IEEEFloat &&rhs) :{}

IEEEFloat::~IEEEFloat() {}

unsigned int IEEEFloat::partCount() const {}

const APFloat::integerPart *IEEEFloat::significandParts() const {}

APFloat::integerPart *IEEEFloat::significandParts() {}

void IEEEFloat::zeroSignificand() {}

/* Increment an fcNormal floating point number's significand.  */
void IEEEFloat::incrementSignificand() {}

/* Add the significand of the RHS.  Returns the carry flag.  */
APFloat::integerPart IEEEFloat::addSignificand(const IEEEFloat &rhs) {}

/* Subtract the significand of the RHS with a borrow flag.  Returns
   the borrow flag.  */
APFloat::integerPart IEEEFloat::subtractSignificand(const IEEEFloat &rhs,
                                                    integerPart borrow) {}

/* Multiply the significand of the RHS.  If ADDEND is non-NULL, add it
   on to the full-precision result of the multiplication.  Returns the
   lost fraction.  */
lostFraction IEEEFloat::multiplySignificand(const IEEEFloat &rhs,
                                            IEEEFloat addend,
                                            bool ignoreAddend) {}

lostFraction IEEEFloat::multiplySignificand(const IEEEFloat &rhs) {}

/* Multiply the significands of LHS and RHS to DST.  */
lostFraction IEEEFloat::divideSignificand(const IEEEFloat &rhs) {}

unsigned int IEEEFloat::significandMSB() const {}

unsigned int IEEEFloat::significandLSB() const {}

/* Note that a zero result is NOT normalized to fcZero.  */
lostFraction IEEEFloat::shiftSignificandRight(unsigned int bits) {}

/* Shift the significand left BITS bits, subtract BITS from its exponent.  */
void IEEEFloat::shiftSignificandLeft(unsigned int bits) {}

APFloat::cmpResult IEEEFloat::compareAbsoluteValue(const IEEEFloat &rhs) const {}

/* Set the least significant BITS bits of a bignum, clear the
   rest.  */
static void tcSetLeastSignificantBits(APInt::WordType *dst, unsigned parts,
                                      unsigned bits) {}

/* Handle overflow.  Sign is preserved.  We either become infinity or
   the largest finite number.  */
APFloat::opStatus IEEEFloat::handleOverflow(roundingMode rounding_mode) {}

/* Returns TRUE if, when truncating the current number, with BIT the
   new LSB, with the given lost fraction and rounding mode, the result
   would need to be rounded away from zero (i.e., by increasing the
   signficand).  This routine must work for fcZero of both signs, and
   fcNormal numbers.  */
bool IEEEFloat::roundAwayFromZero(roundingMode rounding_mode,
                                  lostFraction lost_fraction,
                                  unsigned int bit) const {}

APFloat::opStatus IEEEFloat::normalize(roundingMode rounding_mode,
                                       lostFraction lost_fraction) {}

APFloat::opStatus IEEEFloat::addOrSubtractSpecials(const IEEEFloat &rhs,
                                                   bool subtract) {}

/* Add or subtract two normal numbers.  */
lostFraction IEEEFloat::addOrSubtractSignificand(const IEEEFloat &rhs,
                                                 bool subtract) {}

APFloat::opStatus IEEEFloat::multiplySpecials(const IEEEFloat &rhs) {}

APFloat::opStatus IEEEFloat::divideSpecials(const IEEEFloat &rhs) {}

APFloat::opStatus IEEEFloat::modSpecials(const IEEEFloat &rhs) {}

APFloat::opStatus IEEEFloat::remainderSpecials(const IEEEFloat &rhs) {}

/* Change sign.  */
void IEEEFloat::changeSign() {}

/* Normalized addition or subtraction.  */
APFloat::opStatus IEEEFloat::addOrSubtract(const IEEEFloat &rhs,
                                           roundingMode rounding_mode,
                                           bool subtract) {}

/* Normalized addition.  */
APFloat::opStatus IEEEFloat::add(const IEEEFloat &rhs,
                                 roundingMode rounding_mode) {}

/* Normalized subtraction.  */
APFloat::opStatus IEEEFloat::subtract(const IEEEFloat &rhs,
                                      roundingMode rounding_mode) {}

/* Normalized multiply.  */
APFloat::opStatus IEEEFloat::multiply(const IEEEFloat &rhs,
                                      roundingMode rounding_mode) {}

/* Normalized divide.  */
APFloat::opStatus IEEEFloat::divide(const IEEEFloat &rhs,
                                    roundingMode rounding_mode) {}

/* Normalized remainder.  */
APFloat::opStatus IEEEFloat::remainder(const IEEEFloat &rhs) {}

/* Normalized llvm frem (C fmod). */
APFloat::opStatus IEEEFloat::mod(const IEEEFloat &rhs) {}

/* Normalized fused-multiply-add.  */
APFloat::opStatus IEEEFloat::fusedMultiplyAdd(const IEEEFloat &multiplicand,
                                              const IEEEFloat &addend,
                                              roundingMode rounding_mode) {}

/* Rounding-mode correct round to integral value.  */
APFloat::opStatus IEEEFloat::roundToIntegral(roundingMode rounding_mode) {}

/* Comparison requires normalized numbers.  */
APFloat::cmpResult IEEEFloat::compare(const IEEEFloat &rhs) const {}

/// IEEEFloat::convert - convert a value of one floating point type to another.
/// The return value corresponds to the IEEE754 exceptions.  *losesInfo
/// records whether the transformation lost information, i.e. whether
/// converting the result back to the original type will produce the
/// original value (this is almost the same as return value==fsOK, but there
/// are edge cases where this is not so).

APFloat::opStatus IEEEFloat::convert(const fltSemantics &toSemantics,
                                     roundingMode rounding_mode,
                                     bool *losesInfo) {}

/* Convert a floating point number to an integer according to the
   rounding mode.  If the rounded integer value is out of range this
   returns an invalid operation exception and the contents of the
   destination parts are unspecified.  If the rounded value is in
   range but the floating point number is not the exact integer, the C
   standard doesn't require an inexact exception to be raised.  IEEE
   854 does require it so we do that.

   Note that for conversions to integer type the C standard requires
   round-to-zero to always be used.  */
APFloat::opStatus IEEEFloat::convertToSignExtendedInteger(
    MutableArrayRef<integerPart> parts, unsigned int width, bool isSigned,
    roundingMode rounding_mode, bool *isExact) const {}

/* Same as convertToSignExtendedInteger, except we provide
   deterministic values in case of an invalid operation exception,
   namely zero for NaNs and the minimal or maximal value respectively
   for underflow or overflow.
   The *isExact output tells whether the result is exact, in the sense
   that converting it back to the original floating point type produces
   the original value.  This is almost equivalent to result==opOK,
   except for negative zeroes.
*/
APFloat::opStatus
IEEEFloat::convertToInteger(MutableArrayRef<integerPart> parts,
                            unsigned int width, bool isSigned,
                            roundingMode rounding_mode, bool *isExact) const {}

/* Convert an unsigned integer SRC to a floating point number,
   rounding according to ROUNDING_MODE.  The sign of the floating
   point number is not modified.  */
APFloat::opStatus IEEEFloat::convertFromUnsignedParts(
    const integerPart *src, unsigned int srcCount, roundingMode rounding_mode) {}

APFloat::opStatus IEEEFloat::convertFromAPInt(const APInt &Val, bool isSigned,
                                              roundingMode rounding_mode) {}

/* Convert a two's complement integer SRC to a floating point number,
   rounding according to ROUNDING_MODE.  ISSIGNED is true if the
   integer is signed, in which case it must be sign-extended.  */
APFloat::opStatus
IEEEFloat::convertFromSignExtendedInteger(const integerPart *src,
                                          unsigned int srcCount, bool isSigned,
                                          roundingMode rounding_mode) {}

/* FIXME: should this just take a const APInt reference?  */
APFloat::opStatus
IEEEFloat::convertFromZeroExtendedInteger(const integerPart *parts,
                                          unsigned int width, bool isSigned,
                                          roundingMode rounding_mode) {}

Expected<APFloat::opStatus>
IEEEFloat::convertFromHexadecimalString(StringRef s,
                                        roundingMode rounding_mode) {}

APFloat::opStatus
IEEEFloat::roundSignificandWithExponent(const integerPart *decSigParts,
                                        unsigned sigPartCount, int exp,
                                        roundingMode rounding_mode) {}

Expected<APFloat::opStatus>
IEEEFloat::convertFromDecimalString(StringRef str, roundingMode rounding_mode) {}

bool IEEEFloat::convertFromStringSpecials(StringRef str) {}

Expected<APFloat::opStatus>
IEEEFloat::convertFromString(StringRef str, roundingMode rounding_mode) {}

/* Write out a hexadecimal representation of the floating point value
   to DST, which must be of sufficient size, in the C99 form
   [-]0xh.hhhhp[+-]d.  Return the number of characters written,
   excluding the terminating NUL.

   If UPPERCASE, the output is in upper case, otherwise in lower case.

   HEXDIGITS digits appear altogether, rounding the value if
   necessary.  If HEXDIGITS is 0, the minimal precision to display the
   number precisely is used instead.  If nothing would appear after
   the decimal point it is suppressed.

   The decimal exponent is always printed and has at least one digit.
   Zero values display an exponent of zero.  Infinities and NaNs
   appear as "infinity" or "nan" respectively.

   The above rules are as specified by C99.  There is ambiguity about
   what the leading hexadecimal digit should be.  This implementation
   uses whatever is necessary so that the exponent is displayed as
   stored.  This implies the exponent will fall within the IEEE format
   range, and the leading hexadecimal digit will be 0 (for denormals),
   1 (normal numbers) or 2 (normal numbers rounded-away-from-zero with
   any other digits zero).
*/
unsigned int IEEEFloat::convertToHexString(char *dst, unsigned int hexDigits,
                                           bool upperCase,
                                           roundingMode rounding_mode) const {}

/* Does the hard work of outputting the correctly rounded hexadecimal
   form of a normal floating point number with the specified number of
   hexadecimal digits.  If HEXDIGITS is zero the minimum number of
   digits necessary to print the value precisely is output.  */
char *IEEEFloat::convertNormalToHexString(char *dst, unsigned int hexDigits,
                                          bool upperCase,
                                          roundingMode rounding_mode) const {}

hash_code hash_value(const IEEEFloat &Arg) {}

// Conversion from APFloat to/from host float/double.  It may eventually be
// possible to eliminate these and have everybody deal with APFloats, but that
// will take a while.  This approach will not easily extend to long double.
// Current implementation requires integerPartWidth==64, which is correct at
// the moment but could be made more general.

// Denormals have exponent minExponent in APFloat, but minExponent-1 in
// the actual IEEE respresentations.  We compensate for that here.

APInt IEEEFloat::convertF80LongDoubleAPFloatToAPInt() const {}

APInt IEEEFloat::convertPPCDoubleDoubleAPFloatToAPInt() const {}

template <const fltSemantics &S>
APInt IEEEFloat::convertIEEEFloatToAPInt() const {}

APInt IEEEFloat::convertQuadrupleAPFloatToAPInt() const {}

APInt IEEEFloat::convertDoubleAPFloatToAPInt() const {}

APInt IEEEFloat::convertFloatAPFloatToAPInt() const {}

APInt IEEEFloat::convertBFloatAPFloatToAPInt() const {}

APInt IEEEFloat::convertHalfAPFloatToAPInt() const {}

APInt IEEEFloat::convertFloat8E5M2APFloatToAPInt() const {}

APInt IEEEFloat::convertFloat8E5M2FNUZAPFloatToAPInt() const {}

APInt IEEEFloat::convertFloat8E4M3APFloatToAPInt() const {}

APInt IEEEFloat::convertFloat8E4M3FNAPFloatToAPInt() const {}

APInt IEEEFloat::convertFloat8E4M3FNUZAPFloatToAPInt() const {}

APInt IEEEFloat::convertFloat8E4M3B11FNUZAPFloatToAPInt() const {}

APInt IEEEFloat::convertFloat8E3M4APFloatToAPInt() const {}

APInt IEEEFloat::convertFloatTF32APFloatToAPInt() const {}

APInt IEEEFloat::convertFloat8E8M0FNUAPFloatToAPInt() const {}

APInt IEEEFloat::convertFloat6E3M2FNAPFloatToAPInt() const {}

APInt IEEEFloat::convertFloat6E2M3FNAPFloatToAPInt() const {}

APInt IEEEFloat::convertFloat4E2M1FNAPFloatToAPInt() const {}

// This function creates an APInt that is just a bit map of the floating
// point constant as it would appear in memory.  It is not a conversion,
// and treating the result as a normal integer is unlikely to be useful.

APInt IEEEFloat::bitcastToAPInt() const {}

float IEEEFloat::convertToFloat() const {}

double IEEEFloat::convertToDouble() const {}

#ifdef HAS_IEE754_FLOAT128
float128 IEEEFloat::convertToQuad() const {}
#endif

/// Integer bit is explicit in this format.  Intel hardware (387 and later)
/// does not support these bit patterns:
///  exponent = all 1's, integer bit 0, significand 0 ("pseudoinfinity")
///  exponent = all 1's, integer bit 0, significand nonzero ("pseudoNaN")
///  exponent!=0 nor all 1's, integer bit 0 ("unnormal")
///  exponent = 0, integer bit 1 ("pseudodenormal")
/// At the moment, the first three are treated as NaNs, the last one as Normal.
void IEEEFloat::initFromF80LongDoubleAPInt(const APInt &api) {}

void IEEEFloat::initFromPPCDoubleDoubleAPInt(const APInt &api) {}

// The E8M0 format has the following characteristics:
// It is an 8-bit unsigned format with only exponents (no actual significand).
// No encodings for {zero, infinities or denorms}.
// NaN is represented by all 1's.
// Bias is 127.
void IEEEFloat::initFromFloat8E8M0FNUAPInt(const APInt &api) {}
template <const fltSemantics &S>
void IEEEFloat::initFromIEEEAPInt(const APInt &api) {}

void IEEEFloat::initFromQuadrupleAPInt(const APInt &api) {}

void IEEEFloat::initFromDoubleAPInt(const APInt &api) {}

void IEEEFloat::initFromFloatAPInt(const APInt &api) {}

void IEEEFloat::initFromBFloatAPInt(const APInt &api) {}

void IEEEFloat::initFromHalfAPInt(const APInt &api) {}

void IEEEFloat::initFromFloat8E5M2APInt(const APInt &api) {}

void IEEEFloat::initFromFloat8E5M2FNUZAPInt(const APInt &api) {}

void IEEEFloat::initFromFloat8E4M3APInt(const APInt &api) {}

void IEEEFloat::initFromFloat8E4M3FNAPInt(const APInt &api) {}

void IEEEFloat::initFromFloat8E4M3FNUZAPInt(const APInt &api) {}

void IEEEFloat::initFromFloat8E4M3B11FNUZAPInt(const APInt &api) {}

void IEEEFloat::initFromFloat8E3M4APInt(const APInt &api) {}

void IEEEFloat::initFromFloatTF32APInt(const APInt &api) {}

void IEEEFloat::initFromFloat6E3M2FNAPInt(const APInt &api) {}

void IEEEFloat::initFromFloat6E2M3FNAPInt(const APInt &api) {}

void IEEEFloat::initFromFloat4E2M1FNAPInt(const APInt &api) {}

/// Treat api as containing the bits of a floating point number.
void IEEEFloat::initFromAPInt(const fltSemantics *Sem, const APInt &api) {}

/// Make this number the largest magnitude normal number in the given
/// semantics.
void IEEEFloat::makeLargest(bool Negative) {}

/// Make this number the smallest magnitude denormal number in the given
/// semantics.
void IEEEFloat::makeSmallest(bool Negative) {}

void IEEEFloat::makeSmallestNormalized(bool Negative) {}

IEEEFloat::IEEEFloat(const fltSemantics &Sem, const APInt &API) {}

IEEEFloat::IEEEFloat(float f) {}

IEEEFloat::IEEEFloat(double d) {}

namespace {
  void append(SmallVectorImpl<char> &Buffer, StringRef Str) {}

  /// Removes data from the given significand until it is no more
  /// precise than is required for the desired precision.
  void AdjustToPrecision(APInt &significand,
                         int &exp, unsigned FormatPrecision) {}


  void AdjustToPrecision(SmallVectorImpl<char> &buffer,
                         int &exp, unsigned FormatPrecision) {}

  void toStringImpl(SmallVectorImpl<char> &Str, const bool isNeg, int exp,
                    APInt significand, unsigned FormatPrecision,
                    unsigned FormatMaxPadding, bool TruncateZero) {}
} // namespace

void IEEEFloat::toString(SmallVectorImpl<char> &Str, unsigned FormatPrecision,
                         unsigned FormatMaxPadding, bool TruncateZero) const {}

bool IEEEFloat::getExactInverse(APFloat *inv) const {}

int IEEEFloat::getExactLog2Abs() const {}

bool IEEEFloat::isSignaling() const {}

/// IEEE-754R 2008 5.3.1: nextUp/nextDown.
///
/// *NOTE* since nextDown(x) = -nextUp(-x), we only implement nextUp with
/// appropriate sign switching before/after the computation.
APFloat::opStatus IEEEFloat::next(bool nextDown) {}

APFloatBase::ExponentType IEEEFloat::exponentNaN() const {}

APFloatBase::ExponentType IEEEFloat::exponentInf() const {}

APFloatBase::ExponentType IEEEFloat::exponentZero() const {}

void IEEEFloat::makeInf(bool Negative) {}

void IEEEFloat::makeZero(bool Negative) {}

void IEEEFloat::makeQuiet() {}

int ilogb(const IEEEFloat &Arg) {}

IEEEFloat scalbn(IEEEFloat X, int Exp, roundingMode RoundingMode) {}

IEEEFloat frexp(const IEEEFloat &Val, int &Exp, roundingMode RM) {}

DoubleAPFloat::DoubleAPFloat(const fltSemantics &S)
    :{}

DoubleAPFloat::DoubleAPFloat(const fltSemantics &S, uninitializedTag)
    :{}

DoubleAPFloat::DoubleAPFloat(const fltSemantics &S, integerPart I)
    :{}

DoubleAPFloat::DoubleAPFloat(const fltSemantics &S, const APInt &I)
    :{}

DoubleAPFloat::DoubleAPFloat(const fltSemantics &S, APFloat &&First,
                             APFloat &&Second)
    :{}

DoubleAPFloat::DoubleAPFloat(const DoubleAPFloat &RHS)
    :{}

DoubleAPFloat::DoubleAPFloat(DoubleAPFloat &&RHS)
    :{}

DoubleAPFloat &DoubleAPFloat::operator=(const DoubleAPFloat &RHS) {}

// Implement addition, subtraction, multiplication and division based on:
// "Software for Doubled-Precision Floating-Point Computations",
// by Seppo Linnainmaa, ACM TOMS vol 7 no 3, September 1981, pages 272-283.
APFloat::opStatus DoubleAPFloat::addImpl(const APFloat &a, const APFloat &aa,
                                         const APFloat &c, const APFloat &cc,
                                         roundingMode RM) {}

APFloat::opStatus DoubleAPFloat::addWithSpecial(const DoubleAPFloat &LHS,
                                                const DoubleAPFloat &RHS,
                                                DoubleAPFloat &Out,
                                                roundingMode RM) {}

APFloat::opStatus DoubleAPFloat::add(const DoubleAPFloat &RHS,
                                     roundingMode RM) {}

APFloat::opStatus DoubleAPFloat::subtract(const DoubleAPFloat &RHS,
                                          roundingMode RM) {}

APFloat::opStatus DoubleAPFloat::multiply(const DoubleAPFloat &RHS,
                                          APFloat::roundingMode RM) {}

APFloat::opStatus DoubleAPFloat::divide(const DoubleAPFloat &RHS,
                                        APFloat::roundingMode RM) {}

APFloat::opStatus DoubleAPFloat::remainder(const DoubleAPFloat &RHS) {}

APFloat::opStatus DoubleAPFloat::mod(const DoubleAPFloat &RHS) {}

APFloat::opStatus
DoubleAPFloat::fusedMultiplyAdd(const DoubleAPFloat &Multiplicand,
                                const DoubleAPFloat &Addend,
                                APFloat::roundingMode RM) {}

APFloat::opStatus DoubleAPFloat::roundToIntegral(APFloat::roundingMode RM) {}

void DoubleAPFloat::changeSign() {}

APFloat::cmpResult
DoubleAPFloat::compareAbsoluteValue(const DoubleAPFloat &RHS) const {}

APFloat::fltCategory DoubleAPFloat::getCategory() const {}

bool DoubleAPFloat::isNegative() const {}

void DoubleAPFloat::makeInf(bool Neg) {}

void DoubleAPFloat::makeZero(bool Neg) {}

void DoubleAPFloat::makeLargest(bool Neg) {}

void DoubleAPFloat::makeSmallest(bool Neg) {}

void DoubleAPFloat::makeSmallestNormalized(bool Neg) {}

void DoubleAPFloat::makeNaN(bool SNaN, bool Neg, const APInt *fill) {}

APFloat::cmpResult DoubleAPFloat::compare(const DoubleAPFloat &RHS) const {}

bool DoubleAPFloat::bitwiseIsEqual(const DoubleAPFloat &RHS) const {}

hash_code hash_value(const DoubleAPFloat &Arg) {}

APInt DoubleAPFloat::bitcastToAPInt() const {}

Expected<APFloat::opStatus> DoubleAPFloat::convertFromString(StringRef S,
                                                             roundingMode RM) {}

APFloat::opStatus DoubleAPFloat::next(bool nextDown) {}

APFloat::opStatus
DoubleAPFloat::convertToInteger(MutableArrayRef<integerPart> Input,
                                unsigned int Width, bool IsSigned,
                                roundingMode RM, bool *IsExact) const {}

APFloat::opStatus DoubleAPFloat::convertFromAPInt(const APInt &Input,
                                                  bool IsSigned,
                                                  roundingMode RM) {}

APFloat::opStatus
DoubleAPFloat::convertFromSignExtendedInteger(const integerPart *Input,
                                              unsigned int InputSize,
                                              bool IsSigned, roundingMode RM) {}

APFloat::opStatus
DoubleAPFloat::convertFromZeroExtendedInteger(const integerPart *Input,
                                              unsigned int InputSize,
                                              bool IsSigned, roundingMode RM) {}

unsigned int DoubleAPFloat::convertToHexString(char *DST,
                                               unsigned int HexDigits,
                                               bool UpperCase,
                                               roundingMode RM) const {}

bool DoubleAPFloat::isDenormal() const {}

bool DoubleAPFloat::isSmallest() const {}

bool DoubleAPFloat::isSmallestNormalized() const {}

bool DoubleAPFloat::isLargest() const {}

bool DoubleAPFloat::isInteger() const {}

void DoubleAPFloat::toString(SmallVectorImpl<char> &Str,
                             unsigned FormatPrecision,
                             unsigned FormatMaxPadding,
                             bool TruncateZero) const {}

bool DoubleAPFloat::getExactInverse(APFloat *inv) const {}

int DoubleAPFloat::getExactLog2() const {}

int DoubleAPFloat::getExactLog2Abs() const {}

DoubleAPFloat scalbn(const DoubleAPFloat &Arg, int Exp,
                     APFloat::roundingMode RM) {}

DoubleAPFloat frexp(const DoubleAPFloat &Arg, int &Exp,
                    APFloat::roundingMode RM) {}

} // namespace detail

APFloat::Storage::Storage(IEEEFloat F, const fltSemantics &Semantics) {}

Expected<APFloat::opStatus> APFloat::convertFromString(StringRef Str,
                                                       roundingMode RM) {}

hash_code hash_value(const APFloat &Arg) {}

APFloat::APFloat(const fltSemantics &Semantics, StringRef S)
    :{}

FPClassTest APFloat::classify() const {}

APFloat::opStatus APFloat::convert(const fltSemantics &ToSemantics,
                                   roundingMode RM, bool *losesInfo) {}

APFloat APFloat::getAllOnesValue(const fltSemantics &Semantics) {}

void APFloat::print(raw_ostream &OS) const {}

#if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
LLVM_DUMP_METHOD void APFloat::dump() const {
  print(dbgs());
  dbgs() << '\n';
}
#endif

void APFloat::Profile(FoldingSetNodeID &NID) const {}

/* Same as convertToInteger(integerPart*, ...), except the result is returned in
   an APSInt, whose initial bit-width and signed-ness are used to determine the
   precision of the conversion.
 */
APFloat::opStatus APFloat::convertToInteger(APSInt &result,
                                            roundingMode rounding_mode,
                                            bool *isExact) const {}

double APFloat::convertToDouble() const {}

#ifdef HAS_IEE754_FLOAT128
float128 APFloat::convertToQuad() const {}
#endif

float APFloat::convertToFloat() const {}

} // namespace llvm

#undef APFLOAT_DISPATCH_ON_SEMANTICS