[llvm] r184350 - [APFloat] Added isFiniteNonZero predicate.

Michael Gottesman mgottesman at apple.com
Wed Jun 19 14:00:17 PDT 2013


Author: mgottesman
Date: Wed Jun 19 16:00:17 2013
New Revision: 184350

URL: http://llvm.org/viewvc/llvm-project?rev=184350&view=rev
Log:
[APFloat] Added isFiniteNonZero predicate.

This is the first patch in a series of patches to rename isNormal =>
isFiniteNonZero and isIEEENormal => isNormal. In order to prevent careless
errors on my part the overall plan is:

1. Add the isFiniteNonZero predicate with tests. I can do this in a method
independent of isNormal. (This step is this patch).
2. Convert all references to isNormal with isFiniteNonZero. My plan is to
comment out isNormal locally and continually convert isNormal references =>
isFiniteNonZero until llvm/clang compiles.
3. Remove old isNormal and rename isIEEENormal to isNormal.
4. Look through all of said references from patch 2 and see if we can simplify
them by using the new isNormal.

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=184350&r1=184349&r2=184350&view=diff
==============================================================================
--- llvm/trunk/include/llvm/ADT/APFloat.h (original)
+++ llvm/trunk/include/llvm/ADT/APFloat.h Wed Jun 19 16:00:17 2013
@@ -395,6 +395,7 @@ public:
   const fltSemantics &getSemantics() const { return *semantics; }
   bool isNonZero() const { return category != fcZero; }
   bool isNormal() const { return category == fcNormal; }
+  bool isFiniteNonZero() const { return isFinite() && !isZero(); }
   bool isPosZero() const { return isZero() && !isNegative(); }
   bool isNegZero() const { return isZero() && isNegative(); }
 

Modified: llvm/trunk/unittests/ADT/APFloatTest.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/unittests/ADT/APFloatTest.cpp?rev=184350&r1=184349&r2=184350&view=diff
==============================================================================
--- llvm/trunk/unittests/ADT/APFloatTest.cpp (original)
+++ llvm/trunk/unittests/ADT/APFloatTest.cpp Wed Jun 19 16:00:17 2013
@@ -1458,4 +1458,32 @@ TEST(APFloatTest, isNaN) {
   EXPECT_FALSE(APFloat(APFloat::IEEEsingle, "0x1p-159").isNaN());
 }
 
+TEST(APFloatTest, isFiniteNonZero) {
+  // Test positive/negative normal value.
+  EXPECT_TRUE(APFloat(APFloat::IEEEsingle, "0x1p+0").isFiniteNonZero());
+  EXPECT_TRUE(APFloat(APFloat::IEEEsingle, "-0x1p+0").isFiniteNonZero());
+
+  // Test positive/negative denormal value.
+  EXPECT_TRUE(APFloat(APFloat::IEEEsingle, "0x1p-149").isFiniteNonZero());
+  EXPECT_TRUE(APFloat(APFloat::IEEEsingle, "-0x1p-149").isFiniteNonZero());
+
+  // Test +/- Infinity.
+  EXPECT_FALSE(APFloat::getInf(APFloat::IEEEsingle, false).isFiniteNonZero());
+  EXPECT_FALSE(APFloat::getInf(APFloat::IEEEsingle, true).isFiniteNonZero());
+
+  // Test +/- Zero.
+  EXPECT_FALSE(APFloat::getZero(APFloat::IEEEsingle, false).isFiniteNonZero());
+  EXPECT_FALSE(APFloat::getZero(APFloat::IEEEsingle, true).isFiniteNonZero());
+
+  // Test +/- qNaN. +/- dont mean anything with qNaN but paranoia can't hurt in
+  // this instance.
+  EXPECT_FALSE(APFloat::getNaN(APFloat::IEEEsingle, false).isFiniteNonZero());
+  EXPECT_FALSE(APFloat::getNaN(APFloat::IEEEsingle, true).isFiniteNonZero());
+
+  // Test +/- sNaN. +/- dont mean anything with sNaN but paranoia can't hurt in
+  // this instance.
+  EXPECT_FALSE(APFloat::getSNaN(APFloat::IEEEsingle, false).isFiniteNonZero()); 
+  EXPECT_FALSE(APFloat::getSNaN(APFloat::IEEEsingle, true).isFiniteNonZero()); 
+}
+
 }





More information about the llvm-commits mailing list