[PATCH] D38030: Fix APFloat from string conversion for Inf
Serguei Katkov via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Thu Oct 19 04:17:53 PDT 2017
This revision was automatically updated to reflect the committed changes.
Closed by commit rL316156: Fix APFloat from string conversion for Inf (authored by skatkov).
Changed prior to commit:
https://reviews.llvm.org/D38030?vs=115806&id=119564#toc
Repository:
rL LLVM
https://reviews.llvm.org/D38030
Files:
llvm/trunk/lib/Support/APFloat.cpp
llvm/trunk/unittests/ADT/APFloatTest.cpp
Index: llvm/trunk/lib/Support/APFloat.cpp
===================================================================
--- llvm/trunk/lib/Support/APFloat.cpp
+++ llvm/trunk/lib/Support/APFloat.cpp
@@ -2543,12 +2543,12 @@
}
bool IEEEFloat::convertFromStringSpecials(StringRef str) {
- if (str.equals("inf") || str.equals("INFINITY")) {
+ if (str.equals("inf") || str.equals("INFINITY") || str.equals("+Inf")) {
makeInf(false);
return true;
}
- if (str.equals("-inf") || str.equals("-INFINITY")) {
+ if (str.equals("-inf") || str.equals("-INFINITY") || str.equals("-Inf")) {
makeInf(true);
return true;
}
Index: llvm/trunk/unittests/ADT/APFloatTest.cpp
===================================================================
--- llvm/trunk/unittests/ADT/APFloatTest.cpp
+++ llvm/trunk/unittests/ADT/APFloatTest.cpp
@@ -849,6 +849,22 @@
EXPECT_EQ(2.71828, convertToDoubleFromString("2.71828"));
}
+TEST(APFloatTest, fromToStringSpecials) {
+ auto roundTrip = [] (const char* str) {
+ return convertToString(convertToDoubleFromString(str), 0, 3).c_str();
+ };
+ EXPECT_STREQ("+Inf", roundTrip("+Inf"));
+ EXPECT_STREQ("+Inf", roundTrip("INFINITY"));
+ EXPECT_STREQ("+Inf", roundTrip("inf"));
+ EXPECT_STREQ("-Inf", roundTrip("-Inf"));
+ EXPECT_STREQ("-Inf", roundTrip("-INFINITY"));
+ EXPECT_STREQ("-Inf", roundTrip("-inf"));
+ EXPECT_STREQ("NaN", roundTrip("NaN"));
+ EXPECT_STREQ("NaN", roundTrip("nan"));
+ EXPECT_STREQ("NaN", roundTrip("-NaN"));
+ EXPECT_STREQ("NaN", roundTrip("-nan"));
+}
+
TEST(APFloatTest, fromHexadecimalString) {
EXPECT_EQ( 1.0, APFloat(APFloat::IEEEdouble(), "0x1p0").convertToDouble());
EXPECT_EQ(+1.0, APFloat(APFloat::IEEEdouble(), "+0x1p0").convertToDouble());
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D38030.119564.patch
Type: text/x-patch
Size: 1741 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20171019/9549672e/attachment.bin>
More information about the llvm-commits
mailing list