Add support for letting the client choose different flavors of NaNs. Testcase to be

added in clang.


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@72606 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
Mike Stump 2009-05-30 03:49:43 +00:00
parent 51b16f4737
commit c5ca713b80
2 changed files with 17 additions and 10 deletions

View File

@ -174,7 +174,7 @@ namespace llvm {
// Constructors. // Constructors.
APFloat(const fltSemantics &, const char *); APFloat(const fltSemantics &, const char *);
APFloat(const fltSemantics &, integerPart); APFloat(const fltSemantics &, integerPart);
APFloat(const fltSemantics &, fltCategory, bool negative); APFloat(const fltSemantics &, fltCategory, bool negative, unsigned type=0);
explicit APFloat(double d); explicit APFloat(double d);
explicit APFloat(float f); explicit APFloat(float f);
explicit APFloat(const APInt &, bool isIEEE = false); explicit APFloat(const APInt &, bool isIEEE = false);
@ -188,8 +188,9 @@ namespace llvm {
static APFloat getInf(const fltSemantics &Sem, bool Negative = false) { static APFloat getInf(const fltSemantics &Sem, bool Negative = false) {
return APFloat(Sem, fcInfinity, Negative); return APFloat(Sem, fcInfinity, Negative);
} }
static APFloat getNaN(const fltSemantics &Sem, bool Negative = false) { static APFloat getNaN(const fltSemantics &Sem, bool Negative = false,
return APFloat(Sem, fcNaN, Negative); long unsigned type=0) {
return APFloat(Sem, fcNaN, Negative, type);
} }
/// Profile - Used to insert APFloat objects, or objects that contain /// Profile - Used to insert APFloat objects, or objects that contain
@ -296,7 +297,7 @@ namespace llvm {
opStatus modSpecials(const APFloat &); opStatus modSpecials(const APFloat &);
/* Miscellany. */ /* Miscellany. */
void makeNaN(void); void makeNaN(unsigned = 0);
opStatus normalize(roundingMode, lostFraction); opStatus normalize(roundingMode, lostFraction);
opStatus addOrSubtract(const APFloat &, roundingMode, bool subtract); opStatus addOrSubtract(const APFloat &, roundingMode, bool subtract);
cmpResult compareAbsoluteValue(const APFloat &) const; cmpResult compareAbsoluteValue(const APFloat &) const;

View File

@ -598,12 +598,18 @@ APFloat::copySignificand(const APFloat &rhs)
/* Make this number a NaN, with an arbitrary but deterministic value /* Make this number a NaN, with an arbitrary but deterministic value
for the significand. If double or longer, this is a signalling NaN, for the significand. If double or longer, this is a signalling NaN,
which may not be ideal. */ which may not be ideal. If float, this is QNaN(0). */
void void
APFloat::makeNaN(void) APFloat::makeNaN(unsigned type)
{ {
category = fcNaN; category = fcNaN;
APInt::tcSet(significandParts(), ~0U, partCount()); // FIXME: Add double and long double support for QNaN(0).
if (semantics->precision == 24 && semantics->maxExponent == 127) {
type |= 0x7fc00000U;
type &= ~0x80000000U;
} else
type = ~0U;
APInt::tcSet(significandParts(), type, partCount());
} }
APFloat & APFloat &
@ -662,16 +668,16 @@ APFloat::APFloat(const fltSemantics &ourSemantics, integerPart value)
} }
APFloat::APFloat(const fltSemantics &ourSemantics, APFloat::APFloat(const fltSemantics &ourSemantics,
fltCategory ourCategory, bool negative) fltCategory ourCategory, bool negative, unsigned type)
{ {
assertArithmeticOK(ourSemantics); assertArithmeticOK(ourSemantics);
initialize(&ourSemantics); initialize(&ourSemantics);
category = ourCategory; category = ourCategory;
sign = negative; sign = negative;
if(category == fcNormal) if (category == fcNormal)
category = fcZero; category = fcZero;
else if (ourCategory == fcNaN) else if (ourCategory == fcNaN)
makeNaN(); makeNaN(type);
} }
APFloat::APFloat(const fltSemantics &ourSemantics, const char *text) APFloat::APFloat(const fltSemantics &ourSemantics, const char *text)