[haiku-commits] Change in haiku[master]: libs/posix: Fix printf handling for %F format.

  • From: Gerrit <review@xxxxxxxxxxxxxxxxxxx>
  • To: waddlesplash <waddlesplash@xxxxxxxxx>, haiku-commits@xxxxxxxxxxxxx
  • Date: Thu, 30 Jun 2022 13:14:51 +0000

From Trung Nguyen <trungnt282910@xxxxxxxxx>:

Trung Nguyen has uploaded this change for review. ( 
https://review.haiku-os.org/c/haiku/+/5424 ;)


Change subject: libs/posix: Fix printf handling for %F format.
......................................................................

libs/posix: Fix printf handling for %F format.

Before this patch, calling functions in the `printf` family and
passing %F in the format string, such as

    printf("%6.2F\n", 580.0f);

would incorrectly output numbers in the exponential format:

    5.8D+02

This patch fixes the output for this situation:

    580.00

and fixes the behavior for programs that use %F, such as
several tests for the `fish` shell.

Change-Id: I124a5a7b93b5f551fa190501a5778726812d347c
---
M src/system/libroot/posix/glibc/stdio-common/printf_fp.c
1 file changed, 7 insertions(+), 7 deletions(-)



  git pull ssh://git.haiku-os.org:22/haiku refs/changes/24/5424/1

diff --git a/src/system/libroot/posix/glibc/stdio-common/printf_fp.c 
b/src/system/libroot/posix/glibc/stdio-common/printf_fp.c
index a425b33..71c1202 100644
--- a/src/system/libroot/posix/glibc/stdio-common/printf_fp.c
+++ b/src/system/libroot/posix/glibc/stdio-common/printf_fp.c
@@ -186,7 +186,7 @@
   /* Digit which is result of last hack_digit() call.  */
   wchar_t digit;

-  /* The type of output format that will be used: 'e'/'E' or 'f'.  */
+  /* The type of output format that will be used: 'e'/'E' or 'f'/'F'.  */
   int type;

   /* Counter for number of written characters. */
@@ -206,7 +206,7 @@
       mp_limb_t hi;

 hack_digit:
-      if (expsign != 0 && type == 'f' && exponent-- > 0)
+      if (expsign != 0 && _tolower (type) == 'f' && exponent-- > 0)
        hi = 0;
       else if (scalesize == 0)
        {
@@ -815,9 +815,9 @@
        dig_max = INT_MAX;              /* Unlimited.  */
        significant = 1;                /* Does not matter here.  */
       }
-    else if (info->spec == 'f')
+    else if (_tolower (info->spec) == 'f')
       {
-       type = 'f';
+       type = info->spec;
        fracdig_min = fracdig_max = info->prec < 0 ? 6 : info->prec;
        if (expsign == 0)
          {
@@ -888,7 +888,7 @@
     wcp = wstartp = wbuffer + 2;       /* Let room for rounding.  */

     /* Do the real work: put digits in allocated buffer.  */
-    if (expsign == 0 || type != 'f')
+    if (expsign == 0 || _tolower (type) != 'f')
       {
        assert (expsign == 0 || intdig_max == 1);
        while (intdig_no < intdig_max)
@@ -992,7 +992,7 @@
            else
              /* It is more critical.  All digits were 9's.  */
              {
-               if (type != 'f')
+               if (_tolower (type) != 'f')
                  {
                    *wstartp = '1';
                    exponent += expsign == 0 ? 1 : -1;
@@ -1057,7 +1057,7 @@
                          ngroups);

     /* Write the exponent if it is needed.  */
-    if (type != 'f')
+    if (_tolower (type) != 'f')
       {
        *wcp++ = (wchar_t) type;
        *wcp++ = expsign ? L'-' : L'+';

--
To view, visit https://review.haiku-os.org/c/haiku/+/5424
To unsubscribe, or for help writing mail filters, visit 
https://review.haiku-os.org/settings

Gerrit-Project: haiku
Gerrit-Branch: master
Gerrit-Change-Id: I124a5a7b93b5f551fa190501a5778726812d347c
Gerrit-Change-Number: 5424
Gerrit-PatchSet: 1
Gerrit-Owner: Trung Nguyen <trungnt282910@xxxxxxxxx>
Gerrit-MessageType: newchange

Other related posts:

  • » [haiku-commits] Change in haiku[master]: libs/posix: Fix printf handling for %F format. - Gerrit