LLVM API Documentation

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
Classes | Public Types | Public Member Functions | Static Public Member Functions | Friends | List of all members
llvm::APFloat Class Reference

A self-contained host- and target-independent arbitrary-precision floating-point software implementation. More...

#include <APFloat.h>

Collaboration diagram for llvm::APFloat:
Collaboration graph
[legend]

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
}
 
enum  fltCategory { fcInfinity, fcNaN, fcNormal, fcZero }
 Category of internally-represented number. More...
 
enum  uninitializedTag { uninitialized }
 Convenience enum used to construct an uninitialized APFloat. 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
 
void Emit (Serializer &S) const
 Used by the Bitcode serializer to emit APInts to Bitcode. More...
 
bool operator== (const APFloat &) const LLVM_DELETED_FUNCTION
 
cmpResult compare (const APFloat &) const
 
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
 
APFloatoperator= (const APFloat &)
 
void toString (SmallVectorImpl< char > &Str, unsigned FormatPrecision=0, unsigned FormatMaxPadding=3) const
 
bool getExactInverse (APFloat *inv) const
 
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 ()
 
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...
 
Sign operations.
void changeSign ()
 
void clearSign ()
 
void copySign (const APFloat &)
 
Conversions
opStatus convert (const fltSemantics &, roundingMode, bool *)
 
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
 
bool isNormal () const
 
bool isFinite () const
 
bool isZero () const
 Returns true if and only if the float is plus or minus zero. More...
 
bool isDenormal () const
 
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 &)
 
static APFloat ReadVal (Deserializer &D)
 Used by the Bitcode deserializer to deserialize APInts. More...
 
Convenience "constructors"
static APFloat getZero (const fltSemantics &Sem, bool Negative=false)
 
static APFloat getInf (const fltSemantics &Sem, bool Negative=false)
 
static APFloat getNaN (const fltSemantics &Sem, bool Negative=false, unsigned type=0)
 
static APFloat getQNaN (const fltSemantics &Sem, bool Negative=false, const APInt *payload=0)
 Factory for QNaN values. More...
 
static APFloat getSNaN (const fltSemantics &Sem, bool Negative=false, const APInt *payload=0)
 Factory for SNaN values. More...
 
static APFloat getLargest (const fltSemantics &Sem, bool Negative=false)
 
static APFloat getSmallest (const fltSemantics &Sem, bool Negative=false)
 
static APFloat getSmallestNormalized (const fltSemantics &Sem, bool Negative=false)
 
static APFloat getAllOnesValue (unsigned BitWidth, bool isIEEE=false)
 

Static Public Attributes

Floating Point Semantics.
static const fltSemantics IEEEhalf = { 15, -14, 11 }
 
static const fltSemantics IEEEsingle = { 127, -126, 24 }
 
static const fltSemantics IEEEdouble = { 1023, -1022, 53 }
 
static const fltSemantics IEEEquad = { 16383, -16382, 113 }
 
static const fltSemantics PPCDoubleDouble = { 1023, -1022 + 53, 53 + 53 }
 
static const fltSemantics x87DoubleExtended = { 16383, -16382, 64 }
 
static const fltSemantics Bogus = { 0, 0, 0 }
 

Friends

hash_code hash_value (const APFloat &Arg)
 Overload to compute a hash code for an APFloat value. More...
 

Simple Queries

fltCategory getCategory () const
 
const fltSemanticsgetSemantics () const
 
bool isNonZero () const
 
bool isFiniteNonZero () const
 
bool isPosZero () const
 
bool isNegZero () const
 
bool isSmallest () const
 
bool isLargest () const
 

Detailed Description

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.

TODO

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.

Definition at line 122 of file APFloat.h.

Member Typedef Documentation

typedef signed short llvm::APFloat::ExponentType

A signed type to represent a floating point numbers unbiased exponent.

Definition at line 126 of file APFloat.h.

Member Enumeration Documentation

IEEE-754R 5.11: Floating Point Comparison Relations.

Enumerator
cmpLessThan 
cmpEqual 
cmpGreaterThan 
cmpUnordered 

Definition at line 147 of file APFloat.h.

Category of internally-represented number.

Enumerator
fcInfinity 
fcNaN 
fcNormal 
fcZero 

Definition at line 176 of file APFloat.h.

IEEE-754R 7: Default exception handling.

opUnderflow or opOverflow are always returned or-ed with opInexact.

Enumerator
opOK 
opInvalidOp 
opDivByZero 
opOverflow 
opUnderflow 
opInexact 

Definition at line 166 of file APFloat.h.

IEEE-754R 4.3: Rounding-direction attributes.

Enumerator
rmNearestTiesToEven 
rmTowardPositive 
rmTowardNegative 
rmTowardZero 
rmNearestTiesToAway 

