[llvm] 9eb7160 - Print the sign of negative infinity

Logan Chien via llvm-commits llvm-commits at lists.llvm.org
Tue Dec 14 22:39:58 PST 2021


Author: Logan Chien
Date: 2021-12-14T22:38:42-08:00
New Revision: 9eb71608ee0fef15e3369d936927640187ffc7c9

URL: https://github.com/llvm/llvm-project/commit/9eb71608ee0fef15e3369d936927640187ffc7c9
DIFF: https://github.com/llvm/llvm-project/commit/9eb71608ee0fef15e3369d936927640187ffc7c9.diff

LOG: Print the sign of negative infinity

Differential Revision: https://reviews.llvm.org/D111917

Added: 
    

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

Removed: 
    


################################################################################
diff  --git a/llvm/lib/Support/NativeFormatting.cpp b/llvm/lib/Support/NativeFormatting.cpp
index ae9f03745850f..254d18d797b3e 100644
--- a/llvm/lib/Support/NativeFormatting.cpp
+++ b/llvm/lib/Support/NativeFormatting.cpp
@@ -168,7 +168,7 @@ void llvm::write_double(raw_ostream &S, double N, FloatStyle Style,
     S << "nan";
     return;
   } else if (std::isinf(N)) {
-    S << "INF";
+    S << (std::signbit(N) ? "-INF" : "INF");
     return;
   }
 

diff  --git a/llvm/unittests/Support/NativeFormatTests.cpp b/llvm/unittests/Support/NativeFormatTests.cpp
index bbe9aa6f6dc46..8ab99ffd66b14 100644
--- a/llvm/unittests/Support/NativeFormatTests.cpp
+++ b/llvm/unittests/Support/NativeFormatTests.cpp
@@ -125,6 +125,8 @@ TEST(NativeFormatTest, BoundaryTests) {
                                  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) {


        


More information about the llvm-commits mailing list