[libc-commits] [PATCH] D148179: [libc] Make printf decimal long doubles use hex

Michael Jones via Phabricator via libc-commits libc-commits at lists.llvm.org
Wed May 3 11:08:21 PDT 2023


michaelrj updated this revision to Diff 519175.
michaelrj marked an inline comment as done.
michaelrj added a comment.

add comment to clarify the variable named "a"


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D148179

Files:
  libc/src/stdio/printf_core/converter.cpp
  libc/src/stdio/printf_core/float_hex_converter.h


Index: libc/src/stdio/printf_core/float_hex_converter.h
===================================================================
--- libc/src/stdio/printf_core/float_hex_converter.h
+++ libc/src/stdio/printf_core/float_hex_converter.h
@@ -29,9 +29,9 @@
 LIBC_INLINE int convert_float_hex_exp(Writer *writer,
                                       const FormatSection &to_conv) {
   // All of the letters will be defined relative to variable a, which will be
-  // the appropriate case based on the name of the conversion.
-  // Since the name of the conversion is also 'a', we can just use it directly.
-  const char a = to_conv.conv_name;
+  // the appropriate case based on the name of the conversion. This converts any
+  // conversion name into the letter 'a' with the appropriate case.
+  const char a = (to_conv.conv_name & 32) | 'A';
 
   bool is_negative;
   int exponent;
Index: libc/src/stdio/printf_core/converter.cpp
===================================================================
--- libc/src/stdio/printf_core/converter.cpp
+++ libc/src/stdio/printf_core/converter.cpp
@@ -28,6 +28,23 @@
   if (!to_conv.has_conv)
     return writer->write(to_conv.raw_string);
 
+#ifndef LIBC_COPT_PRINTF_DISABLE_FLOAT
+  // TODO(michaelrj): Undo this once decimal long double support is done.
+  if (to_conv.length_modifier == LengthModifier::L) {
+    switch (to_conv.conv_name) {
+    case 'f':
+    case 'F':
+    case 'e':
+    case 'E':
+    case 'g':
+    case 'G':
+      return convert_float_hex_exp(writer, to_conv);
+    default:
+      break;
+    }
+  }
+#endif // LIBC_COPT_PRINTF_DISABLE_FLOAT
+
   switch (to_conv.conv_name) {
   case '%':
     return writer->write("%");


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D148179.519175.patch
Type: text/x-patch
Size: 1685 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/libc-commits/attachments/20230503/f0cc941f/attachment-0001.bin>


More information about the libc-commits mailing list