This is the mail archive of the
newlib@sourceware.org
mailing list for the newlib project.
Re: [PATCH] Print sign of NaN values
- From: Kito Cheng <kito dot cheng at gmail dot com>
- To: Craig Howland <howland at lgsinnovations dot com>
- Cc: newlib at sourceware dot org
- Date: Wed, 7 Jun 2017 14:55:38 +0800
- Subject: Re: [PATCH] Print sign of NaN values
- Authentication-results: sourceware.org; auth=none
- References: <CA+yXCZBD5s=81zURuLEPYS-TkkaXt2OgbTgZhLNzA92WhHn1Jg@mail.gmail.com> <0aab66f6-20a6-10ec-f399-2a39799ab980@LGSInnovations.com>
Hi Craig:
Thanks your review :)
here is updated patch.
On Tue, Jun 6, 2017 at 12:45 AM, Craig Howland
<howland@lgsinnovations.com> wrote:
> On 06/03/2017 09:54 AM, Kito Cheng wrote:
>>
>> This patch let -NaN can print the right sign like glibc do[1] :)
>>
>> Ref:
>> [1]
>> https://sourceware.org/git/?p=glibc.git;a=commit;h=003c9895a89e71767ad64bafac1ca99622be2eb7
>
> For vfwprintf.c, the two assignments to sign ought to be "sign = L'-';"
> (missing the L).
>
From 93a618861e85a404a9ad7e4933dab566a55e1d5f Mon Sep 17 00:00:00 2001
From: Kito Cheng <kito.cheng@gmail.com>
Date: Sat, 3 Jun 2017 21:41:29 +0800
Subject: [PATCH] Print sign of NaN values.
---
newlib/libc/stdio/vfprintf.c | 4 ++++
newlib/libc/stdio/vfwprintf.c | 4 ++++
2 files changed, 8 insertions(+)
diff --git a/newlib/libc/stdio/vfprintf.c b/newlib/libc/stdio/vfprintf.c
index ed92bb2..3585423 100644
--- a/newlib/libc/stdio/vfprintf.c
+++ b/newlib/libc/stdio/vfprintf.c
@@ -1245,6 +1245,8 @@ reswitch: switch (ch) {
break;
}
if (isnan (_fpvalue)) {
+ if (signbit (_fpvalue))
+ sign = '-';
if (ch <= 'G') /* 'A', 'E', 'F', or 'G' */
cp = "NAN";
else
@@ -1276,6 +1278,8 @@ reswitch: switch (ch) {
break;
}
if (expt == 1) {
+ if (signbit (_fpvalue))
+ sign = '-';
if (ch <= 'G') /* 'A', 'E', 'F', or 'G' */
cp = "NAN";
else
diff --git a/newlib/libc/stdio/vfwprintf.c b/newlib/libc/stdio/vfwprintf.c
index f0179a0..4786ed6 100644
--- a/newlib/libc/stdio/vfwprintf.c
+++ b/newlib/libc/stdio/vfwprintf.c
@@ -970,6 +970,8 @@ reswitch: switch (ch) {
break;
}
if (isnan (_fpvalue)) {
+ if (signbit (_fpvalue))
+ sign = L'-';
if (ch <= L'G') /* 'A', 'E', 'F', or 'G' */
cp = L"NAN";
else
@@ -1001,6 +1003,8 @@ reswitch: switch (ch) {
break;
}
if (expt == 1) {
+ if (signbit (_fpvalue))
+ sign = L'-';
if (ch <= L'G') /* 'A', 'E', 'F', or 'G' */
cp = L"NAN";
else
--
2.7.4