Definition at line 155 of file APFloat.h.

Convenience enum used to construct an uninitialized APFloat.

Enumerator
uninitialized 

Definition at line 184 of file APFloat.h.

Constructor & Destructor Documentation

APFloat::APFloat ( const fltSemantics ourSemantics)

Definition at line 788 of file APFloat.cpp.

References fcZero.

Referenced by getAllOnesValue().

APFloat::APFloat ( const fltSemantics ourSemantics,
StringRef  text 
)

Definition at line 799 of file APFloat.cpp.

References convertFromString(), and rmNearestTiesToEven.

APFloat::APFloat ( const fltSemantics ourSemantics,
integerPart  value 
)
APFloat::APFloat ( const fltSemantics ourSemantics,
uninitializedTag  tag 
)

Definition at line 794 of file APFloat.cpp.

APFloat::APFloat ( const fltSemantics Sem,
const APInt API 
)

Definition at line 3415 of file APFloat.cpp.

APFloat::APFloat ( double  d)
explicit

Definition at line 3423 of file APFloat.cpp.

References llvm::APInt::doubleToBits(), and IEEEdouble.

APFloat::APFloat ( float  f)
explicit

Definition at line 3419 of file APFloat.cpp.

References llvm::APInt::floatToBits(), and IEEEsingle.

APFloat::APFloat ( const APFloat rhs)

Definition at line 804 of file APFloat.cpp.

APFloat::~APFloat ( )

Definition at line 809 of file APFloat.cpp.

Member Function Documentation

APFloat::opStatus APFloat::add ( const APFloat rhs,
roundingMode  rounding_mode 
)
APInt APFloat::bitcastToAPInt ( ) const
bool APFloat::bitwiseIsEqual ( const APFloat rhs) const

Bitwise comparison for equality (QNaNs compare equal, 0!=-0).

Definition at line 755 of file APFloat.cpp.

References fcInfinity, fcZero, and isFiniteNonZero().

Referenced by llvm::ConstantFP::isExactlyValue(), llvm::X86TargetLowering::isFPImmLegal(), and llvm::DenseMapAPFloatKeyInfo::KeyTy::operator==().

void APFloat::changeSign ( )
void APFloat::clearSign ( )

Definition at line 1596 of file APFloat.cpp.

Referenced by llvm::SelectionDAG::getNode(), 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 1859 of file APFloat.cpp.

References cmpEqual, cmpGreaterThan, cmpLessThan, cmpUnordered, fcInfinity, fcNaN, fcNormal, fcZero, llvm_unreachable, and PackCategoriesIntoKey.

Referenced by llvm::ConstantFoldCompareInstruction(), llvm::MDNode::getMostGenericFPMath(), and llvm::InstCombiner::visitFCmpInst().

APFloat::opStatus APFloat::convert ( const fltSemantics toSemantics,
roundingMode  rounding_mode,
bool losesInfo 
)
APFloat::opStatus APFloat::convertFromAPInt ( const APInt Val,
bool  isSigned,
roundingMode  rounding_mode 
)
APFloat::opStatus APFloat::convertFromSignExtendedInteger ( const integerPart src,
unsigned int  srcCount,
bool  isSigned,
roundingMode  rounding_mode 
)
APFloat::opStatus APFloat::convertFromString ( StringRef  str,
roundingMode  rounding_mode 
)

Definition at line 2611 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 
)
double APFloat::convertToDouble ( ) const
float APFloat::convertToFloat ( ) const
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 2663 of file APFloat.cpp.

References fcInfinity, fcNaN, fcNormal, fcZero, infinityL, infinityU, llvm::Intrinsic::memcpy, llvm::Intrinsic::memset, NaNL, and NaNU.

APFloat::opStatus APFloat::convertToInteger ( integerPart parts,
unsigned int  width,
bool  isSigned,
roundingMode  rounding_mode,
bool isExact 
) const
APFloat::opStatus APFloat::convertToInteger ( APSInt result,
roundingMode  rounding_mode,
bool isExact 
) const
void APFloat::copySign ( const APFloat rhs)

Definition at line 1603 of file APFloat.cpp.

Referenced by llvm::SelectionDAG::getNode(), and roundToIntegral().

APFloat::opStatus APFloat::divide ( const APFloat rhs,
roundingMode  rounding_mode 
)
void llvm::APFloat::Emit ( Serializer &  S) const

Used by the Bitcode serializer to emit APInts to Bitcode.

APFloat::opStatus APFloat::fusedMultiplyAdd ( const APFloat multiplicand,
const APFloat addend,
roundingMode  rounding_mode 
)
APFloat APFloat::getAllOnesValue ( unsigned  BitWidth,
bool  isIEEE = false 
)
static

Returns a float which is bitcasted from an all one value int.

