diff options
author | Dale Johannesen <dalej@apple.com> | 2007-08-31 04:03:46 +0000 |
---|---|---|
committer | Dale Johannesen <dalej@apple.com> | 2007-08-31 04:03:46 +0000 |
commit | df8a831eb0f35fad163b2e45212f8154a17bbd36 (patch) | |
tree | 426df38ac585285c3b18e3b4575b297fcd4d9e59 /include | |
parent | 85f456100c0a6dea1475c91dd358e4d9a81eb151 (diff) | |
download | external_llvm-df8a831eb0f35fad163b2e45212f8154a17bbd36.zip external_llvm-df8a831eb0f35fad163b2e45212f8154a17bbd36.tar.gz external_llvm-df8a831eb0f35fad163b2e45212f8154a17bbd36.tar.bz2 |
Enhance APFloat to retain bits of NaNs (fixes oggenc).
Use APFloat interfaces for more references, mostly
of ConstantFPSDNode.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@41632 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'include')
-rw-r--r-- | include/llvm/ADT/APFloat.h | 13 | ||||
-rw-r--r-- | include/llvm/ADT/StringExtras.h | 9 |
2 files changed, 18 insertions, 4 deletions
diff --git a/include/llvm/ADT/APFloat.h b/include/llvm/ADT/APFloat.h index 165e290..a29f15c 100644 --- a/include/llvm/ADT/APFloat.h +++ b/include/llvm/ADT/APFloat.h @@ -64,8 +64,11 @@ 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 - indeterminate and meaningless. For QNaNs the sign bit, as well as - the exponent and significand are indeterminate and meaningless. + 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; the exponent is + implicitly all 1 bits. TODO ==== @@ -155,7 +158,7 @@ namespace llvm { /* Category of internally-represented number. */ enum fltCategory { fcInfinity, - fcQNaN, + fcNaN, fcNormal, fcZero }; @@ -192,7 +195,7 @@ namespace llvm { whatever it is you really mean. */ // bool operator==(const APFloat &) const; // DO NOT IMPLEMENT - /* IEEE comparison with another floating point number (QNaNs + /* IEEE comparison with another floating point number (NaNs compare unordered, 0==-0). */ cmpResult compare(const APFloat &) const; @@ -205,6 +208,8 @@ namespace llvm { bool isZero() const { return category == fcZero; } bool isNonZero() const { return category != fcZero; } bool isNegative() const { return sign; } + bool isPosZero() const { return isZero() && !isNegative(); } + bool isNegZero() const { return isZero() && isNegative(); } APFloat& operator=(const APFloat &); diff --git a/include/llvm/ADT/StringExtras.h b/include/llvm/ADT/StringExtras.h index f0788a1..b56c183 100644 --- a/include/llvm/ADT/StringExtras.h +++ b/include/llvm/ADT/StringExtras.h @@ -15,6 +15,7 @@ #define LLVM_ADT_STRINGEXTRAS_H #include "llvm/Support/DataTypes.h" +#include "llvm/ADT/APFloat.h" #include <cctype> #include <cstdio> #include <string> @@ -92,6 +93,14 @@ static inline std::string ftostr(double V) { return B; } +static inline std::string ftostr(APFloat V) { + if (&V.getSemantics() == &APFloat::IEEEsingle) + return ftostr(V.convertToDouble()); + else if (&V.getSemantics() == &APFloat::IEEEdouble) + return ftostr((double)V.convertToFloat()); + return 0; // error +} + static inline std::string LowercaseString(const std::string &S) { std::string result(S); for (unsigned i = 0; i < S.length(); ++i) |