c42f / tinyformat

Minimal, type safe printf replacement library for C++
537 stars 75 forks source link

Passing -INF through %.16d still puts the minus sign at far-left #81

Open duffy-ocraven opened 3 years ago

duffy-ocraven commented 3 years ago

Before #77 change gets widely circulated, check whether passing the negative -INF through %.16d still puts the minus sign at far-left

bbannier commented 3 years ago

A reproducer is

diff --git a/tinyformat_test.cpp b/tinyformat_test.cpp
index 4bb1d60..3e85007 100644
--- a/tinyformat_test.cpp
+++ b/tinyformat_test.cpp
@@ -222,6 +222,7 @@ int unitTests()
     CHECK_EQUAL(tfm::format("%.3d",   std::numeric_limits<double>::quiet_NaN()), "nan");
     CHECK_EQUAL(tfm::format("%.4d",   std::numeric_limits<double>::quiet_NaN()), " nan");
     CHECK_EQUAL(tfm::format("%04.0f", std::numeric_limits<double>::quiet_NaN()), " nan");
+    CHECK_EQUAL(tfm::format("%.5d", -std::numeric_limits<double>::infinity()), " -inf");
 #   endif

     //------------------------------------------------------------

which fails with

test failed, line 225
- inf !=  -inf
[tfm::format("%.5d", -std::numeric_limits<double>::infinity()), " -inf"]