Parameters
BitWidth- Select float type
isIEEE- If 128 bit number, select between PPC and IEEE

Definition at line 3320 of file APFloat.cpp.

References APFloat(), llvm::APInt::getAllOnesValue(), IEEEdouble, IEEEhalf, IEEEquad, IEEEsingle, llvm_unreachable, PPCDoubleDouble, and x87DoubleExtended.

Referenced by llvm::Constant::getAllOnesValue().

fltCategory llvm::APFloat::getCategory ( ) const
inline

Definition at line 396 of file APFloat.h.

bool APFloat::getExactInverse ( APFloat inv) const

If this value has an exact multiplicative inverse, store it in inv and return true.

Definition at line 3714 of file APFloat.cpp.

References divide(), isDenormal(), isFiniteNonZero(), opOK, llvm::fltSemantics::precision, and rmNearestTiesToEven.

Referenced by CvtFDivConstToReciprocal().

static APFloat llvm::APFloat::getInf ( const fltSemantics Sem,
bool  Negative = false 
)
inlinestatic

Factory for Positive and Negative Infinity.

Parameters
NegativeTrue iff the number should be negative.

Definition at line 221 of file APFloat.h.

References uninitialized.

Referenced by llvm::ConstantFP::getInfinity().

APFloat APFloat::getLargest ( const fltSemantics Sem,
bool  Negative = false 
)
static

Returns the largest finite number in the given semantics.

Parameters
Negative- True iff the number should be negative

Definition at line 3377 of file APFloat.cpp.

References uninitialized.

static APFloat llvm::APFloat::getNaN ( const fltSemantics Sem,
bool  Negative = false,
unsigned  type = 0 
)
inlinestatic

Factory for QNaN values.

Parameters
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 232 of file APFloat.h.

References getQNaN().

static APFloat llvm::APFloat::getQNaN ( const fltSemantics Sem,
bool  Negative = false,
const APInt payload = 0 
)
inlinestatic

Factory for QNaN values.

Definition at line 243 of file APFloat.h.

Referenced by getNaN().

const fltSemantics& llvm::APFloat::getSemantics ( ) const
inline
APFloat APFloat::getSmallest ( const fltSemantics Sem,
bool  Negative = false 
)
static

Returns the smallest (by magnitude) finite number in the given semantics. Might be denormalized, which implies a relative loss of precision.

Parameters
Negative- True iff the number should be negative

Definition at line 3387 of file APFloat.cpp.

References uninitialized.

APFloat APFloat::getSmallestNormalized ( const fltSemantics Sem,
bool  Negative = false 
)
static

Returns the smallest (by magnitude) normalized finite number in the given semantics.

Parameters
Negative- True iff the number should be negative

Definition at line 3397 of file APFloat.cpp.

References fcNormal, llvm::fltSemantics::minExponent, partCountForBits(), llvm::fltSemantics::precision, and uninitialized.

Referenced by llvm::InstCombiner::visitFCmpInst().

static APFloat llvm::APFloat::getSNaN ( const fltSemantics Sem,
bool  Negative = false,
const APInt payload = 0 
)
inlinestatic

Factory for SNaN values.

Definition at line 249 of file APFloat.h.

static APFloat llvm::APFloat::getZero ( const fltSemantics Sem,
bool  Negative = false 
)
inlinestatic

Factory for Positive and Negative Zero.

Parameters
NegativeTrue iff the number should be negative.

Definition at line 212 of file APFloat.h.

References uninitialized.

Referenced by llvm::ExecutionEngine::getConstantValue(), llvm::Constant::getNullValue(), and llvm::X86TargetLowering::resetOperationActions().

bool APFloat::isDenormal ( ) const

IEEE-754R isSubnormal(): Returns true if and only if the float is a denormal.

Definition at line 687 of file APFloat.cpp.

References isFiniteNonZero(), llvm::fltSemantics::minExponent, llvm::fltSemantics::precision, and llvm::APInt::tcExtractBit().

Referenced by getExactInverse(), isNormal(), and next().

bool llvm::APFloat::isFinite ( ) const
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 373 of file APFloat.h.

References isInfinity(), and isNaN().

Referenced by isFiniteNonZero().

bool llvm::APFloat::isFiniteNonZero ( ) const
inline
bool llvm::APFloat::isInfinity ( ) const
inline

IEEE-754R isInfinite(): Returns true if and only if the float is infinity.

Definition at line 383 of file APFloat.h.

References fcInfinity.

Referenced by isFinite().

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 747 of file APFloat.cpp.

References isFiniteNonZero(), and llvm::fltSemantics::maxExponent.

Referenced by next().

bool llvm::APFloat::isNaN ( ) const
inline

Returns true if and only if the float is a quiet or signaling NaN.

Definition at line 386 of file APFloat.h.

