LLVM  8.0.1
Public Types | Static Public Member Functions | Static Public Attributes | List of all members
llvm::APFloatBase Struct Reference

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

#include "llvm/ADT/APFloat.h"

Inheritance diagram for llvm::APFloatBase:
Inheritance graph
[legend]
Collaboration diagram for llvm::APFloatBase:
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
}
 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 APInt::WordType integerPart
 
typedef signed short ExponentType
 A signed type to represent a floating point numbers unbiased exponent. More...
 

Static Public Member Functions

static unsigned int semanticsPrecision (const fltSemantics &)
 
static ExponentType semanticsMinExponent (const fltSemantics &)
 
static ExponentType semanticsMaxExponent (const fltSemantics &)
 
static unsigned int semanticsSizeInBits (const fltSemantics &)
 
static unsigned getSizeInBits (const fltSemantics &Sem)
 Returns the size of the floating point number (in bits) in the given semantics. More...
 
Floating Point Semantics.
static const fltSemanticsIEEEhalf () LLVM_READNONE
 
static const fltSemanticsIEEEsingle () LLVM_READNONE
 
static const fltSemanticsIEEEdouble () LLVM_READNONE
 
static const fltSemanticsIEEEquad () LLVM_READNONE
 
static const fltSemanticsPPCDoubleDouble () LLVM_READNONE
 
static const fltSemanticsx87DoubleExtended () LLVM_READNONE
 
static const fltSemanticsBogus () LLVM_READNONE
 A Pseudo fltsemantic used to construct APFloats that cannot conflict with anything real. More...
 

Static Public Attributes

static const unsigned integerPartWidth = APInt::APINT_BITS_PER_WORD
 

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

Member Typedef Documentation

◆ ExponentType

typedef signed short llvm::APFloatBase::ExponentType

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

Definition at line 147 of file APFloat.h.

◆ integerPart

Definition at line 143 of file APFloat.h.

Member Enumeration Documentation

◆ cmpResult

IEEE-754R 5.11: Floating Point Comparison Relations.

Enumerator
cmpLessThan 
cmpEqual 
cmpGreaterThan 
cmpUnordered 

Definition at line 166 of file APFloat.h.

◆ fltCategory

Category of internally-represented number.

Enumerator
fcInfinity 
fcNaN 
fcNormal 
fcZero 

Definition at line 195 of file APFloat.h.

◆ IlogbErrorKinds

Enumeration of ilogb error results.

Enumerator
IEK_Zero 
IEK_NaN 
IEK_Inf 

Definition at line 208 of file APFloat.h.

◆ opStatus

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

◆ roundingMode

IEEE-754R 4.3: Rounding-direction attributes.

Enumerator
rmNearestTiesToEven 
rmTowardPositive 
rmTowardNegative 
rmTowardZero 
rmNearestTiesToAway 

Definition at line 174 of file APFloat.h.

◆ uninitializedTag

Convenience enum used to construct an uninitialized APFloat.

Enumerator
uninitialized 

Definition at line 203 of file APFloat.h.

Member Function Documentation

◆ Bogus()

const fltSemantics & llvm::APFloatBase::Bogus ( )
static

A Pseudo fltsemantic used to construct APFloats that cannot conflict with anything real.

Definition at line 132 of file APFloat.cpp.

References llvm::semBogus.

Referenced by llvm::ConstantFoldCastInstruction(), llvm::DenseMapAPFloatKeyInfo::getEmptyKey(), and llvm::DenseMapAPFloatKeyInfo::getTombstoneKey().

◆ getSizeInBits()

unsigned llvm::APFloatBase::getSizeInBits ( const fltSemantics Sem)
static

Returns the size of the floating point number (in bits) in the given semantics.

Definition at line 170 of file APFloat.cpp.

References llvm::fltSemantics::sizeInBits.

◆ IEEEdouble()

const fltSemantics & llvm::APFloatBase::IEEEdouble ( )
static

◆ IEEEhalf()

const fltSemantics & llvm::APFloatBase::IEEEhalf ( )
static

◆ IEEEquad()

const fltSemantics & llvm::APFloatBase::IEEEquad ( )
static

◆ IEEEsingle()

const fltSemantics & llvm::APFloatBase::IEEEsingle ( )
static

◆ PPCDoubleDouble()

const fltSemantics & llvm::APFloatBase::PPCDoubleDouble ( )
static

◆ semanticsMaxExponent()

APFloatBase::ExponentType llvm::APFloatBase::semanticsMaxExponent ( const fltSemantics semantics)
static

Definition at line 159 of file APFloat.cpp.

References llvm::fltSemantics::maxExponent.

Referenced by llvm::FunctionComparator::cmpAPFloats().

◆ semanticsMinExponent()

APFloatBase::ExponentType llvm::APFloatBase::semanticsMinExponent ( const fltSemantics semantics)
static

Definition at line 163 of file APFloat.cpp.

References llvm::fltSemantics::minExponent.

Referenced by llvm::FunctionComparator::cmpAPFloats().

◆ semanticsPrecision()

unsigned int llvm::APFloatBase::semanticsPrecision ( const fltSemantics semantics)
static

◆ semanticsSizeInBits()

unsigned int llvm::APFloatBase::semanticsSizeInBits ( const fltSemantics semantics)
static

Definition at line 166 of file APFloat.cpp.

References llvm::fltSemantics::sizeInBits.

Referenced by llvm::FunctionComparator::cmpAPFloats().

◆ x87DoubleExtended()

const fltSemantics & llvm::APFloatBase::x87DoubleExtended ( )
static

Member Data Documentation

◆ integerPartWidth

const unsigned llvm::APFloatBase::integerPartWidth = APInt::APINT_BITS_PER_WORD
static

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