strtod ("nan") returns negative NaN
Corinna Vinschen
corinna-cygwin@cygwin.com
Tue Aug 14 10:39:00 GMT 2018
On Aug 14 11:56, Corinna Vinschen wrote:
> On Aug 14 13:45, Masamichi Hosoda wrote:
> > >From a50ee5a4747a99c70469a53fe959f3dc22d3b79a Mon Sep 17 00:00:00 2001
> > From: Masamichi Hosoda <trueroad@trueroad.jp>
> > Date: Tue, 14 Aug 2018 12:50:32 +0900
> > Subject: [PATCH] Fix strtod ("nan") returns qNaN
> >
> > The definition of qNaN for x86_64 and x86 was wrong.
> > So strtod ("nan") returned sNaN instead of qNaN.
> >
> > Furthermore, it was inverted the sign bit with the presence of `-` character.
> > So strtod ("-nan") returned qNaN.
> >
> > This commit fixes definition of qNaN
> > and removes the sign bit inversion when evaluating "nan".
> > ---
> > newlib/libc/stdlib/gd_qnan.h | 8 ++++----
> > newlib/libc/stdlib/strtod.c | 1 +
> > 2 files changed, 5 insertions(+), 4 deletions(-)
>
> Can you please send this patch to the newlib AT sourceware DOT org
> mailing list? As soon as something in newlib gets changed, a lot of
> other targets are affected and the guys working on those targets should
> have a chance to chime in.
Looks like strtold is affected as well, just differently:
printf ("strtod (\"nan\", NULL) = %f\n", strtod ("nan", NULL));
printf ("strtod (\"-nan\", NULL) = %f\n", strtod ("-nan", NULL));
printf ("strtold (\"nan\", NULL) = %Lf\n", strtold ("nan", NULL));
printf ("strtold (\"-nan\", NULL) = %Lf\n", strtold ("-nan", NULL));
printf ("nan (\"\") = %f\n", nan (""));
==>
strtod ("nan", NULL) = -nan
strtod ("-nan", NULL) = nan
strtold ("nan", NULL) = -nan
strtold ("-nan", NULL) = -nan
nan ("") = nan
so it prints always -nan.
With your patch, strtold looks more correct, but it still prints the
sign of NaN:
strtod ("nan", NULL) = nan
strtod ("-nan", NULL) = nan
strtold ("nan", NULL) = nan
strtold ("-nan", NULL) = -nan
nan ("") = nan
Question: What's wrong with that? Wouldn't it be more correct if
strtod returns -NaN for "-nan" as well?
Corinna
--
Corinna Vinschen Please, send mails regarding Cygwin to
Cygwin Maintainer cygwin AT cygwin DOT com
Red Hat
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 833 bytes
Desc: not available
URL: <http://cygwin.com/pipermail/cygwin/attachments/20180814/c6bfca89/attachment.sig>
More information about the Cygwin
mailing list