References fcNaN.

Referenced by llvm::InstCombiner::FoldFCmp_IntToFP_Cst(), llvm::hash_value(), isFinite(), llvm::ConstantFP::isNaN(), and isSignaling().

bool llvm::APFloat::isNegative ( ) const
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 361 of file APFloat.h.

Referenced by llvm::InstCombiner::FoldFCmp_IntToFP_Cst(), llvm::A64Imms::isFPImm(), llvm::ConstantFP::isNegative(), isNegZero(), isPosZero(), next(), roundToIntegral(), and toString().

bool llvm::APFloat::isNegZero ( ) const
inline

Definition at line 401 of file APFloat.h.

References isNegative(), and isZero().

Referenced by llvm::SystemZTargetLowering::isFPImmLegal().

bool llvm::APFloat::isNonZero ( ) const
inline

Definition at line 398 of file APFloat.h.

References fcZero.

bool llvm::APFloat::isNormal ( ) const
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 367 of file APFloat.h.

References isDenormal(), and isFiniteNonZero().

Referenced by isNormalFp(), and llvm::InstCombiner::visitFDiv().

bool llvm::APFloat::isPosZero ( ) const
inline

Definition at line 400 of file APFloat.h.

References isNegative(), and isZero().

bool APFloat::isSignaling ( ) const

Returns true if and only if the float is a signaling NaN.

Definition at line 3743 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 694 of file APFloat.cpp.

References isFiniteNonZero(), and llvm::fltSemantics::minExponent.

Referenced by next().

bool llvm::APFloat::isZero ( ) const
inline
APFloat::opStatus APFloat::mod ( const APFloat rhs,
roundingMode  rounding_mode 
)
APFloat::opStatus APFloat::multiply ( const APFloat rhs,
roundingMode  rounding_mode 
)
bool llvm::APFloat::needsCleanup ( ) const
inline

Returns whether this instance allocated memory.

Definition at line 204 of file APFloat.h.

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 3756 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().

APFloat & APFloat::operator= ( const APFloat rhs)

Definition at line 673 of file APFloat.cpp.

bool llvm::APFloat::operator== ( const APFloat ) const

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 815 of file APFloat.cpp.

References llvm::FoldingSetNodeID::Add(), and bitcastToAPInt().

static APFloat llvm::APFloat::ReadVal ( Deserializer &  D)
static

Used by the Bitcode deserializer to deserialize APInts.

APFloat::opStatus APFloat::remainder ( const APFloat rhs)
APFloat::opStatus APFloat::roundToIntegral ( roundingMode  rounding_mode)
unsigned int APFloat::semanticsPrecision ( const fltSemantics semantics)
static

Definition at line 826 of file APFloat.cpp.

References llvm::fltSemantics::precision.

Referenced by llvm::A64Imms::isFPImm(), and roundToIntegral().

APFloat::opStatus APFloat::subtract ( const APFloat rhs,
roundingMode  rounding_mode 
)
void APFloat::toString ( SmallVectorImpl< char > &  Str,
unsigned  FormatPrecision = 0,
unsigned  FormatMaxPadding = 3 
) const

Converts this value into a decimal string.

Parameters
FormatPrecisionThe 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.
FormatMaxPaddingThe 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 3511 of file APFloat.cpp.

References llvm::sys::path::append(), llvm::APInt::countTrailingZeros(), llvm::SmallVectorBase::empty(), llvm::Intrinsic::exp, 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< T >::value >::push_back(), llvm::SmallVectorTemplateBase< T, isPodLike >::push_back(), llvm::SmallVectorTemplateCommon< T >::size(), llvm::APInt::udivrem(), and llvm::APInt::zext().

Referenced by emitGlobalConstantFP().

Friends And Related Function Documentation

hash_code hash_value ( const APFloat Arg)
friend

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.

See friend declaration above.

This additional declaration is required in order to compile LLVM with IBM xlC compiler.

Member Data Documentation

const fltSemantics llvm::APFloat::Bogus = { 0, 0, 0 }
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(), and llvm::DenseMapAPFloatKeyInfo::getTombstoneKey().

const fltSemantics llvm::APFloat::IEEEdouble = { 1023, -1022, 53 }
static
const fltSemantics llvm::APFloat::IEEEhalf = { 15, -14, 11 }
static
const fltSemantics llvm::APFloat::IEEEquad = { 16383, -16382, 113 }
static
const fltSemantics llvm::APFloat::IEEEsingle = { 127, -126, 24 }
static
const fltSemantics llvm::APFloat::PPCDoubleDouble = { 1023, -1022 + 53, 53 + 53 }
static
const fltSemantics llvm::APFloat::x87DoubleExtended = { 16383, -16382, 64 }
static

The documentation for this class was generated from the following files: