[PATCH] D111917: Print the sign of negative infinity

Logan Chien via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Fri Oct 15 17:51:08 PDT 2021


logan created this revision.
Herald added subscribers: dexonsmith, hiraditya.
logan requested review of this revision.
Herald added a project: LLVM.
Herald added a subscriber: llvm-commits.

This commit makes `llvm::write_double` print `-inf` as `"-INF"` instead of `"INF"`.


https://reviews.llvm.org/D111917

Files:
  llvm/lib/Support/NativeFormatting.cpp
  llvm/unittests/Support/NativeFormatTests.cpp


Index: llvm/unittests/Support/NativeFormatTests.cpp
===================================================================
--- llvm/unittests/Support/NativeFormatTests.cpp
+++ llvm/unittests/Support/NativeFormatTests.cpp
@@ -125,6 +125,8 @@
                                  FloatStyle::Fixed));
   EXPECT_EQ("INF", format_number(std::numeric_limits<double>::infinity(),
                                  FloatStyle::Fixed));
+  EXPECT_EQ("-INF", format_number(-std::numeric_limits<double>::infinity(),
+                                  FloatStyle::Fixed));
 }
 
 TEST(NativeFormatTest, HexTests) {
Index: llvm/lib/Support/NativeFormatting.cpp
===================================================================
--- llvm/lib/Support/NativeFormatting.cpp
+++ llvm/lib/Support/NativeFormatting.cpp
@@ -168,7 +168,7 @@
     S << "nan";
     return;
   } else if (std::isinf(N)) {
-    S << "INF";
+    S << (std::signbit(N) ? "-INF" : "INF");
     return;
   }
 


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D111917.380124.patch
Type: text/x-patch
Size: 958 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20211016/b9f7fa71/attachment.bin>


More information about the llvm-commits mailing list