class IEEEFloat

Declaration

class IEEEFloat : public APFloatBase { /* full declaration omitted */ };

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.

Declared at: llvm/include/llvm/ADT/APFloat.h:242

Inherits from: APFloatBase

Member Variables

Inherited from APFloatBase:

public static integerPartWidth = APInt::APINT_BITS_PER_WORD

Method Overview

  • public IEEEFloat(const llvm::fltSemantics &, llvm::APFloatBase::integerPart)
  • public IEEEFloat(const llvm::fltSemantics &, llvm::APFloatBase::uninitializedTag)
  • public IEEEFloat(const llvm::fltSemantics &, const llvm::APInt &)
  • public IEEEFloat(double d)
  • public IEEEFloat(float f)
  • public IEEEFloat(const llvm::detail::IEEEFloat &)
  • public IEEEFloat(llvm::detail::IEEEFloat &&)
  • public IEEEFloat(const llvm::fltSemantics &)
  • public llvm::APFloatBase::opStatus add(const llvm::detail::IEEEFloat &, llvm::APFloatBase::roundingMode)
  • public llvm::APInt bitcastToAPInt() const
  • public bool bitwiseIsEqual(const llvm::detail::IEEEFloat &) const
  • public void changeSign()
  • public llvm::APFloatBase::cmpResult compare(const llvm::detail::IEEEFloat &) const
  • public llvm::APFloatBase::cmpResult compareAbsoluteValue(const llvm::detail::IEEEFloat &) const
  • public llvm::APFloatBase::opStatus convert(const llvm::fltSemantics &, llvm::APFloatBase::roundingMode, bool *)
  • public llvm::APFloatBase::opStatus convertFromAPInt(const llvm::APInt &, bool, llvm::APFloatBase::roundingMode)
  • public llvm::APFloatBase::opStatus convertFromSignExtendedInteger(const llvm::APFloatBase::integerPart *, unsigned int, bool, llvm::APFloatBase::roundingMode)
  • public Expected<llvm::APFloatBase::opStatus> convertFromString(llvm::StringRef, llvm::APFloatBase::roundingMode)
  • public llvm::APFloatBase::opStatus convertFromZeroExtendedInteger(const llvm::APFloatBase::integerPart *, unsigned int, bool, llvm::APFloatBase::roundingMode)
  • public double convertToDouble() const
  • public float convertToFloat() const
  • public unsigned int convertToHexString(char * dst, unsigned int hexDigits, bool upperCase, llvm::APFloatBase::roundingMode) const
  • public llvm::APFloatBase::opStatus convertToInteger(MutableArrayRef<llvm::APFloatBase::integerPart>, unsigned int, bool, llvm::APFloatBase::roundingMode, bool *) const
  • public llvm::APFloatBase::opStatus divide(const llvm::detail::IEEEFloat &, llvm::APFloatBase::roundingMode)
  • public llvm::APFloatBase::opStatus fusedMultiplyAdd(const llvm::detail::IEEEFloat &, const llvm::detail::IEEEFloat &, llvm::APFloatBase::roundingMode)
  • public llvm::APFloatBase::fltCategory getCategory() const
  • public bool getExactInverse(llvm::APFloat * inv) const
  • public const llvm::fltSemantics & getSemantics() const
  • public bool isDenormal() const
  • public bool isFinite() const
  • public bool isFiniteNonZero() const
  • public bool isInfinity() const
  • public bool isInteger() const
  • public bool isLargest() const
  • public bool isNaN() const
  • public bool isNegZero() const
  • public bool isNegative() const
  • public bool isNonZero() const
  • public bool isNormal() const
  • public bool isPosZero() const
  • public bool isSignaling() const
  • public bool isSmallest() const
  • public bool isZero() const
  • public void makeInf(bool Neg = false)
  • public void makeLargest(bool Neg = false)
  • public void makeNaN(bool SNaN = false, bool Neg = false, const llvm::APInt * fill = nullptr)
  • public void makeQuiet()
  • public void makeSmallest(bool Neg = false)
  • public void makeSmallestNormalized(bool Negative = false)
  • public void makeZero(bool Neg = false)
  • public llvm::APFloatBase::opStatus mod(const llvm::detail::IEEEFloat &)
  • public llvm::APFloatBase::opStatus multiply(const llvm::detail::IEEEFloat &, llvm::APFloatBase::roundingMode)
  • public bool needsCleanup() const
  • public llvm::APFloatBase::opStatus next(bool nextDown)
  • public llvm::APFloatBase::opStatus remainder(const llvm::detail::IEEEFloat &)
  • public llvm::APFloatBase::opStatus roundToIntegral(llvm::APFloatBase::roundingMode)
  • public llvm::APFloatBase::opStatus subtract(const llvm::detail::IEEEFloat &, llvm::APFloatBase::roundingMode)
  • public void toString(SmallVectorImpl<char> & Str, unsigned int FormatPrecision = 0, unsigned int FormatMaxPadding = 3, bool TruncateZero = true) const
  • public ~IEEEFloat()

