llvm.org GIT mirror llvm / 90ee44d
Fix APFloat from string conversion for Inf The method IEEEFloat::convertFromStringSpecials() does not recognize the "+Inf" and "-Inf" strings but these strings are printed for the double Infinities by the IEEEFloat::toString(). This patch adds the "+Inf" and "-Inf" strings to the list of recognized patterns in IEEEFloat::convertFromStringSpecials(). Reviewers: sberg, bogner, majnemer, timshen, rnk, skatkov, gottesmm, bkramer, scanon Reviewed By: skatkov Subscribers: apilipenko, reames, llvm-commits Differential Revision: https://reviews.llvm.org/D38030 git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@316156 91177308-0d34-0410-b5e6-96231b3b80d8 Serguei Katkov 1 year, 10 months ago
2 changed file(s) with 18 addition(s) and 2 deletion(s). Raw diff Collapse all Expand all
25422542 }
25432543
25442544 bool IEEEFloat::convertFromStringSpecials(StringRef str) {
2545 if (str.equals("inf") || str.equals("INFINITY")) {
2545 if (str.equals("inf") || str.equals("INFINITY") || str.equals("+Inf")) {
25462546 makeInf(false);
25472547 return true;
25482548 }
25492549
2550 if (str.equals("-inf") || str.equals("-INFINITY")) {
2550 if (str.equals("-inf") || str.equals("-INFINITY") || str.equals("-Inf")) {
25512551 makeInf(true);
25522552 return true;
25532553 }
846846 EXPECT_TRUE(APFloat(APFloat::IEEEdouble(), "-1e-99999").isNegZero());
847847
848848 EXPECT_EQ(2.71828, convertToDoubleFromString("2.71828"));
849 }
850
851 TEST(APFloatTest, fromToStringSpecials) {
852 auto roundTrip = [] (const char* str) {
853 return convertToString(convertToDoubleFromString(str), 0, 3).c_str();
854 };
855 EXPECT_STREQ("+Inf", roundTrip("+Inf"));
856 EXPECT_STREQ("+Inf", roundTrip("INFINITY"));
857 EXPECT_STREQ("+Inf", roundTrip("inf"));
858 EXPECT_STREQ("-Inf", roundTrip("-Inf"));
859 EXPECT_STREQ("-Inf", roundTrip("-INFINITY"));
860 EXPECT_STREQ("-Inf", roundTrip("-inf"));
861 EXPECT_STREQ("NaN", roundTrip("NaN"));
862 EXPECT_STREQ("NaN", roundTrip("nan"));
863 EXPECT_STREQ("NaN", roundTrip("-NaN"));
864 EXPECT_STREQ("NaN", roundTrip("-nan"));
849865 }
850866
851867 TEST(APFloatTest, fromHexadecimalString) {