[APFloat] Added a unittest for APFloat::getZero.
authorMichael Gottesman <mgottesman@apple.com>
Fri, 31 May 2013 18:43:34 +0000 (18:43 +0000)
committerMichael Gottesman <mgottesman@apple.com>
Fri, 31 May 2013 18:43:34 +0000 (18:43 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@183028 91177308-0d34-0410-b5e6-96231b3b80d8

unittests/ADT/APFloatTest.cpp

index 1d7ac99d68a9529d0853a0acbcb34589361d3f52..72403f4f142cb337703228fefeb4f5a25b5c4394 100644 (file)
@@ -1274,6 +1274,43 @@ TEST(APFloatTest, getSmallestNormalized) {
   EXPECT_TRUE(test.bitwiseIsEqual(expected));  
 }
 
+TEST(APFloatTest, getZero) {
+  struct {
+    const fltSemantics *semantics;
+    const bool sign;
+    const unsigned long long bitPattern[2];
+    const unsigned bitPatternLength;
+  } GetZeroTest[] = {
+    { &APFloat::IEEEhalf, false, {0, 0}, 1},
+    { &APFloat::IEEEhalf, true, {0x8000, 0}, 1},
+    { &APFloat::IEEEsingle, false, {0, 0}, 1},
+    { &APFloat::IEEEsingle, true, {0x80000000, 0}, 1},
+    { &APFloat::IEEEdouble, false, {0, 0}, 1},
+    { &APFloat::IEEEdouble, true, {0x8000000000000000, 0}, 1},
+    { &APFloat::IEEEquad, false, {0, 0}, 2},
+    { &APFloat::IEEEquad, true, {0, 0x8000000000000000}, 2},
+    { &APFloat::PPCDoubleDouble, false, {0, 0}, 2},
+    { &APFloat::PPCDoubleDouble, true, {0x8000000000000000, 0}, 2},
+    { &APFloat::x87DoubleExtended, false, {0, 0}, 2},
+    { &APFloat::x87DoubleExtended, true, {0, 0x8000}, 2},
+  };
+  const unsigned NumGetZeroTests = 12;
+  for (unsigned i = 0; i < NumGetZeroTests; ++i) {
+    APFloat test = APFloat::getZero(*GetZeroTest[i].semantics,
+                                   GetZeroTest[i].sign);
+    const char *pattern = GetZeroTest[i].sign? "-0x0p+0" : "0x0p+0";
+    APFloat expected = APFloat(*GetZeroTest[i].semantics,
+                              pattern);
+    EXPECT_TRUE(test.isZero());
+    EXPECT_TRUE(GetZeroTest[i].sign? test.isNegative() : !test.isNegative());
+    EXPECT_TRUE(test.bitwiseIsEqual(expected));
+    for (unsigned j = 0, je = GetZeroTest[i].bitPatternLength; j < je; ++j) {
+      EXPECT_EQ(GetZeroTest[i].bitPattern[j],
+               test.bitcastToAPInt().getRawData()[j]);
+    }
+  }
+}
+
 TEST(APFloatTest, convert) {
   bool losesInfo;
   APFloat test(APFloat::IEEEdouble, "1.0");