Inherited from APFloatBase:

Methods

IEEEFloat(const llvm::fltSemantics&,
          llvm::APFloatBase::integerPart)

Declared at: llvm/include/llvm/ADT/APFloat.h:248

Parameters

const llvm::fltSemantics&
llvm::APFloatBase::integerPart

IEEEFloat(const llvm::fltSemantics&,
          llvm::APFloatBase::uninitializedTag)

Declared at: llvm/include/llvm/ADT/APFloat.h:249

Parameters

const llvm::fltSemantics&
llvm::APFloatBase::uninitializedTag

IEEEFloat(const llvm::fltSemantics&,
          const llvm::APInt&)

Declared at: llvm/include/llvm/ADT/APFloat.h:250

Parameters

const llvm::fltSemantics&
const llvm::APInt&

IEEEFloat(double d)

Declared at: llvm/include/llvm/ADT/APFloat.h:251

Parameters

double d

IEEEFloat(float f)

Declared at: llvm/include/llvm/ADT/APFloat.h:252

Parameters

float f

IEEEFloat(const llvm::detail::IEEEFloat&)

Declared at: llvm/include/llvm/ADT/APFloat.h:253

Parameters

const llvm::detail::IEEEFloat&

IEEEFloat(llvm::detail::IEEEFloat&&)

Declared at: llvm/include/llvm/ADT/APFloat.h:254

Parameters

llvm::detail::IEEEFloat&&

IEEEFloat(const llvm::fltSemantics&)

Description

