public inbox for cygwin@cygwin.com
 help / color / mirror / Atom feed
From: Heavenly Avenger <avenger@avenger.ws>
To: cygwin@cygwin.com
Subject: Re: strtod ("nan") returns negative NaN
Date: Tue, 14 Aug 2018 15:35:00 -0000	[thread overview]
Message-ID: <6074ccd0-84a3-5395-4902-33028de1d9a4@avenger.ws> (raw)
In-Reply-To: <20180815.000539.1012490218433540835.trueroad@trueroad.jp>

Here's the result for a gentoo with the same code provided by Masamichi 
Hosoda.

Linux ethereal 4.14.32-std522-amd64 #2 SMP Sat Mar 31 20:05:28 UTC 2018 
x86_64 Intel(R) Xeon(R) CPU E5-2670 v2 @ 2.50GHz GenuineIntel GNU/Linux

strtof ("nan", NULL) = nan
strtof ("-nan", NULL) = nan
strtod ("nan", NULL) = nan
strtod ("-nan", NULL) = nan
strtold ("nan", NULL) = nan
strtold ("-nan", NULL) = nan

This further supports the reasoning to always return just 'nan'.


On 8/14/2018 12:05 PM, Masamichi Hosoda wrote:
> Hi
>
> I've found that strtod ("nan") returns negative NaN on Cygwin 64 bit.
> https://cygwin.com/ml/cygwin/2018-08/msg00168.html
>
> On Linux with glibc, both strtod ("nan")
> and strtod ("-nan") return positive NaN.
>
> So I've created the patch that behaves like glibc.
> Both strtod ("nan") and strtod ("-nan") return positive NaN.
>
> Sample code:
> ```
> #include <stdio.h>
> #include <stdlib.h>
>
> int main (void)
> {
>    printf ("strtof (\"nan\", NULL) = %f\n", strtof ("nan", NULL));
>    printf ("strtof (\"-nan\", NULL) = %f\n", strtof ("-nan", NULL));
>    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));
> }
> ```
>
> The result of Cygwin (newlib) without my patch:
> ```
> strtof ("nan", NULL) = nan
> strtof ("-nan", NULL) = nan
> strtod ("nan", NULL) = -nan
> strtod ("-nan", NULL) = nan
> strtold ("nan", NULL) = -nan
> strtold ("-nan", NULL) = -nan
> ```
>
> The result of Linux (glibc, Ubuntu 16.04):
> ```
> strtof ("nan", NULL) = nan
> strtof ("-nan", NULL) = nan
> strtod ("nan", NULL) = nan
> strtod ("-nan", NULL) = nan
> strtold ("nan", NULL) = nan
> strtold ("-nan", NULL) = nan
> ```
>
> The result of FreeBSD 10.1 (BSD libc):
> ```
> strtof ("nan", NULL) = nan
> strtof ("-nan", NULL) = nan
> strtod ("nan", NULL) = nan
> strtod ("-nan", NULL) = nan
> strtold ("nan", NULL) = nan
> strtold ("-nan", NULL) = nan
> ```
>
> The result of Cygwin (newlib) with my patch:
> ```
> strtof ("nan", NULL) = nan
> strtof ("-nan", NULL) = nan
> strtod ("nan", NULL) = nan
> strtod ("-nan", NULL) = nan
> strtold ("nan", NULL) = nan
> strtold ("-nan", NULL) = nan
> ```
>
> Thanks.
>
>
> --
> Problem reports:       http://cygwin.com/problems.html
> FAQ:                   http://cygwin.com/faq/
> Documentation:         http://cygwin.com/docs.html
> Unsubscribe info:      http://cygwin.com/ml/#unsubscribe-simple


--
Problem reports:       http://cygwin.com/problems.html
FAQ:                   http://cygwin.com/faq/
Documentation:         http://cygwin.com/docs.html
Unsubscribe info:      http://cygwin.com/ml/#unsubscribe-simple

  parent reply	other threads:[~2018-08-14 15:25 UTC|newest]

Thread overview: 32+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-08-13 15:16 `std::stod ("nan")` " Masamichi Hosoda
2018-08-13 16:53 ` Stephen John Smoogen
2018-08-13 23:46   ` Duncan Roe
2018-08-14  0:46     ` Stephen John Smoogen
2018-08-14  1:10       ` Masamichi Hosoda
2018-08-14  2:31         ` strtod ("nan") returns negative NaN (was `std::stod ("nan")` returns negative NaN) Masamichi Hosoda
2018-08-14  3:25           ` strtod ("nan") returns negative NaN Steven Penny
2018-08-14  4:46           ` Masamichi Hosoda
2018-08-14  9:56             ` Corinna Vinschen
2018-08-14 10:39               ` Corinna Vinschen
2018-08-14 12:18                 ` Masamichi Hosoda
2018-08-14 13:23                   ` Corinna Vinschen
2018-08-14 13:41                     ` Stephen John Smoogen
2018-08-14 15:25                     ` Heavenly Avenger
2018-08-14 15:54                       ` Corinna Vinschen
2018-08-14 17:08                         ` Heavenly Avenger
2018-08-14 16:05                     ` Masamichi Hosoda
2018-08-14 19:24                     ` Steven Penny
2018-08-14 21:45                       ` Andy Moreton
2018-08-14 22:23                         ` Stephen John Smoogen
2018-08-15  0:02                           ` Eric Blake
2018-08-15  7:36                             ` Steven Penny
2018-08-21  3:18                             ` Brian Inglis
2018-08-14 19:44                 ` Achim Gratz
2018-08-21 13:28                   ` Brian Inglis
2018-08-14 15:05               ` Masamichi Hosoda
2018-08-14 15:21                 ` Masamichi Hosoda
2018-08-14 15:35                 ` Heavenly Avenger [this message]
2018-08-14 20:05                 ` Joseph Myers
2018-08-14 20:19                   ` Joseph Myers
2018-08-15  8:51                   ` Masamichi Hosoda
2018-08-15 12:55                     ` Masamichi Hosoda

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=6074ccd0-84a3-5395-4902-33028de1d9a4@avenger.ws \
    --to=avenger@avenger.ws \
    --cc=cygwin@cygwin.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).