-//== llvm/Support/APFloat.h - Arbitrary Precision Floating Point -*- C++ -*-==//
+//===- llvm/ADT/APFloat.h - Arbitrary Precision Floating Point ---*- C++ -*-==//
//
// The LLVM Compiler Infrastructure
//
#ifndef LLVM_ADT_APFLOAT_H
#define LLVM_ADT_APFLOAT_H
-// APInt contains static functions implementing bignum arithmetic.
#include "llvm/ADT/APInt.h"
namespace llvm {
-/// A signed type to represent a floating point numbers unbiased exponent.
-typedef signed short exponent_t;
-
struct fltSemantics;
class APSInt;
class StringRef;
/// New formats: x87 in single and double precision mode (IEEE apart from
/// extended exponent range) (hard).
///
-/// New operations: sqrt, IEEE remainder, C90 fmod, nextafter, nexttoward.
+/// New operations: sqrt, IEEE remainder, C90 fmod, nexttoward.
///
class APFloat {
public:
+ /// A signed type to represent a floating point numbers unbiased exponent.
+ typedef signed short ExponentType;
+
/// \name Floating Point Semantics.
/// @{
/// anything real.
static const fltSemantics Bogus;
+ /// @}
+
static unsigned int semanticsPrecision(const fltSemantics &);
/// IEEE-754R 5.11: Floating Point Comparison Relations.
APFloat(const fltSemantics &); // Default construct to 0.0
APFloat(const fltSemantics &, StringRef);
APFloat(const fltSemantics &, integerPart);
- APFloat(const fltSemantics &, fltCategory, bool negative);
APFloat(const fltSemantics &, uninitializedTag);
APFloat(const fltSemantics &, const APInt &);
explicit APFloat(double d);
explicit APFloat(float f);
APFloat(const APFloat &);
+ APFloat(APFloat &&);
~APFloat();
/// @}
+ /// \brief Returns whether this instance allocated memory.
+ bool needsCleanup() const { return partCount() > 1; }
+
/// \name Convenience "constructors"
/// @{
///
/// \param Negative True iff the number should be negative.
static APFloat getZero(const fltSemantics &Sem, bool Negative = false) {
- return APFloat(Sem, fcZero, Negative);
+ APFloat Val(Sem, uninitialized);
+ Val.makeZero(Negative);
+ return Val;
}
/// Factory for Positive and Negative Infinity.
///
/// \param Negative True iff the number should be negative.
static APFloat getInf(const fltSemantics &Sem, bool Negative = false) {
- return APFloat(Sem, fcInfinity, Negative);
+ APFloat Val(Sem, uninitialized);
+ Val.makeInf(Negative);
+ return Val;
}
/// Factory for QNaN values.
/// IEEE-754R 5.3.1: nextUp/nextDown.
opStatus next(bool nextDown);
+ /// @}
+
/// \name Sign operations.
/// @{
unsigned int convertToHexString(char *dst, unsigned int hexDigits,
bool upperCase, roundingMode) const;
+ /// \name IEEE-754R 5.7.2 General operations.
+ /// @{
+
+ /// IEEE-754R isSignMinus: Returns true if and only if the current value is
+ /// negative.
+ ///
+ /// This applies to zeros and NaNs as well.
+ bool isNegative() const { return sign; }
+
+ /// 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.
+ bool isNormal() const { return !isDenormal() && isFiniteNonZero(); }
+
+ /// Returns true if and only if the current value is zero, subnormal, or
+ /// normal.
+ ///
+ /// This means that the value is not infinite or NaN.
+ bool isFinite() const { return !isNaN() && !isInfinity(); }
+
+ /// Returns true if and only if the float is plus or minus zero.
+ bool isZero() const { return category == fcZero; }
+
+ /// IEEE-754R isSubnormal(): Returns true if and only if the float is a
+ /// denormal.
+ bool isDenormal() const;
+
+ /// IEEE-754R isInfinite(): Returns true if and only if the float is infinity.
+ bool isInfinity() const { return category == fcInfinity; }
+
+ /// Returns true if and only if the float is a quiet or signaling NaN.
+ bool isNaN() const { return category == fcNaN; }
+
+ /// Returns true if and only if the float is a signaling NaN.
+ bool isSignaling() const;
+
+ /// @}
+
/// \name Simple Queries
/// @{
fltCategory getCategory() const { return category; }
const fltSemantics &getSemantics() const { return *semantics; }
- bool isZero() const { return category == fcZero; }
bool isNonZero() const { return category != fcZero; }
- bool isNormal() const { return category == fcNormal; }
- bool isNaN() const { return category == fcNaN; }
- bool isInfinity() const { return category == fcInfinity; }
- bool isNegative() const { return sign; }
+ bool isFiniteNonZero() const { return isFinite() && !isZero(); }
bool isPosZero() const { return isZero() && !isNegative(); }
bool isNegZero() const { return isZero() && isNegative(); }
- bool isDenormal() const;
- /// IEEE-754R 5.7.2: isSignaling. Returns true if this is a signaling NaN.
- bool isSignaling() const;
+
+ /// Returns true if and only if the number has the smallest possible non-zero
+ /// magnitude in the current semantics.
+ bool isSmallest() const;
+
+ /// Returns true if and only if the number has the largest possible finite
+ /// magnitude in the current semantics.
+ bool isLargest() const;
/// @}
APFloat &operator=(const APFloat &);
+ APFloat &operator=(APFloat &&);
/// \brief Overload to compute a hash code for an APFloat value.
///
void makeNaN(bool SNaN = false, bool Neg = false, const APInt *fill = 0);
static APFloat makeNaN(const fltSemantics &Sem, bool SNaN, bool Negative,
const APInt *fill);
-
- /// @}
-
- /// \name Special value queries only useful internally to APFloat
- /// @{
-
- /// Returns true if and only if the number has the smallest possible non-zero
- /// magnitude in the current semantics.
- bool isSmallest() const;
- /// Returns true if and only if the number has the largest possible finite
- /// magnitude in the current semantics.
- bool isLargest() const;
+ void makeInf(bool Neg = false);
+ void makeZero(bool Neg = false);
/// @}
/// \name Miscellany
/// @{
+ bool convertFromStringSpecials(StringRef str);
opStatus normalize(roundingMode, lostFraction);
opStatus addOrSubtract(const APFloat &, roundingMode, bool subtract);
cmpResult compareAbsoluteValue(const APFloat &) const;
} significand;
/// The signed unbiased exponent of the value.
- exponent_t exponent;
+ ExponentType exponent;
/// What kind of floating point number this is.
///