@ {

Declared at: llvm/include/llvm/ADT/APFloat.h:247

Parameters

const llvm::fltSemantics&

llvm::APFloatBase::opStatus add(
    const llvm::detail::IEEEFloat&,
    llvm::APFloatBase::roundingMode)

Description

@ {

Declared at: llvm/include/llvm/ADT/APFloat.h:270

Parameters

const llvm::detail::IEEEFloat&
llvm::APFloatBase::roundingMode

llvm::APInt bitcastToAPInt() const

Declared at: llvm/include/llvm/ADT/APFloat.h:304

bool bitwiseIsEqual(
    const llvm::detail::IEEEFloat&) const

Description

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

Declared at: llvm/include/llvm/ADT/APFloat.h:320

Parameters

const llvm::detail::IEEEFloat&

void changeSign()

Description

@ {

Declared at: llvm/include/llvm/ADT/APFloat.h:288

llvm::APFloatBase::cmpResult compare(
    const llvm::detail::IEEEFloat&) const

Description

IEEE comparison with another floating point number (NaNs compare unordered, 0==-0).

Declared at: llvm/include/llvm/ADT/APFloat.h:317

Parameters

const llvm::detail::IEEEFloat&

llvm::APFloatBase::cmpResult compareAbsoluteValue(
    const llvm::detail::IEEEFloat&) const

Description

@ }

Declared at: llvm/include/llvm/ADT/APFloat.h:472

Parameters

const llvm::detail::IEEEFloat&

llvm::APFloatBase::opStatus convert(
    const llvm::fltSemantics&,
    llvm::APFloatBase::roundingMode,
    bool*)

Description

@ {

Declared at: llvm/include/llvm/ADT/APFloat.h:295

Parameters

const llvm::fltSemantics&
llvm::APFloatBase::roundingMode
bool*

llvm::APFloatBase::opStatus convertFromAPInt(
    const llvm::APInt&,
    bool,
    llvm::APFloatBase::roundingMode)

Declared at: llvm/include/llvm/ADT/APFloat.h:298

Parameters

const llvm::APInt&
bool
llvm::APFloatBase::roundingMode

llvm::APFloatBase::opStatus
convertFromSignExtendedInteger(
    const llvm::APFloatBase::integerPart*,
    unsigned int,
    bool,
    llvm::APFloatBase::roundingMode)

Declared at: llvm/include/llvm/ADT/APFloat.h:299

Parameters

const llvm::APFloatBase::integerPart*
unsigned int
bool
llvm::APFloatBase::roundingMode

Expected<llvm::APFloatBase::opStatus>
convertFromString(llvm::StringRef,
                  llvm::APFloatBase::roundingMode)

Declared at: llvm/include/llvm/ADT/APFloat.h:303

Parameters

llvm::StringRef
llvm::APFloatBase::roundingMode

llvm::APFloatBase::opStatus
convertFromZeroExtendedInteger(
    const llvm::APFloatBase::integerPart*,
    unsigned int,
    bool,
    llvm::APFloatBase::roundingMode)

Declared at: llvm/include/llvm/ADT/APFloat.h:301

Parameters

const llvm::APFloatBase::integerPart*
unsigned int
bool
llvm::APFloatBase::roundingMode

double convertToDouble() const

Declared at: llvm/include/llvm/ADT/APFloat.h:305

float convertToFloat() const

Declared at: llvm/include/llvm/ADT/APFloat.h:306

unsigned int convertToHexString(
    char* dst,
    unsigned int hexDigits,
    bool upperCase,
    llvm::APFloatBase::roundingMode) const

Description

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.

Declared at: llvm/include/llvm/ADT/APFloat.h:325

Parameters

char* dst
unsigned int hexDigits
bool upperCase
llvm::APFloatBase::roundingMode

llvm::APFloatBase::opStatus convertToInteger(
    MutableArrayRef<
        llvm::APFloatBase::integerPart>,
    unsigned int,
    bool,
    llvm::APFloatBase::roundingMode,
    bool*) const

Declared at: llvm/include/llvm/ADT/APFloat.h:296

Parameters

MutableArrayRef<llvm::APFloatBase::integerPart>
unsigned int
bool
llvm::APFloatBase::roundingMode
bool*

llvm::APFloatBase::opStatus divide(
    const llvm::detail::IEEEFloat&,
    llvm::APFloatBase::roundingMode)

Declared at: llvm/include/llvm/ADT/APFloat.h:273

Parameters

const llvm::detail::IEEEFloat&
llvm::APFloatBase::roundingMode

llvm::APFloatBase::opStatus fusedMultiplyAdd(
    const llvm::detail::IEEEFloat&,
    const llvm::detail::IEEEFloat&,
    llvm::APFloatBase::roundingMode)

Declared at: llvm/include/llvm/ADT/APFloat.h:278

Parameters

const llvm::detail::IEEEFloat&
const llvm::detail::IEEEFloat&
llvm::APFloatBase::roundingMode

llvm::APFloatBase::fltCategory getCategory() const

Description

@ {

Declared at: llvm/include/llvm/ADT/APFloat.h:370

bool getExactInverse(llvm::APFloat* inv) const

Description

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

Declared at: llvm/include/llvm/ADT/APFloat.h:435

Parameters

llvm::APFloat* inv

const llvm::fltSemantics& getSemantics() const

Declared at: llvm/include/llvm/ADT/APFloat.h:371

bool isDenormal() const

Description

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

Declared at: llvm/include/llvm/ADT/APFloat.h:354

bool isFinite() const

Description

Returns true if and only if the current value is zero, subnormal, or normal. This means that the value is not infinite or NaN.

Declared at: llvm/include/llvm/ADT/APFloat.h:347

bool isFiniteNonZero() const

Declared at: llvm/include/llvm/ADT/APFloat.h:373

bool isInfinity() const

Description

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

Declared at: llvm/include/llvm/ADT/APFloat.h:357

bool isInteger() const

Description

Returns true if and only if the number is an exact integer.

Declared at: llvm/include/llvm/ADT/APFloat.h:386

bool isLargest() const

Description

Returns true if and only if the number has the largest possible finite magnitude in the current semantics.

Declared at: llvm/include/llvm/ADT/APFloat.h:383

bool isNaN() const

Description

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

Declared at: llvm/include/llvm/ADT/APFloat.h:360

bool isNegZero() const

Declared at: llvm/include/llvm/ADT/APFloat.h:375

bool isNegative() const

Description

IEEE-754R isSignMinus: Returns true if and only if the current value is negative. This applies to zeros and NaNs as well.

Declared at: llvm/include/llvm/ADT/APFloat.h:335

bool isNonZero() const

Declared at: llvm/include/llvm/ADT/APFloat.h:372

bool isNormal() const

Description

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.

Declared at: llvm/include/llvm/ADT/APFloat.h:341

bool isPosZero() const

Declared at: llvm/include/llvm/ADT/APFloat.h:374

bool isSignaling() const

Description

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

Declared at: llvm/include/llvm/ADT/APFloat.h:363

bool isSmallest() const

Description

Returns true if and only if the number has the smallest possible non-zero magnitude in the current semantics.

Declared at: llvm/include/llvm/ADT/APFloat.h:379

bool isZero() const

Description

Returns true if and only if the float is plus or minus zero.

Declared at: llvm/include/llvm/ADT/APFloat.h:350

void makeInf(bool Neg = false)

Declared at: llvm/include/llvm/ADT/APFloat.h:460

Parameters

bool Neg = false

void makeLargest(bool Neg = false)

Description

@ {

Declared at: llvm/include/llvm/ADT/APFloat.h:456

Parameters

bool Neg = false

void makeNaN(bool SNaN = false,
             bool Neg = false,
             const llvm::APInt* fill = nullptr)

Declared at: llvm/include/llvm/ADT/APFloat.h:458

Parameters

bool SNaN = false
bool Neg = false
const llvm::APInt* fill = nullptr

void makeQuiet()

Declared at: llvm/include/llvm/ADT/APFloat.h:462

void makeSmallest(bool Neg = false)

Declared at: llvm/include/llvm/ADT/APFloat.h:457

Parameters

bool Neg = false

void makeSmallestNormalized(bool Negative = false)

Description

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

Declared at: llvm/include/llvm/ADT/APFloat.h:468

Parameters

bool Negative = false
- True iff the number should be negative

void makeZero(bool Neg = false)

Declared at: llvm/include/llvm/ADT/APFloat.h:461

Parameters

bool Neg = false

llvm::APFloatBase::opStatus mod(
    const llvm::detail::IEEEFloat&)

Description

C fmod, or llvm frem.

Declared at: llvm/include/llvm/ADT/APFloat.h:277

Parameters

const llvm::detail::IEEEFloat&

llvm::APFloatBase::opStatus multiply(
    const llvm::detail::IEEEFloat&,
    llvm::APFloatBase::roundingMode)

Declared at: llvm/include/llvm/ADT/APFloat.h:272

Parameters

const llvm::detail::IEEEFloat&
llvm::APFloatBase::roundingMode

bool needsCleanup() const

Description

Returns whether this instance allocated memory.

Declared at: llvm/include/llvm/ADT/APFloat.h:260

llvm::APFloatBase::opStatus next(bool nextDown)

Description

IEEE-754R 5.3.1: nextUp/nextDown.

Declared at: llvm/include/llvm/ADT/APFloat.h:281

Parameters

bool nextDown

llvm::APFloatBase::opStatus remainder(
    const llvm::detail::IEEEFloat&)

Description

IEEE remainder.

Declared at: llvm/include/llvm/ADT/APFloat.h:275

Parameters

const llvm::detail::IEEEFloat&

llvm::APFloatBase::opStatus roundToIntegral(
    llvm::APFloatBase::roundingMode)

Declared at: llvm/include/llvm/ADT/APFloat.h:279

Parameters

llvm::APFloatBase::roundingMode

llvm::APFloatBase::opStatus subtract(
    const llvm::detail::IEEEFloat&,
    llvm::APFloatBase::roundingMode)

Declared at: llvm/include/llvm/ADT/APFloat.h:271

Parameters

const llvm::detail::IEEEFloat&
llvm::APFloatBase::roundingMode

void toString(SmallVectorImpl<char>& Str,
              unsigned int FormatPrecision = 0,
              unsigned int FormatMaxPadding = 3,
              bool TruncateZero = true) const

Description

Converts this value into a decimal string. 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

Declared at: llvm/include/llvm/ADT/APFloat.h:430

Parameters

SmallVectorImpl<char>& Str
unsigned int FormatPrecision = 0
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.
unsigned int FormatMaxPadding = 3
The maximum number of zeros to consider inserting before falling back to scientific notation. 0 means to always use scientific notation.
bool TruncateZero = true
Indicate whether to remove the trailing zero in fraction part or not. Also setting this parameter to false forcing producing of output more similar to default printf behavior. Specifically the lower e is used as exponent delimiter and exponent always contains no less than two digits.

~IEEEFloat()

Declared at: llvm/include/llvm/ADT/APFloat.h:255