[PATCH] D145277: [support] Support printing floats in ScopedPrinter

Paul Kirth via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Tue Mar 7 10:07:26 PST 2023


paulkirth added inline comments.


================
Comment at: llvm/include/llvm/Support/ScopedPrinter.h:237
 
+  virtual void printNumber(StringRef Label, float Value) {
+    startLine() << Label << ": " << format("%5.1f", Value) << "\n";
----------------
jhenderson wrote:
> Would it make sense to add a `double` overload too, whilst you're at it? I think it might be a little confusing having one but not the other. (I can see the argument against it, since it's not going to be used immediately though, so happy either way)
I think that is a good idea, and is probably more consistent w/ JSON representation anyway. 


================
Comment at: llvm/unittests/Support/ScopedPrinterTest.cpp:560
+    float MinFloat = std::numeric_limits<float>::min();
+    float NaN = std::nanf("1");
+    W.printNumber("float-max", MaxFloat);
----------------
jhenderson wrote:
> Perhaps should check infinity too (https://en.cppreference.com/w/cpp/types/numeric_limits/infinity).
Good catch. Thank you.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D145277/new/

https://reviews.llvm.org/D145277



More information about the llvm-commits mailing list