|
LLVM
3.7.0
|
A self-contained host- and target-independent arbitrary-precision floating-point software implementation. More...
#include <APFloat.h>
Public Types | |
| enum | cmpResult { cmpLessThan, cmpEqual, cmpGreaterThan, cmpUnordered } |
| IEEE-754R 5.11: Floating Point Comparison Relations. More... | |
| enum | roundingMode { rmNearestTiesToEven, rmTowardPositive, rmTowardNegative, rmTowardZero, rmNearestTiesToAway } |
| IEEE-754R 4.3: Rounding-direction attributes. More... | |
| enum | opStatus { opOK = 0x00, opInvalidOp = 0x01, opDivByZero = 0x02, opOverflow = 0x04, opUnderflow = 0x08, opInexact = 0x10 } |
| IEEE-754R 7: Default exception handling. More... | |
| enum | fltCategory { fcInfinity, fcNaN, fcNormal, fcZero } |
| Category of internally-represented number. More... | |
| enum | uninitializedTag { uninitialized } |
| Convenience enum used to construct an uninitialized APFloat. More... | |
| enum | IlogbErrorKinds { IEK_Zero = INT_MIN+1, IEK_NaN = INT_MIN, IEK_Inf = INT_MAX } |
Enumeration of ilogb error results. More... | |
| typedef signed short | ExponentType |
| A signed type to represent a floating point numbers unbiased exponent. More... | |
Public Member Functions | |
| bool | needsCleanup () const |
| Returns whether this instance allocated memory. More... | |
| void | Profile (FoldingSetNodeID &NID) const |
| Used to insert APFloat objects, or objects that contain APFloat objects, into FoldingSets. More... | |
| bool | operator== (const APFloat &) const =delete |
| The definition of equality is not straightforward for floating point, so we won't use operator==. More... | |
| cmpResult | compare (const APFloat &) const |
| IEEE comparison with another floating point number (NaNs compare unordered, 0==-0). More... | |
| bool | bitwiseIsEqual (const APFloat &) const |
| Bitwise comparison for equality (QNaNs compare equal, 0!=-0). More... | |
| 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 sufficient size, in the C99 form [-]0xh.hhhhp[+-]d. More... | |
| APFloat & | operator= (const APFloat &) |
| APFloat & | operator= (APFloat &&) |
| void | toString (SmallVectorImpl< char > &Str, unsigned FormatPrecision=0, unsigned FormatMaxPadding=3) const |
| Converts this value into a decimal string. More... | |
| bool | getExactInverse (APFloat *inv) const |
| If this value has an exact multiplicative inverse, store it in inv and return true. More... | |
Constructors | |
| APFloat (const fltSemantics &) | |
| APFloat (const fltSemantics &, StringRef) | |
| APFloat (const fltSemantics &, integerPart) | |
| APFloat (const fltSemantics &, uninitializedTag) | |
| APFloat (const fltSemantics &, const APInt &) | |
| APFloat (double d) | |
| APFloat (float f) | |
| APFloat (const APFloat &) | |
| APFloat (APFloat &&) | |
| ~APFloat () | |
Arithmetic | |
| opStatus | add (const APFloat &, roundingMode) |
| opStatus | subtract (const APFloat &, roundingMode) |
| opStatus | multiply (const APFloat &, roundingMode) |
| opStatus | divide (const APFloat &, roundingMode) |
| opStatus | remainder (const APFloat &) |
| IEEE remainder. More... | |
| opStatus | mod (const APFloat &, roundingMode) |
| C fmod, or llvm frem. More... | |
| opStatus | fusedMultiplyAdd (const APFloat &, const APFloat &, roundingMode) |
| opStatus | roundToIntegral (roundingMode) |
| opStatus | next (bool nextDown) |
| IEEE-754R 5.3.1: nextUp/nextDown. More... | |
| APFloat | operator+ (const APFloat &RHS) const |
Operator+ overload which provides the default nmNearestTiesToEven rounding mode and no error checking. More... | |
| APFloat | operator- (const APFloat &RHS) const |
Operator- overload which provides the default nmNearestTiesToEven rounding mode and no error checking. More... | |
| APFloat | operator* (const APFloat &RHS) const |
Operator* overload which provides the default nmNearestTiesToEven rounding mode and no error checking. More... | |
| APFloat | operator/ (const APFloat &RHS) const |
Operator/ overload which provides the default nmNearestTiesToEven rounding mode and no error checking. More... | |
Conversions | |
| opStatus | convert (const fltSemantics &, roundingMode, bool *) |
| APFloat::convert - convert a value of one floating point type to another. More... | |
| opStatus | convertToInteger (integerPart *, unsigned int, bool, roundingMode, bool *) const |
| opStatus | convertToInteger (APSInt &, roundingMode, bool *) const |
| opStatus | convertFromAPInt (const APInt &, bool, roundingMode) |
| opStatus | convertFromSignExtendedInteger (const integerPart *, unsigned int, bool, roundingMode) |
| opStatus | convertFromZeroExtendedInteger (const integerPart *, unsigned int, bool, roundingMode) |
| opStatus | convertFromString (StringRef, roundingMode) |
| APInt | bitcastToAPInt () const |
| double | convertToDouble () const |
| float | convertToFloat () const |
IEEE-754R 5.7.2 General operations. | |
| bool | isNegative () const |
| IEEE-754R isSignMinus: Returns true if and only if the current value is negative. More... | |
| bool | isNormal () const |
| IEEE-754R isNormal: Returns true if and only if the current value is normal. More... | |
| bool | isFinite () const |
| Returns true if and only if the current value is zero, subnormal, or normal. More... | |
| bool | isZero () const |
| Returns true if and only if the float is plus or minus zero. More... | |
| bool | isDenormal () const |
| IEEE-754R isSubnormal(): Returns true if and only if the float is a denormal. More... | |
| bool | isInfinity () const |
| IEEE-754R isInfinite(): Returns true if and only if the float is infinity. More... | |
| bool | isNaN () const |
| Returns true if and only if the float is a quiet or signaling NaN. More... | |
| bool | isSignaling () const |
| Returns true if and only if the float is a signaling NaN. More... | |
Static Public Member Functions | |
| static unsigned int | semanticsPrecision (const fltSemantics &) |
Convenience "constructors" | |
| static APFloat | getZero (const fltSemantics &Sem, bool Negative=false) |
| Factory for Positive and Negative Zero. More... | |
| static APFloat | getInf (const fltSemantics &Sem, bool Negative=false) |
| Factory for Positive and Negative Infinity. More... | |
| static APFloat | getNaN (const fltSemantics &Sem, bool Negative=false, unsigned type=0) |
| Factory for QNaN values. More... | |
| static APFloat | getQNaN (const fltSemantics &Sem, bool Negative=false, const APInt *payload=nullptr) |
| Factory for QNaN values. More... | |
| static APFloat | getSNaN (const fltSemantics &Sem, bool Negative=false, const APInt *payload=nullptr) |
| Factory for SNaN values. More... | |
| static APFloat | getLargest (const fltSemantics &Sem, bool Negative=false) |
| Returns the largest finite number in the given semantics. More... | |
| static APFloat | getSmallest (const fltSemantics &Sem, bool Negative=false) |
| Returns the smallest (by magnitude) finite number in the given semantics. More... | |
| static APFloat | getSmallestNormalized (const fltSemantics &Sem, bool Negative=false) |
| Returns the smallest (by magnitude) normalized finite number in the given semantics. More... | |
| static APFloat | getAllOnesValue (unsigned BitWidth, bool isIEEE=false) |
| Returns a float which is bitcasted from an all one value int. More... | |
| static unsigned | getSizeInBits (const fltSemantics &Sem) |
| Returns the size of the floating point number (in bits) in the given semantics. More... | |
Static Public Attributes | |
Floating Point Semantics. | |
| static const fltSemantics | IEEEhalf = { 15, -14, 11, 16 } |
| static const fltSemantics | IEEEsingle = { 127, -126, 24, 32 } |
| static const fltSemantics | IEEEdouble = { 1023, -1022, 53, 64 } |
| static const fltSemantics | IEEEquad = { 16383, -16382, 113, 128 } |
| static const fltSemantics | PPCDoubleDouble = { 1023, -1022 + 53, 53 + 53, 128 } |
| static const fltSemantics | x87DoubleExtended = { 16383, -16382, 64, 80 } |
| static const fltSemantics | Bogus = { 0, 0, 0, 0 } |
| A Pseudo fltsemantic used to construct APFloats that cannot conflict with anything real. More... | |
Friends | |
| hash_code | hash_value (const APFloat &Arg) |
| Overload to compute a hash code for an APFloat value. More... | |
| int | ilogb (const APFloat &Arg) |
| Returns the exponent of the internal representation of the APFloat. More... | |
| APFloat | scalbn (APFloat X, int Exp) |
| Returns: X * 2^Exp for integral exponents. More... | |
Sign operations. | |
| static APFloat | copySign (APFloat Value, const APFloat &Sign) |
| A static helper to produce a copy of an APFloat value with its sign copied from some other APFloat. More... | |
| void | changeSign () |
| void | clearSign () |
| void | copySign (const APFloat &) |
Simple Queries | |
| fltCategory | getCategory () const |
| const fltSemantics & | getSemantics () const |
| bool | isNonZero () const |
| bool | isFiniteNonZero () const |
| bool | isPosZero () const |
| bool | isNegZero () const |
| bool | isSmallest () const |
| Returns true if and only if the number has the smallest possible non-zero magnitude in the current semantics. More... | |
| bool | isLargest () const |
| Returns true if and only if the number has the largest possible finite magnitude in the current semantics. More... | |
A self-contained host- and target-independent arbitrary-precision floating-point software implementation.
APFloat uses bignum integer arithmetic as provided by static functions in the APInt class. The library will work with bignum integers whose parts are any unsigned type at least 16 bits wide, but 64 bits is recommended.
Written for clarity rather than speed, in particular with a view to use in the front-end of a cross compiler so that target arithmetic can be correctly performed on the host. Performance should nonetheless be reasonable, particularly for its intended use. It may be useful as a base implementation for a run-time library during development of a faster target-specific one.
All 5 rounding modes in the IEEE-754R draft are handled correctly for all implemented operations. Currently implemented operations are add, subtract, multiply, divide, fused-multiply-add, conversion-to-float, conversion-to-integer and conversion-from-integer. New rounding modes (e.g. away from zero) can be added with three or four lines of code.
Four formats are built-in: IEEE single precision, double precision, quadruple precision, and x87 80-bit extended double (when operating with full extended precision). Adding a new format that obeys IEEE semantics only requires adding two lines of code: a declaration and definition of the format.
All operations return the status of that operation as an exception bit-mask, so multiple operations can be done consecutively with their results or-ed together. The returned status can be useful for compiler diagnostics; e.g., inexact, underflow and overflow can be easily diagnosed on constant folding, and compiler optimizers can determine what exceptions would be raised by folding operations and optimize, or perhaps not optimize, accordingly.
At present, underflow tininess is detected after rounding; it should be straight forward to add support for the before-rounding case too.
The library reads hexadecimal floating point numbers as per C99, and correctly rounds if necessary according to the specified rounding mode. Syntax is required to have been validated by the caller. It also converts floating point numbers to hexadecimal text as per the C99 a and A conversions. The output precision (or alternatively the natural minimal precision) can be specified; if the requested precision is less than the natural precision the output is correctly rounded for the specified rounding mode.
It also reads decimal floating point numbers and correctly rounds according to the specified rounding mode.
Conversion to decimal text is not currently implemented.
Non-zero finite numbers are represented internally as a sign bit, a 16-bit signed exponent, and the significand as an array of integer parts. After normalization of a number of precision P the exponent is within the range of the format, and if the number is not denormal the P-th bit of the significand is set as an explicit integer bit. For denormals the most significant bit is shifted right so that the exponent is maintained at the format's minimum, so that the smallest denormal has just the least significant bit of the significand set. The sign of zeroes and infinities is significant; the exponent and significand of such numbers is not stored, but has a known implicit (deterministic) value: 0 for the significands, 0 for zero exponent, all 1 bits for infinity exponent. For NaNs the sign and significand are deterministic, although not really meaningful, and preserved in non-conversion operations. The exponent is implicitly all 1 bits.
APFloat does not provide any exception handling beyond default exception handling. We represent Signaling NaNs via IEEE-754R 2008 6.2.1 should clause by encoding Signaling NaNs with the first bit of its trailing significand as 0.
Some features that may or may not be worth adding:
Binary to decimal conversion (hard).
Optional ability to detect underflow tininess before rounding.
New formats: x87 in single and double precision mode (IEEE apart from extended exponent range) (hard).
New operations: sqrt, IEEE remainder, C90 fmod, nexttoward.
| typedef signed short llvm::APFloat::ExponentType |
| APFloat::APFloat | ( | const fltSemantics & | ourSemantics | ) |
| APFloat::APFloat | ( | const fltSemantics & | ourSemantics, |
| StringRef | text | ||
| ) |
Definition at line 815 of file APFloat.cpp.
References convertFromString(), and rmNearestTiesToEven.
| APFloat::APFloat | ( | const fltSemantics & | ourSemantics, |
| integerPart | value | ||
| ) |
Definition at line 794 of file APFloat.cpp.
References fcNormal, llvm::lfExactlyZero, llvm::fltSemantics::precision, and rmNearestTiesToEven.
| APFloat::APFloat | ( | const fltSemantics & | ourSemantics, |
| uninitializedTag | tag | ||
| ) |
Definition at line 810 of file APFloat.cpp.
| APFloat::APFloat | ( | const fltSemantics & | Sem, |
| const APInt & | API | ||
| ) |
Definition at line 3455 of file APFloat.cpp.
|
explicit |
Definition at line 3463 of file APFloat.cpp.
References llvm::APInt::doubleToBits(), and IEEEdouble.
|
explicit |
Definition at line 3459 of file APFloat.cpp.
References llvm::APInt::floatToBits(), and IEEEsingle.
Definition at line 820 of file APFloat.cpp.
| APFloat::APFloat | ( | APFloat && | rhs | ) |
Definition at line 825 of file APFloat.cpp.
| APFloat::~APFloat | ( | ) |
Definition at line 829 of file APFloat.cpp.
| APFloat::opStatus APFloat::add | ( | const APFloat & | rhs, |
| roundingMode | rounding_mode | ||
| ) |
Definition at line 1676 of file APFloat.cpp.
Referenced by llvm::ConstantFoldBinaryInstruction(), llvm::ExecutionEngine::getConstantValue(), llvm::SelectionDAG::getNode(), operator+(), and roundToIntegral().
| APInt APFloat::bitcastToAPInt | ( | ) | const |
Definition at line 3084 of file APFloat.cpp.
References IEEEdouble, IEEEhalf, IEEEquad, IEEEsingle, PPCDoubleDouble, and x87DoubleExtended.
Referenced by llvm::DwarfUnit::addConstantFPValue(), convertToDouble(), convertToFloat(), emitGlobalConstantFP(), llvm::R600TargetLowering::EmitInstrWithCustomInserter(), FoldOperand(), llvm::ExecutionEngine::getConstantValue(), llvm::AArch64_AM::getFP32Imm(), llvm::ARM_AM::getFP32Imm(), llvm::AArch64_AM::getFP64Imm(), llvm::ARM_AM::getFP64Imm(), llvm::SelectionDAG::getNode(), llvm::HexagonLowerToMC(), llvm::NVPTXFloatMCExpr::printImpl(), Profile(), and WriteConstantInternal().
Bitwise comparison for equality (QNaNs compare equal, 0!=-0).
Definition at line 771 of file APFloat.cpp.
References fcInfinity, fcZero, and isFiniteNonZero().
Referenced by llvm::DenseMapAPFloatKeyInfo::isEqual(), llvm::ConstantFP::isExactlyValue(), and llvm::X86TargetLowering::isFPImmLegal().
| void APFloat::changeSign | ( | ) |
Definition at line 1623 of file APFloat.cpp.
Referenced by GetNegatedExpression(), llvm::SelectionDAG::getNode(), next(), roundToIntegral(), and llvm::X86TargetLowering::X86TargetLowering().
| void APFloat::clearSign | ( | ) |
Definition at line 1630 of file APFloat.cpp.
Referenced by llvm::abs(), llvm::SelectionDAG::getNode(), LowerFCOPYSIGN(), and llvm::InstCombiner::visitFCmpInst().
| APFloat::cmpResult APFloat::compare | ( | const APFloat & | rhs | ) | const |
IEEE comparison with another floating point number (NaNs compare unordered, 0==-0).
Definition at line 1893 of file APFloat.cpp.
References cmpEqual, cmpGreaterThan, cmpLessThan, cmpUnordered, fcInfinity, fcNaN, fcNormal, fcZero, llvm_unreachable, and PackCategoriesIntoKey.
Referenced by llvm::ConstantFoldCompareInstruction(), llvm::InstCombiner::FoldFCmp_IntToFP_Cst(), llvm::MDNode::getMostGenericFPMath(), llvm::maxnum(), llvm::minnum(), and llvm::InstCombiner::visitFCmpInst().
| APFloat::opStatus APFloat::convert | ( | const fltSemantics & | toSemantics, |
| roundingMode | rounding_mode, | ||
| bool * | losesInfo | ||
| ) |
APFloat::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).
Definition at line 1972 of file APFloat.cpp.
References fcNaN, isFiniteNonZero(), llvm::lfExactlyZero, llvm::fltSemantics::minExponent, opOK, partCountForBits(), llvm::fltSemantics::precision, shiftRight(), llvm::APInt::tcAssign(), llvm::APInt::tcSet(), llvm::APInt::tcSetBit(), llvm::APInt::tcShiftLeft(), and x87DoubleExtended.
Referenced by llvm::ConstantFoldCastInstruction(), ConstantFoldScalarCall(), emitDebugValueComment(), FitsInFPType(), llvm::ConstantFP::get(), GetConstantFoldFPValue(), llvm::SelectionDAG::getConstantFP(), llvm::SelectionDAG::getNode(), getValueAsDouble(), llvm::ConstantFP::isExactlyValue(), llvm::ConstantFPSDNode::isExactlyValue(), llvm::ConstantFP::isValueValidForType(), LLVMConstRealGetDouble(), llvm::ARMAsmPrinter::lowerOperand(), llvm::NVPTXFloatMCExpr::printImpl(), selectCCOpsAreFMaxCompatible(), valueHasFloatPrecision(), llvm::InstCombiner::visitFCmpInst(), WriteConstantInternal(), and llvm::X86TargetLowering::X86TargetLowering().
| APFloat::opStatus APFloat::convertFromAPInt | ( | const APInt & | Val, |
| bool | isSigned, | ||
| roundingMode | rounding_mode | ||
| ) |
Definition at line 2272 of file APFloat.cpp.
References llvm::APInt::getNumWords(), llvm::APInt::getRawData(), and llvm::APInt::isNegative().
Referenced by llvm::ConstantFoldCastInstruction(), llvm::InstCombiner::FoldFCmp_IntToFP_Cst(), llvm::ExecutionEngine::getConstantValue(), llvm::SelectionDAG::getNode(), and roundToIntegral().
| APFloat::opStatus APFloat::convertFromSignExtendedInteger | ( | const integerPart * | src, |
| unsigned int | srcCount, | ||
| bool | isSigned, | ||
| roundingMode | rounding_mode | ||
| ) |
Definition at line 2292 of file APFloat.cpp.
References llvm::integerPartWidth, llvm::sys::fs::status(), llvm::APInt::tcAssign(), llvm::APInt::tcExtractBit(), and llvm::APInt::tcNegate().
| APFloat::opStatus APFloat::convertFromString | ( | StringRef | str, |
| roundingMode | rounding_mode | ||
| ) |
Definition at line 2645 of file APFloat.cpp.
References llvm::StringRef::begin(), llvm::StringRef::empty(), opOK, and llvm::StringRef::size().
Referenced by APFloat().
| APFloat::opStatus APFloat::convertFromZeroExtendedInteger | ( | const integerPart * | parts, |
| unsigned int | width, | ||
| bool | isSigned, | ||
| roundingMode | rounding_mode | ||
| ) |
Definition at line 2320 of file APFloat.cpp.
References llvm::APInt::getRawData(), llvm::makeArrayRef(), partCountForBits(), and llvm::APInt::tcExtractBit().
Referenced by mod(), and remainder().
| double APFloat::convertToDouble | ( | ) | const |
Definition at line 3116 of file APFloat.cpp.
References bitcastToAPInt(), llvm::APInt::bitsToDouble(), and IEEEdouble.
Referenced by emitDebugValueComment(), ftostr(), getValueAsDouble(), LLVMConstRealGetDouble(), and llvm::ARMAsmPrinter::lowerOperand().
| float APFloat::convertToFloat | ( | ) | const |
Definition at line 3107 of file APFloat.cpp.
References bitcastToAPInt(), llvm::APInt::bitsToFloat(), and IEEEsingle.
Referenced by emitDebugValueComment(), FoldOperand(), ftostr(), llvm::FPMathOperator::getFPAccuracy(), getValueAsDouble(), and LLVMConstRealGetDouble().
| unsigned int APFloat::convertToHexString | ( | char * | dst, |
| unsigned int | hexDigits, | ||
| bool | upperCase, | ||
| roundingMode | rounding_mode | ||
| ) | const |
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.
Definition at line 2697 of file APFloat.cpp.
References fcInfinity, fcNaN, fcNormal, fcZero, infinityL, infinityU, NaNL, and NaNU.
| APFloat::opStatus APFloat::convertToInteger | ( | integerPart * | parts, |
| unsigned int | width, | ||
| bool | isSigned, | ||
| roundingMode | rounding_mode, | ||
| bool * | isExact | ||
| ) | const |
Definition at line 2191 of file APFloat.cpp.
References fcNaN, opInvalidOp, partCountForBits(), llvm::APInt::tcSetLeastSignificantBits(), and llvm::APInt::tcShiftLeft().
Referenced by llvm::ConstantFoldCastInstruction(), ConstantFoldConvertToInt(), convertToInteger(), ConvertToSInt(), llvm::InstCombiner::FoldFCmp_IntToFP_Cst(), llvm::ExecutionEngine::getConstantValue(), llvm::SelectionDAG::getNode(), isConstVecPow2(), mod(), and remainder().
| APFloat::opStatus APFloat::convertToInteger | ( | APSInt & | result, |
| roundingMode | rounding_mode, | ||
| bool * | isExact | ||
| ) | const |
Definition at line 2225 of file APFloat.cpp.
References convertToInteger(), llvm::APInt::getBitWidth(), llvm::APInt::getNumWords(), llvm::APSInt::isSigned(), and llvm::sys::fs::status().
Definition at line 1637 of file APFloat.cpp.
Referenced by ConstantFoldScalarCall(), copySign(), llvm::SelectionDAG::getNode(), and roundToIntegral().
A static helper to produce a copy of an APFloat value with its sign copied from some other APFloat.
Definition at line 348 of file APFloat.h.
References copySign().
| APFloat::opStatus APFloat::divide | ( | const APFloat & | rhs, |
| roundingMode | rounding_mode | ||
| ) |
Definition at line 1709 of file APFloat.cpp.
References isFiniteNonZero(), llvm::lfExactlyZero, and opInexact.
Referenced by llvm::ConstantFoldBinaryInstruction(), llvm::ExecutionEngine::getConstantValue(), getExactInverse(), llvm::SelectionDAG::getNode(), mod(), operator/(), remainder(), and llvm::InstCombiner::visitCallInst().
| APFloat::opStatus APFloat::fusedMultiplyAdd | ( | const APFloat & | multiplicand, |
| const APFloat & | addend, | ||
| roundingMode | rounding_mode | ||
| ) |
Definition at line 1805 of file APFloat.cpp.
References fcZero, isFinite(), isFiniteNonZero(), llvm::lfExactlyZero, opInexact, opOK, opUnderflow, and rmTowardNegative.
Referenced by ConstantFoldScalarCall(), and llvm::SelectionDAG::getNode().
Returns a float which is bitcasted from an all one value int.
| BitWidth | - Select float type |
| isIEEE | - If 128 bit number, select between PPC and IEEE |
Definition at line 3354 of file APFloat.cpp.
References APFloat(), llvm::APInt::getAllOnesValue(), IEEEdouble, IEEEhalf, IEEEquad, IEEEsingle, llvm_unreachable, PPCDoubleDouble, and x87DoubleExtended.
Referenced by llvm::Constant::getAllOnesValue().
|
inline |
If this value has an exact multiplicative inverse, store it in inv and return true.
Definition at line 3754 of file APFloat.cpp.
References divide(), isDenormal(), isFiniteNonZero(), opOK, llvm::fltSemantics::precision, and rmNearestTiesToEven.
Referenced by CvtFDivConstToReciprocal().
|
inlinestatic |
Factory for Positive and Negative Infinity.
| Negative | True iff the number should be negative. |
Definition at line 222 of file APFloat.h.
References uninitialized.
Referenced by llvm::ConstantFP::getInfinity(), and llvm::scalbn().
|
static |
Returns the largest finite number in the given semantics.
| Negative | - True iff the number should be negative |
Definition at line 3417 of file APFloat.cpp.
References uninitialized.
|
inlinestatic |
Factory for QNaN values.
| Negative | - True iff the NaN generated should be negative. |
| type | - The unspecified fill bits for creating the NaN, 0 by default. The value is truncated as necessary. |
Definition at line 233 of file APFloat.h.
References getQNaN().
Referenced by llvm::ConstantFP::getNaN().
|
inline |
Definition at line 435 of file APFloat.h.
Referenced by llvm::ConstantFP::ConstantFP(), CvtFDivConstToReciprocal(), llvm::InstCombiner::FoldFCmp_IntToFP_Cst(), ftostr(), llvm::ConstantFP::get(), llvm::ConstantFP::isExactlyValue(), llvm::ConstantFP::isValueValidForType(), llvm::scalbn(), and llvm::InstCombiner::visitCallInst().
|
static |
Returns the size of the floating point number (in bits) in the given semantics.
Definition at line 3374 of file APFloat.cpp.
References llvm::fltSemantics::sizeInBits.
|
static |
Returns the smallest (by magnitude) finite number in the given semantics.
Might be denormalized, which implies a relative loss of precision.
| Negative | - True iff the number should be negative |
Definition at line 3427 of file APFloat.cpp.
References uninitialized.
|
static |
Returns the smallest (by magnitude) normalized finite number in the given semantics.
| Negative | - True iff the number should be negative |
Definition at line 3437 of file APFloat.cpp.
References fcNormal, llvm::fltSemantics::minExponent, partCountForBits(), llvm::fltSemantics::precision, and uninitialized.
Referenced by llvm::InstCombiner::visitFCmpInst().
|
inlinestatic |
Factory for Positive and Negative Zero.
| Negative | True iff the number should be negative. |
Definition at line 213 of file APFloat.h.
References uninitialized.
Referenced by llvm::ExecutionEngine::getConstantValue(), llvm::ConstantFP::getNegativeZero(), llvm::Constant::getNullValue(), llvm::scalbn(), and llvm::X86TargetLowering::X86TargetLowering().
| bool APFloat::isDenormal | ( | ) | const |
IEEE-754R isSubnormal(): Returns true if and only if the float is a denormal.
Definition at line 703 of file APFloat.cpp.
References isFiniteNonZero(), llvm::fltSemantics::minExponent, llvm::fltSemantics::precision, and llvm::APInt::tcExtractBit().
Referenced by getExactInverse(), isNormal(), and next().
|
inline |
Returns true if and only if the current value is zero, subnormal, or normal.
This means that the value is not infinite or NaN.
Definition at line 411 of file APFloat.h.
References isInfinity(), and isNaN().
Referenced by fusedMultiplyAdd(), and isFiniteNonZero().
|
inline |
Definition at line 437 of file APFloat.h.
References isFinite(), and isZero().
Referenced by bitwiseIsEqual(), convert(), CvtFDivConstToReciprocal(), divide(), fusedMultiplyAdd(), getExactInverse(), llvm::hash_value(), isDenormal(), isFiniteNonZeroFp(), isLargest(), isNormal(), isSmallest(), mod(), multiply(), and roundToIntegral().
|
inline |
IEEE-754R isInfinite(): Returns true if and only if the float is infinity.
Definition at line 421 of file APFloat.h.
References fcInfinity.
Referenced by isFinite(), llvm::ConstantFP::isInfinity(), and llvm::scalbn().
| bool APFloat::isLargest | ( | ) | const |
Returns true if and only if the number has the largest possible finite magnitude in the current semantics.
Definition at line 763 of file APFloat.cpp.
References isFiniteNonZero(), and llvm::fltSemantics::maxExponent.
Referenced by next().
|
inline |
Returns true if and only if the float is a quiet or signaling NaN.
Definition at line 424 of file APFloat.h.
References fcNaN.
Referenced by llvm::InstCombiner::FoldFCmp_IntToFP_Cst(), llvm::hash_value(), isFinite(), llvm::ConstantFP::isNaN(), isSignaling(), llvm::maxnum(), llvm::minnum(), and llvm::scalbn().
|
inline |
IEEE-754R isSignMinus: Returns true if and only if the current value is negative.
This applies to zeros and NaNs as well.
Definition at line 399 of file APFloat.h.
Referenced by llvm::InstCombiner::FoldFCmp_IntToFP_Cst(), llvm::ConstantFP::isNegative(), isNegZero(), isPosZero(), next(), roundToIntegral(), llvm::scalbn(), and toString().
|
inline |
Definition at line 439 of file APFloat.h.
References isNegative(), and isZero().
Referenced by llvm::SystemZTargetLowering::isFPImmLegal().
|
inline |
|
inline |
IEEE-754R isNormal: Returns true if and only if the current value is normal.
This implies that the current value of the float is not zero, subnormal, infinite, or NaN following the definition of normality from IEEE-754R.
Definition at line 405 of file APFloat.h.
References isDenormal(), and isFiniteNonZero().
Referenced by isNormalFp().
|
inline |
Definition at line 438 of file APFloat.h.
References isNegative(), and isZero().
Referenced by llvm::InstCombiner::FoldFCmp_IntToFP_Cst(), llvm::AArch64TargetLowering::isFPImmLegal(), and LowerFCOPYSIGN().
| bool APFloat::isSignaling | ( | ) | const |
Returns true if and only if the float is a signaling NaN.
Definition at line 3783 of file APFloat.cpp.
References isNaN(), llvm::fltSemantics::precision, and llvm::APInt::tcExtractBit().
Referenced by next().
| bool APFloat::isSmallest | ( | ) | const |
Returns true if and only if the number has the smallest possible non-zero magnitude in the current semantics.
Definition at line 710 of file APFloat.cpp.
References isFiniteNonZero(), and llvm::fltSemantics::minExponent.
Referenced by next().
|
inline |
Returns true if and only if the float is plus or minus zero.
Definition at line 414 of file APFloat.h.
References fcZero.
Referenced by llvm::InstCombiner::FoldFCmp_IntToFP_Cst(), isFiniteNonZero(), llvm::SystemZTargetLowering::isFPImmLegal(), isNegZero(), isPosZero(), llvm::ConstantFP::isZero(), mod(), remainder(), llvm::scalbn(), llvm::InstCombiner::visitFCmpInst(), and llvm::InstCombiner::visitSub().
| APFloat::opStatus APFloat::mod | ( | const APFloat & | rhs, |
| roundingMode | rounding_mode | ||
| ) |
C fmod, or llvm frem.
Definition at line 1765 of file APFloat.cpp.
References convertFromZeroExtendedInteger(), convertToInteger(), divide(), llvm::integerPartWidth, isFiniteNonZero(), isZero(), multiply(), opDivByZero, opInexact, opInvalidOp, opOK, rmNearestTiesToEven, rmTowardZero, and subtract().
Referenced by llvm::ConstantFoldBinaryInstruction(), llvm::ExecutionEngine::getConstantValue(), and llvm::SelectionDAG::getNode().
| APFloat::opStatus APFloat::multiply | ( | const APFloat & | rhs, |
| roundingMode | rounding_mode | ||
| ) |
Definition at line 1690 of file APFloat.cpp.
References isFiniteNonZero(), llvm::lfExactlyZero, and opInexact.
Referenced by llvm::ConstantFoldBinaryInstruction(), llvm::ExecutionEngine::getConstantValue(), llvm::SelectionDAG::getNode(), mod(), operator*(), and remainder().
|
inline |
| APFloat::opStatus APFloat::next | ( | bool | nextDown | ) |
IEEE-754R 5.3.1: nextUp/nextDown.
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.
Definition at line 3796 of file APFloat.cpp.
References changeSign(), fcInfinity, fcNaN, fcNormal, fcZero, isDenormal(), isLargest(), isNegative(), isSignaling(), isSmallest(), llvm::fltSemantics::maxExponent, llvm::fltSemantics::minExponent, opInvalidOp, opOK, llvm::fltSemantics::precision, llvm::APInt::tcDecrement(), llvm::APInt::tcSet(), and llvm::APInt::tcSetBit().
Operator* overload which provides the default nmNearestTiesToEven rounding mode and no error checking.
Definition at line 323 of file APFloat.h.
References multiply(), and rmNearestTiesToEven.
Operator+ overload which provides the default nmNearestTiesToEven rounding mode and no error checking.
Definition at line 307 of file APFloat.h.
References add(), and rmNearestTiesToEven.
Operator- overload which provides the default nmNearestTiesToEven rounding mode and no error checking.
Definition at line 315 of file APFloat.h.
References rmNearestTiesToEven, and subtract().
Operator/ overload which provides the default nmNearestTiesToEven rounding mode and no error checking.
Definition at line 331 of file APFloat.h.
References divide(), and rmNearestTiesToEven.
Definition at line 675 of file APFloat.cpp.
Definition at line 689 of file APFloat.cpp.
References Bogus.
The definition of equality is not straightforward for floating point, so we won't use operator==.
Use one of the following, or write whatever it is you really mean.
| void APFloat::Profile | ( | FoldingSetNodeID & | NID | ) | const |
Used to insert APFloat objects, or objects that contain APFloat objects, into FoldingSets.
Definition at line 835 of file APFloat.cpp.
References llvm::FoldingSetNodeID::Add(), and bitcastToAPInt().
| APFloat::opStatus APFloat::remainder | ( | const APFloat & | rhs | ) |
IEEE remainder.
Definition at line 1728 of file APFloat.cpp.
References convertFromZeroExtendedInteger(), convertToInteger(), divide(), llvm::integerPartWidth, isZero(), multiply(), opDivByZero, opInexact, opInvalidOp, opOK, rmNearestTiesToEven, and subtract().
| APFloat::opStatus APFloat::roundToIntegral | ( | roundingMode | rounding_mode | ) |
Definition at line 1849 of file APFloat.cpp.
References add(), changeSign(), convertFromAPInt(), copySign(), isFiniteNonZero(), isNegative(), llvm::NextPowerOf2(), opInexact, opOK, rmNearestTiesToEven, semanticsPrecision(), and subtract().
Referenced by ConstantFoldScalarCall(), llvm::InstCombiner::FoldFCmp_IntToFP_Cst(), and llvm::SelectionDAG::getNode().
|
static |
Definition at line 846 of file APFloat.cpp.
References llvm::fltSemantics::precision.
Referenced by FoldIntToFPToInt(), and roundToIntegral().
| APFloat::opStatus APFloat::subtract | ( | const APFloat & | rhs, |
| roundingMode | rounding_mode | ||
| ) |
Definition at line 1683 of file APFloat.cpp.
Referenced by llvm::ConstantFoldBinaryInstruction(), llvm::ExecutionEngine::getConstantValue(), llvm::SelectionDAG::getNode(), mod(), operator-(), remainder(), and roundToIntegral().
| void APFloat::toString | ( | SmallVectorImpl< char > & | Str, |
| unsigned | FormatPrecision = 0, |
||
| unsigned | FormatMaxPadding = 3 |
||
| ) | const |
Converts this value into a decimal string.
| FormatPrecision | The maximum number of digits of precision to output. If there are fewer digits available, zero padding will not be used unless the value is integral and small enough to be expressed in FormatPrecision digits. 0 means to use the natural precision of the number. |
| FormatMaxPadding | The maximum number of zeros to consider inserting before falling back to scientific notation. 0 means to always use scientific notation. |
Number Precision MaxPadding Result
1.01E+4 5 2 10100 1.01E+4 4 2 1.01E+4 1.01E+4 5 1 1.01E+4 1.01E-2 5 2 0.0101 1.01E-2 4 2 0.0101 1.01E-2 4 1 1.01E-2
Definition at line 3551 of file APFloat.cpp.
References llvm::sys::path::append(), llvm::APInt::countTrailingZeros(), llvm::SmallVectorBase::empty(), fcInfinity, fcNaN, fcNormal, fcZero, llvm::APInt::getBitWidth(), llvm::APInt::getZExtValue(), I, isNegative(), llvm::APInt::lshr(), llvm::makeArrayRef(), partCountForBits(), llvm::fltSemantics::precision, llvm::SmallVectorTemplateBase< T, isPodLike >::push_back(), llvm::SmallVectorTemplateBase< T, isPodLike< T >::value >::push_back(), llvm::SmallVectorTemplateCommon< T >::size(), llvm::APInt::udivrem(), and llvm::APInt::zext().
Referenced by emitGlobalConstantFP(), and toStringAPFloat().
Overload to compute a hash code for an APFloat value.
Note that the use of hash codes for floating point values is in general frought with peril. Equality is hard to define for these values. For example, should negative and positive zero hash to different codes? Are they equal or not? This hash value implementation specifically emphasizes producing different codes for different inputs in order to be used in canonicalization and memoization. As such, equality is bitwiseIsEqual, and 0 != -0.
These additional declarations are required in order to compile LLVM with IBM xlC compiler.
|
static |
A Pseudo fltsemantic used to construct APFloats that cannot conflict with anything real.
Definition at line 140 of file APFloat.h.
Referenced by llvm::ConstantFoldCastInstruction(), llvm::DenseMapAPFloatKeyInfo::getEmptyKey(), llvm::DenseMapAPFloatKeyInfo::getTombstoneKey(), and operator=().
|
static |
Definition at line 133 of file APFloat.h.
Referenced by APFloat(), bitcastToAPInt(), llvm::X86TargetLowering::BuildFILD(), llvm::ConstantFoldCastInstruction(), convertToDouble(), emitDebugValueComment(), llvm::SelectionDAG::EVTToAPFloatSemantics(), ftostr(), llvm::ConstantFP::get(), getAllOnesValue(), llvm::ConstantDataSequential::getElementAsAPFloat(), llvm::Type::getFltSemantics(), llvm::SelectionDAG::getNode(), llvm::Constant::getNullValue(), getValueAsDouble(), llvm::ConstantFP::isValueValidForType(), LLVMConstRealGetDouble(), LookThroughFPExtensions(), LowerFCOPYSIGN(), llvm::ARMAsmPrinter::lowerOperand(), llvm::SDNode::print_details(), llvm::NVPTXFloatMCExpr::printImpl(), selectCCOpsAreFMaxCompatible(), TypeToFloatSemantics(), llvm::InstCombiner::visitFCmpInst(), and WriteConstantInternal().
|
static |
Definition at line 131 of file APFloat.h.
Referenced by bitcastToAPInt(), llvm::ConstantFoldCastInstruction(), ConstantFoldScalarCall(), llvm::SelectionDAG::EVTToAPFloatSemantics(), llvm::ConstantFP::get(), getAllOnesValue(), GetConstantFoldFPValue(), llvm::Type::getFltSemantics(), llvm::SelectionDAG::getNode(), llvm::Constant::getNullValue(), llvm::ConstantFP::isValueValidForType(), LookThroughFPExtensions(), TypeToFloatSemantics(), llvm::InstCombiner::visitFCmpInst(), and WriteConstantInternal().
|
static |
Definition at line 134 of file APFloat.h.
Referenced by bitcastToAPInt(), llvm::ConstantFoldCastInstruction(), llvm::SelectionDAG::EVTToAPFloatSemantics(), llvm::ConstantFP::get(), getAllOnesValue(), llvm::Type::getFltSemantics(), llvm::Constant::getNullValue(), llvm::ConstantFP::isValueValidForType(), TypeToFloatSemantics(), llvm::InstCombiner::visitFCmpInst(), and WriteConstantInternal().
|
static |
Definition at line 132 of file APFloat.h.
Referenced by APFloat(), bitcastToAPInt(), llvm::ConstantFoldCastInstruction(), convertToFloat(), llvm::SelectionDAG::EVTToAPFloatSemantics(), ftostr(), llvm::ConstantFP::get(), getAllOnesValue(), llvm::ConstantDataSequential::getElementAsAPFloat(), getF32Constant(), llvm::Type::getFltSemantics(), llvm::SelectionDAG::getNode(), llvm::Constant::getNullValue(), llvm::ConstantFP::isValueValidForType(), LookThroughFPExtensions(), LowerFCOPYSIGN(), lowerUINT_TO_FP_vXi32(), llvm::SDNode::print_details(), llvm::NVPTXFloatMCExpr::printImpl(), TypeToFloatSemantics(), valueHasFloatPrecision(), llvm::InstCombiner::visitFCmpInst(), and WriteConstantInternal().
|
static |
Definition at line 135 of file APFloat.h.
Referenced by bitcastToAPInt(), llvm::ConstantFoldCastInstruction(), llvm::SelectionDAG::EVTToAPFloatSemantics(), llvm::ConstantFP::get(), getAllOnesValue(), llvm::Type::getFltSemantics(), llvm::Constant::getNullValue(), llvm::ConstantFP::isValueValidForType(), TypeToFloatSemantics(), llvm::InstCombiner::visitFCmpInst(), and WriteConstantInternal().
|
static |
Definition at line 136 of file APFloat.h.
Referenced by bitcastToAPInt(), llvm::ConstantFoldCastInstruction(), convert(), llvm::SelectionDAG::EVTToAPFloatSemantics(), llvm::ConstantFP::get(), getAllOnesValue(), llvm::ExecutionEngine::getConstantValue(), llvm::Type::getFltSemantics(), llvm::Constant::getNullValue(), llvm::ConstantFP::isValueValidForType(), toStringAPFloat(), TypeToFloatSemantics(), llvm::InstCombiner::visitFCmpInst(), WriteConstantInternal(), and llvm::X86TargetLowering::X86TargetLowering().
1.8.6