[libc-commits] [PATCH] D140042: [libc] add exponent format to printf

Michael Jones via Phabricator via libc-commits libc-commits at lists.llvm.org
Wed Dec 21 14:17:28 PST 2022


michaelrj marked an inline comment as done.
michaelrj added inline comments.


================
Comment at: libc/src/stdio/printf_core/float_dec_converter.h:190
+  cpp::string_view exp_str(int exponent, cpp::span<char> exp_buffer) {
+    int positive_exponent = exponent < 0 ? -exponent : exponent;
+    char exp_sign = exponent < 0 ? '-' : '+';
----------------
sivachandra wrote:
> Is `-exponent` guaranteed to not overflow here? If not, then may be you should just let `IntegerToString` handle the sign for negative numbers,  but add a `+` if `exponent` is non-negative.
yes exponent is guaranteed not to overflow. It is an int (usually 32 bits, but a minimum of 16) and long doubles have a maximum of 15 bits for their exponent.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D140042



More information about the libc-commits mailing list