[llvm] r183179 - IEEE-754R 5.7.2 General Operations is* operations (except for isCanonical).
Michael Gottesman
mgottesman at apple.com
Mon Jun 3 20:46:25 PDT 2013
Author: mgottesman
Date: Mon Jun 3 22:46:25 2013
New Revision: 183179
URL: http://llvm.org/viewvc/llvm-project?rev=183179&view=rev
Log:
IEEE-754R 5.7.2 General Operations is* operations (except for isCanonical).
Specifically the following work was done:
1. If the operation was not implemented, I implemented it.
2. If the operation was already implemented, I just moved its location
in the APFloat header into the IEEE-754R 5.7.2 section. If the name was
incorrect, I put in a comment giving the true IEEE-754R name.
Also unittests have been added for all of the functions which did not
already have a unittest.
Modified:
llvm/trunk/include/llvm/ADT/APFloat.h
llvm/trunk/unittests/ADT/APFloatTest.cpp
Modified: llvm/trunk/include/llvm/ADT/APFloat.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/ADT/APFloat.h?rev=183179&r1=183178&r2=183179&view=diff
==============================================================================
--- llvm/trunk/include/llvm/ADT/APFloat.h (original)
+++ llvm/trunk/include/llvm/ADT/APFloat.h Mon Jun 3 22:46:25 2013
@@ -346,22 +346,57 @@ public:
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.
+ ///
+ /// The current implementation of isNormal() differs from this by treating
+ /// subnormal values as normal values.
+ bool isIEEENormal() const { return !isDenormal() && isNormal(); }
+
+ /// 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 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;
/// @}
Modified: llvm/trunk/unittests/ADT/APFloatTest.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/unittests/ADT/APFloatTest.cpp?rev=183179&r1=183178&r2=183179&view=diff
==============================================================================
--- llvm/trunk/unittests/ADT/APFloatTest.cpp (original)
+++ llvm/trunk/unittests/ADT/APFloatTest.cpp Mon Jun 3 22:46:25 2013
@@ -1397,4 +1397,65 @@ TEST(APFloatTest, PPCDoubleDouble) {
EXPECT_EQ(0x0000000000000000ull, test.bitcastToAPInt().getRawData()[1]);
#endif
}
+
+TEST(APFloatTest, isNegative) {
+ APFloat t(APFloat::IEEEsingle, "0x1p+0");
+ EXPECT_FALSE(t.isNegative());
+ t = APFloat(APFloat::IEEEsingle, "-0x1p+0");
+ EXPECT_TRUE(t.isNegative());
+
+ EXPECT_FALSE(APFloat::getInf(APFloat::IEEEsingle, false).isNegative());
+ EXPECT_TRUE(APFloat::getInf(APFloat::IEEEsingle, true).isNegative());
+
+ EXPECT_FALSE(APFloat::getZero(APFloat::IEEEsingle, false).isNegative());
+ EXPECT_TRUE(APFloat::getZero(APFloat::IEEEsingle, true).isNegative());
+
+ EXPECT_FALSE(APFloat::getNaN(APFloat::IEEEsingle, false).isNegative());
+ EXPECT_TRUE(APFloat::getNaN(APFloat::IEEEsingle, true).isNegative());
+
+ EXPECT_FALSE(APFloat::getSNaN(APFloat::IEEEsingle, false).isNegative());
+ EXPECT_TRUE(APFloat::getSNaN(APFloat::IEEEsingle, true).isNegative());
+}
+
+TEST(APFloatTest, isIEEENormal) {
+ APFloat t(APFloat::IEEEsingle, "0x1p+0");
+ EXPECT_TRUE(t.isIEEENormal());
+
+ EXPECT_FALSE(APFloat::getInf(APFloat::IEEEsingle, false).isIEEENormal());
+ EXPECT_FALSE(APFloat::getZero(APFloat::IEEEsingle, false).isIEEENormal());
+ EXPECT_FALSE(APFloat::getNaN(APFloat::IEEEsingle, false).isIEEENormal());
+ EXPECT_FALSE(APFloat::getSNaN(APFloat::IEEEsingle, false).isIEEENormal());
+ EXPECT_FALSE(APFloat(APFloat::IEEEsingle, "0x1p-159").isIEEENormal());
+}
+
+TEST(APFloatTest, isFinite) {
+ APFloat t(APFloat::IEEEsingle, "0x1p+0");
+ EXPECT_TRUE(t.isFinite());
+ EXPECT_FALSE(APFloat::getInf(APFloat::IEEEsingle, false).isFinite());
+ EXPECT_TRUE(APFloat::getZero(APFloat::IEEEsingle, false).isFinite());
+ EXPECT_FALSE(APFloat::getNaN(APFloat::IEEEsingle, false).isFinite());
+ EXPECT_FALSE(APFloat::getSNaN(APFloat::IEEEsingle, false).isFinite());
+ EXPECT_TRUE(APFloat(APFloat::IEEEsingle, "0x1p-159").isFinite());
+}
+
+TEST(APFloatTest, isInfinity) {
+ APFloat t(APFloat::IEEEsingle, "0x1p+0");
+ EXPECT_FALSE(t.isInfinity());
+ EXPECT_TRUE(APFloat::getInf(APFloat::IEEEsingle, false).isInfinity());
+ EXPECT_FALSE(APFloat::getZero(APFloat::IEEEsingle, false).isInfinity());
+ EXPECT_FALSE(APFloat::getNaN(APFloat::IEEEsingle, false).isInfinity());
+ EXPECT_FALSE(APFloat::getSNaN(APFloat::IEEEsingle, false).isInfinity());
+ EXPECT_FALSE(APFloat(APFloat::IEEEsingle, "0x1p-159").isInfinity());
+}
+
+TEST(APFloatTest, isNaN) {
+ APFloat t(APFloat::IEEEsingle, "0x1p+0");
+ EXPECT_FALSE(t.isNaN());
+ EXPECT_FALSE(APFloat::getInf(APFloat::IEEEsingle, false).isNaN());
+ EXPECT_FALSE(APFloat::getZero(APFloat::IEEEsingle, false).isNaN());
+ EXPECT_TRUE(APFloat::getNaN(APFloat::IEEEsingle, false).isNaN());
+ EXPECT_TRUE(APFloat::getSNaN(APFloat::IEEEsingle, false).isNaN());
+ EXPECT_FALSE(APFloat(APFloat::IEEEsingle, "0x1p-159").isNaN());
+}
+
}
More information about the llvm-commits
mailing list