Add a unittest for APFloat::getSmallest.
authorMichael Gottesman <mgottesman@apple.com>
Wed, 29 May 2013 23:58:29 +0000 (23:58 +0000)
committerMichael Gottesman <mgottesman@apple.com>
Wed, 29 May 2013 23:58:29 +0000 (23:58 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@182894 91177308-0d34-0410-b5e6-96231b3b80d8

unittests/ADT/APFloatTest.cpp

index 099f6db7cbfc7f7249672e11471cae8c5a46b240..4b51e85d631e3034ce3022988294ec9bb7fb0edd 100644 (file)
@@ -794,6 +794,32 @@ TEST(APFloatTest, getLargest) {
   EXPECT_EQ(1.7976931348623158e+308, APFloat::getLargest(APFloat::IEEEdouble).convertToDouble());
 }
 
+TEST(APFloatTest, getSmallest) {
+  APFloat test = APFloat::getSmallest(APFloat::IEEEsingle, false);
+  APFloat expected = APFloat(APFloat::IEEEsingle, "0x0.000002p-126");
+  EXPECT_TRUE(!test.isNegative());
+  EXPECT_TRUE(test.isNormal());
+  EXPECT_TRUE(test.bitwiseIsEqual(expected));
+
+  test = APFloat::getSmallest(APFloat::IEEEsingle, true);
+  expected = APFloat(APFloat::IEEEsingle, "-0x0.000002p-126");
+  EXPECT_TRUE(test.isNegative());
+  EXPECT_TRUE(test.isNormal());
+  EXPECT_TRUE(test.bitwiseIsEqual(expected));
+
+  test = APFloat::getSmallest(APFloat::IEEEquad, false);
+  expected = APFloat(APFloat::IEEEquad, "0x0.0000000000000000000000000001p-16382");
+  EXPECT_TRUE(!test.isNegative());
+  EXPECT_TRUE(test.isNormal());
+  EXPECT_TRUE(test.bitwiseIsEqual(expected));
+
+  test = APFloat::getSmallest(APFloat::IEEEquad, true);
+  expected = APFloat(APFloat::IEEEquad, "-0x0.0000000000000000000000000001p-16382");
+  EXPECT_TRUE(test.isNegative());
+  EXPECT_TRUE(test.isNormal());
+  EXPECT_TRUE(test.bitwiseIsEqual(expected));  
+}
+
 TEST(APFloatTest, convert) {
   bool losesInfo;
   APFloat test(APFloat::IEEEdouble, "1.0");