17 #ifndef LLVM_ADT_APFLOAT_H
18 #define LLVM_ADT_APFLOAT_H
442 unsigned FormatMaxPadding = 3)
const;
469 void makeNaN(
bool SNaN =
false,
bool Neg =
false,
470 const APInt *fill =
nullptr);
471 void makeInf(
bool Neg =
false);
491 unsigned int partCount()
const;
503 void incrementSignificand();
505 void shiftSignificandLeft(
unsigned int);
507 unsigned int significandLSB()
const;
508 unsigned int significandMSB()
const;
509 void zeroSignificand();
511 bool isSignificandAllOnes()
const;
513 bool isSignificandAllZeros()
const;
530 bool convertFromStringSpecials(
StringRef str);
541 char *convertNormalToHexString(
char *,
unsigned int,
bool,
548 APInt convertHalfAPFloatToAPInt()
const;
549 APInt convertFloatAPFloatToAPInt()
const;
550 APInt convertDoubleAPFloatToAPInt()
const;
551 APInt convertQuadrupleAPFloatToAPInt()
const;
552 APInt convertF80LongDoubleAPFloatToAPInt()
const;
553 APInt convertPPCDoubleDoubleAPFloatToAPInt()
const;
555 void initFromHalfAPInt(
const APInt &api);
556 void initFromFloatAPInt(
const APInt &api);
557 void initFromDoubleAPInt(
const APInt &api);
558 void initFromQuadrupleAPInt(
const APInt &api);
559 void initFromF80LongDoubleAPInt(
const APInt &api);
560 void initFromPPCDoubleDoubleAPInt(
const APInt &api);
564 void freeSignificand();
588 unsigned int sign : 1;
592 int ilogb(
const IEEEFloat &Arg);
603 std::unique_ptr<APFloat[]> Floats;
657 static_assert(std::is_standard_layout<IEEEFloat>::value,
"");
666 : Double(std::move(F)) {
670 template <
typename... ArgTypes>
672 if (usesLayout<IEEEFloat>(Semantics)) {
676 if (usesLayout<DoubleAPFloat>(Semantics)) {
684 if (usesLayout<IEEEFloat>(*semantics)) {
688 if (usesLayout<DoubleAPFloat>(*semantics)) {
689 Double.~DoubleAPFloat();
695 Storage(
const Storage &RHS) {
696 if (usesLayout<IEEEFloat>(*RHS.semantics)) {
700 if (usesLayout<DoubleAPFloat>(*RHS.semantics)) {
707 Storage(Storage &&RHS) {
708 if (usesLayout<IEEEFloat>(*RHS.semantics)) {
709 new (
this)
IEEEFloat(std::move(RHS.IEEE));
712 if (usesLayout<DoubleAPFloat>(*RHS.semantics)) {
720 if (usesLayout<IEEEFloat>(*semantics) &&
721 usesLayout<IEEEFloat>(*RHS.semantics)) {
723 }
else if (usesLayout<DoubleAPFloat>(*semantics) &&
724 usesLayout<DoubleAPFloat>(*RHS.semantics)) {
726 }
else if (
this != &RHS) {
728 new (
this) Storage(RHS);
734 if (usesLayout<IEEEFloat>(*semantics) &&
735 usesLayout<IEEEFloat>(*RHS.semantics)) {
736 IEEE = std::move(RHS.IEEE);
737 }
else if (usesLayout<DoubleAPFloat>(*semantics) &&
738 usesLayout<DoubleAPFloat>(*RHS.semantics)) {
739 Double = std::move(RHS.Double);
740 }
else if (
this != &RHS) {
742 new (
this) Storage(std::move(RHS));
748 template <
typename T>
static bool usesLayout(
const fltSemantics &Semantics) {
749 static_assert(std::is_same<T, IEEEFloat>::value ||
750 std::is_same<T, DoubleAPFloat>::value,
"");
751 if (std::is_same<T, DoubleAPFloat>::value) {
758 if (usesLayout<IEEEFloat>(*U.semantics))
760 if (usesLayout<DoubleAPFloat>(*U.semantics))
761 return U.Double.getFirst().U.IEEE;
766 if (usesLayout<IEEEFloat>(*U.semantics))
768 if (usesLayout<DoubleAPFloat>(*U.semantics))
769 return U.Double.getFirst().U.IEEE;
773 void makeZero(
bool Neg) { getIEEE().
makeZero(Neg); }
775 void makeInf(
bool Neg) {
776 if (usesLayout<IEEEFloat>(*U.semantics))
777 return U.IEEE.makeInf(Neg);
778 if (usesLayout<DoubleAPFloat>(*U.semantics))
779 return U.Double.makeInf(Neg);
783 void makeNaN(
bool SNaN,
bool Neg,
const APInt *fill) {
784 getIEEE().
makeNaN(SNaN, Neg, fill);
787 void makeLargest(
bool Neg) { getIEEE().
makeLargest(Neg); }
789 void makeSmallest(
bool Neg) { getIEEE().
makeSmallest(Neg); }
791 void makeSmallestNormalized(
bool Neg) {
804 : U(std::move(F), S) {}
809 return U.IEEE.compareAbsoluteValue(RHS.U.IEEE);
811 return U.Double.compareAbsoluteValue(RHS.U.Double);
832 return U.IEEE.needsCleanup();
834 return U.Double.needsCleanup();
843 Val.makeZero(Negative);
852 Val.makeInf(Negative);
864 APInt fill(64, type);
865 return getQNaN(Sem, Negative, &fill);
867 return getQNaN(Sem, Negative,
nullptr);
873 const APInt *payload =
nullptr) {
875 Val.makeNaN(
false, Negative, payload);
881 const APInt *payload =
nullptr) {
883 Val.makeNaN(
true, Negative, payload);
892 Val.makeLargest(Negative);
902 Val.makeSmallest(Negative);
911 bool Negative =
false) {
913 Val.makeSmallestNormalized(Negative);
927 return U.IEEE.add(RHS.U.IEEE, RM);
929 return U.Double.add(RHS.U.Double, RM);
934 return U.IEEE.subtract(RHS.U.IEEE, RM);
936 return U.Double.subtract(RHS.U.Double, RM);
943 return getIEEE().
divide(RHS.getIEEE(),
RM);
946 return getIEEE().
remainder(RHS.getIEEE());
988 bool *IsExact)
const {
992 bool *IsExact)
const {
1000 unsigned int InputSize,
bool IsSigned,
1006 unsigned int InputSize,
bool IsSigned,
1019 return getIEEE().
compare(RHS.getIEEE());
1056 unsigned FormatMaxPadding = 3)
const {
1057 return getIEEE().
toString(Str, FormatPrecision, FormatMaxPadding);
1071 return U.Double.getSecond();
1128 #endif // LLVM_ADT_APFLOAT_H
friend int ilogb(const APFloat &Arg)
opStatus roundToIntegral(roundingMode RM)
DoubleAPFloat & operator=(const DoubleAPFloat &RHS)
fltCategory
Category of internally-represented number.
const APFloat & getFirst() const
void makeNaN(bool SNaN, bool Neg, const APInt *fill)
opStatus convertFromAPInt(const APInt &Input, bool IsSigned, roundingMode RM)
APFloat(const fltSemantics &Semantics)
void makeSmallestNormalized(bool Negative=false)
Returns the smallest (by magnitude) normalized finite number in the given semantics.
float convertToFloat() const
opStatus convertFromSignExtendedInteger(const integerPart *, unsigned int, bool, roundingMode)
opStatus roundToIntegral(roundingMode)
fltCategory getCategory() const
bool isSmallest() const
Returns true if and only if the number has the smallest possible non-zero magnitude in the current se...
bool bitwiseIsEqual(const IEEEFloat &) const
Bitwise comparison for equality (QNaNs compare equal, 0!=-0).
void makeInf(bool Neg=false)
static unsigned getSizeInBits(const fltSemantics &Sem)
Returns the size of the floating point number (in bits) in the given semantics.
hash_code hash_value(const IEEEFloat &Arg)
static const fltSemantics & Bogus()
A Pseudo fltsemantic used to construct APFloats that cannot conflict with anything real...
static APFloat getZero(const fltSemantics &Sem, bool Negative=false)
Factory for Positive and Negative Zero.
friend IEEEFloat frexp(const IEEEFloat &X, int &Exp, roundingMode)
bool isFinite() const
Returns true if and only if the current value is zero, subnormal, or normal.
bool isFiniteNonZero() const
opStatus next(bool nextDown)
APFloat(const fltSemantics &Semantics, const APInt &I)
bool isLargest() const
Returns true if and only if the number has the largest possible finite magnitude in the current seman...
opStatus convertFromSignExtendedInteger(const integerPart *Input, unsigned int InputSize, bool IsSigned, roundingMode RM)
friend APFloat frexp(const APFloat &X, int &Exp, roundingMode RM)
opStatus divide(const APFloat &RHS, roundingMode RM)
static APFloat getSmallest(const fltSemantics &Sem, bool Negative=false)
Returns the smallest (by magnitude) finite number in the given semantics.
const APFloat & getSecond() const
opStatus convertFromString(StringRef, roundingMode)
static const fltSemantics & x87DoubleExtended()
roundingMode
IEEE-754R 4.3: Rounding-direction attributes.
IEEEFloat(const fltSemantics &)
static APFloat getAllOnesValue(unsigned BitWidth, bool isIEEE=false)
Returns a float which is bitcasted from an all one value int.
void makeLargest(bool Neg=false)
Make this number the largest magnitude normal number in the given semantics.
void toString(SmallVectorImpl< char > &Str, unsigned FormatPrecision=0, unsigned FormatMaxPadding=3) const
This class consists of common code factored out of the SmallVector class to reduce code duplication b...
bool isFiniteNonZero() const
APFloat & operator=(const APFloat &RHS)=default
cmpResult compareAbsoluteValue(const DoubleAPFloat &RHS) const
APInt bitcastToAPInt() const
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...
opStatus subtract(const DoubleAPFloat &RHS, roundingMode RM)
static ExponentType semanticsMaxExponent(const fltSemantics &)
bool isSignaling() const
Returns true if and only if the float is a signaling NaN.
void makeSmallest(bool Neg=false)
Make this number the smallest magnitude denormal number in the given semantics.
APFloat operator+(const APFloat &RHS) const
This file implements a class to represent arbitrary precision integral constant values and operations...
void makeNaN(bool SNaN=false, bool Neg=false, const APInt *fill=nullptr)
opStatus add(const DoubleAPFloat &RHS, roundingMode RM)
IEEEFloat & operator=(const IEEEFloat &)
void Profile(FoldingSetNodeID &NID) const
Used to insert APFloat objects, or objects that contain APFloat objects, into FoldingSets.
opStatus convert(const fltSemantics &ToSemantics, roundingMode RM, bool *losesInfo)
static unsigned int semanticsSizeInBits(const fltSemantics &)
cmpResult compare(const IEEEFloat &) const
IEEE comparison with another floating point number (NaNs compare unordered, 0==-0).
fltCategory getCategory() const
opStatus convertFromAPInt(const APInt &, bool, roundingMode)
bool isNormal() const
IEEE-754R isNormal: Returns true if and only if the current value is normal.
opStatus mod(const IEEEFloat &)
C fmod, or llvm frem.
bool isZero() const
Returns true if and only if the float is plus or minus zero.
hash_code hash_value(const APFloat &Arg)
See friend declarations above.
opStatus next(bool nextDown)
IEEE-754R 5.3.1: nextUp/nextDown.
IEEEFloat frexp(const IEEEFloat &Val, int &Exp, IEEEFloat::roundingMode RM)
opStatus subtract(const APFloat &RHS, roundingMode RM)
opStatus convertFromString(StringRef, roundingMode)
static GCRegistry::Add< OcamlGC > B("ocaml","ocaml 3.10-compatible GC")
cmpResult
IEEE-754R 5.11: Floating Point Comparison Relations.
DoubleAPFloat(const fltSemantics &S)
const APFloat & getSecondFloat() const
bool isInteger() const
Returns true if and only if the number is an exact integer.
opStatus convertFromZeroExtendedInteger(const integerPart *, unsigned int, bool, roundingMode)
static APFloat getInf(const fltSemantics &Sem, bool Negative=false)
Factory for Positive and Negative Infinity.
static ExponentType semanticsMinExponent(const fltSemantics &)
const fltSemantics & getSemantics() const
opStatus convertToInteger(integerPart *, unsigned int, bool, roundingMode, bool *) const
uninitializedTag
Convenience enum used to construct an uninitialized APFloat.
cmpResult compareAbsoluteValue(const IEEEFloat &) const
IlogbErrorKinds
Enumeration of ilogb error results.
static APFloat copySign(APFloat Value, const APFloat &Sign)
static const fltSemantics & IEEEsingle()
FoldingSetNodeID - This class is used to gather all the unique data bits of a node.
friend hash_code hash_value(const APFloat &Arg)
See friend declarations above.
void Profile(FoldingSetNodeID &NID) const
bool operator==(const APFloat &) const =delete
bool bitwiseIsEqual(const APFloat &RHS) const
IEEEFloat scalbn(IEEEFloat X, int Exp, IEEEFloat::roundingMode)
opStatus convert(const fltSemantics &, roundingMode, bool *)
IEEEFloat::convert - convert a value of one floating point type to another.
static const fltSemantics & IEEEhalf()
friend APFloat scalbn(APFloat X, int Exp, roundingMode RM)
APFloat scalbn(APFloat X, int Exp, APFloat::roundingMode RM)
opStatus remainder(const IEEEFloat &)
IEEE remainder.
static GCMetadataPrinterRegistry::Add< ErlangGCPrinter > X("erlang","erlang-compatible garbage collector")
static IEEEFloat copySign(IEEEFloat Value, const IEEEFloat &Sign)
A static helper to produce a copy of an APFloat value with its sign copied from some other APFloat...
opStatus multiply(const APFloat &RHS, roundingMode RM)
APFloat operator/(const APFloat &RHS) const
opStatus convertToInteger(integerPart *Input, unsigned int Width, bool IsSigned, roundingMode RM, bool *IsExact) const
fltCategory getCategory() const
friend int ilogb(const IEEEFloat &Arg)
Returns the exponent of the internal representation of the APFloat.
static const fltSemantics & IEEEquad()
#define llvm_unreachable(msg)
Marks that the current location is not supposed to be reachable.
void copySign(const APFloat &RHS)
LLVM_READONLY APFloat maxnum(const APFloat &A, const APFloat &B)
Implements IEEE maxNum semantics.
bool needsCleanup() const
void toString(SmallVectorImpl< char > &Str, unsigned FormatPrecision=0, unsigned FormatMaxPadding=3) const
Converts this value into a decimal string.
signed short ExponentType
A signed type to represent a floating point numbers unbiased exponent.
IEEEFloat operator*(const IEEEFloat &RHS) const
Operator* overload which provides the default nmNearestTiesToEven rounding mode and no error checking...
void makeZero(bool Neg=false)
bool isInfinity() const
IEEE-754R isInfinite(): Returns true if and only if the float is infinity.
DoubleAPFloat & operator=(DoubleAPFloat &&RHS)
IEEEFloat operator-(const IEEEFloat &RHS) const
Operator- overload which provides the default nmNearestTiesToEven rounding mode and no error checking...
opStatus add(const IEEEFloat &, roundingMode)
void copySign(const IEEEFloat &)
lostFraction
Enum that represents what fraction of the LSB truncated bits of an fp number represent.
opStatus subtract(const IEEEFloat &, roundingMode)
APFloat frexp(const APFloat &X, int &Exp, APFloat::roundingMode RM)
Equivalent of C standard library function.
static unsigned int semanticsPrecision(const fltSemantics &)
bool needsCleanup() const
Class for arbitrary precision integers.
void print(raw_ostream &) const
static APFloat getSNaN(const fltSemantics &Sem, bool Negative=false, const APInt *payload=nullptr)
Factory for SNaN values.
unsigned int convertToHexString(char *DST, unsigned int HexDigits, bool UpperCase, roundingMode RM) const
opStatus mod(const APFloat &RHS)
An opaque object representing a hash code.
double convertToDouble() const
static const fltSemantics & IEEEdouble()
opStatus add(const APFloat &RHS, roundingMode RM)
bool isNegative() const
IEEE-754R isSignMinus: Returns true if and only if the current value is negative. ...
static APFloat getNaN(const fltSemantics &Sem, bool Negative=false, unsigned type=0)
Factory for NaN values.
opStatus
IEEE-754R 7: Default exception handling.
double convertToDouble() const
APFloat operator*(const APFloat &RHS) const
bool needsCleanup() const
Returns whether this instance allocated memory.
APFloat abs(APFloat X)
Returns the absolute value of the argument.
opStatus fusedMultiplyAdd(const IEEEFloat &, const IEEEFloat &, roundingMode)
static const fltSemantics & PPCDoubleDouble()
IEEEFloat operator+(const IEEEFloat &RHS) const
Operator+ overload which provides the default nmNearestTiesToEven rounding mode and no error checking...
static APFloat getLargest(const fltSemantics &Sem, bool Negative=false)
Returns the largest finite number in the given semantics.
static APFloat getSmallestNormalized(const fltSemantics &Sem, bool Negative=false)
Returns the smallest (by magnitude) normalized finite number in the given semantics.
float convertToFloat() const
opStatus divide(const IEEEFloat &, roundingMode)
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
opStatus fusedMultiplyAdd(const APFloat &Multiplicand, const APFloat &Addend, roundingMode RM)
APFloat operator-(const APFloat &RHS) const
opStatus remainder(const APFloat &RHS)
A self-contained host- and target-independent arbitrary-precision floating-point software implementat...
LLVM Value Representation.
APInt bitcastToAPInt() const
opStatus multiply(const IEEEFloat &, roundingMode)
bool operator==(const IEEEFloat &) const =delete
The definition of equality is not straightforward for floating point, so we won't use operator==...
opStatus convertToInteger(APSInt &Result, roundingMode RM, bool *IsExact) const
bool getExactInverse(IEEEFloat *inv) const
If this value has an exact multiplicative inverse, store it in inv and return true.
This class implements an extremely fast bulk output stream that can only output to a stream...
friend IEEEFloat scalbn(IEEEFloat X, int Exp, roundingMode)
Returns: X * 2^Exp for integral exponents.
cmpResult compare(const APFloat &RHS) const
StringRef - Represent a constant reference to a string, i.e.
opStatus convertFromZeroExtendedInteger(const integerPart *Input, unsigned int InputSize, bool IsSigned, roundingMode RM)
bool getExactInverse(APFloat *inv) const
IEEEFloat operator/(const IEEEFloat &RHS) const
Operator/ overload which provides the default nmNearestTiesToEven rounding mode and no error checking...
bool isNaN() const
Returns true if and only if the float is a quiet or signaling NaN.
bool isDenormal() const
IEEE-754R isSubnormal(): Returns true if and only if the float is a denormal.
friend hash_code hash_value(const IEEEFloat &Arg)
Overload to compute a hash code for an APFloat value.
static GCRegistry::Add< ErlangGC > A("erlang","erlang-compatible garbage collector")
APFloat(const fltSemantics &Semantics, integerPart I)
const fltSemantics & getSemantics() const
static APFloat getQNaN(const fltSemantics &Sem, bool Negative=false, const APInt *payload=nullptr)
Factory for QNaN values.
APFloat(const fltSemantics &Semantics, uninitializedTag)
LLVM_READONLY APFloat minnum(const APFloat &A, const APFloat &B)
Implements IEEE minNum semantics.
int ilogb(const IEEEFloat &Arg)