delorie.com/archives/browse.cgi   search  
Mail Archives: cygwin/2018/08/13/22:31:56

X-Recipient: archive-cygwin AT delorie DOT com
DomainKey-Signature: a=rsa-sha1; c=nofws; d=sourceware.org; h=list-id
:list-unsubscribe:list-subscribe:list-archive:list-post
:list-help:sender:date:message-id:to:cc:subject:from:in-reply-to
:references:mime-version:content-type:content-transfer-encoding;
q=dns; s=default; b=X8xU68ixpM4lCqaMLPkztEJLWfssYZeL70xUMU1C23/
60c1Lo6EHARfxk9M9KQKCPhvJLHvgKW3406k6BsGCT9jRaT/HngdUcy+JXtxssHa
x1TsWTOukYz0unq2lsnaHZRFrPC6fsqQ5uLU3UqJzyPUlfMp0MySwOOP+vIouaHo
=
DKIM-Signature: v=1; a=rsa-sha1; c=relaxed; d=sourceware.org; h=list-id
:list-unsubscribe:list-subscribe:list-archive:list-post
:list-help:sender:date:message-id:to:cc:subject:from:in-reply-to
:references:mime-version:content-type:content-transfer-encoding;
s=default; bh=uLkkHedLqBpuHv/jqHwcHzv6YwE=; b=iW7CRvwVdzgf0wtnu
o+S9HfJmZRqsIoCIglZXwX1mS/b6WpiB3O4mn/FEZ32qccFBGnAgUsvqoxwYpuak
BPTTrD9B+h0vb5cK8KQglcF17ay0NvbZY4WgxGh+24g7uM4PA2riscCepz1le7ZZ
vLE7ys7PRCWnugIhn+TcX0JzLE=
Mailing-List: contact cygwin-help AT cygwin DOT com; run by ezmlm
List-Id: <cygwin.cygwin.com>
List-Subscribe: <mailto:cygwin-subscribe AT cygwin DOT com>
List-Archive: <http://sourceware.org/ml/cygwin/>
List-Post: <mailto:cygwin AT cygwin DOT com>
List-Help: <mailto:cygwin-help AT cygwin DOT com>, <http://sourceware.org/ml/#faqs>
Sender: cygwin-owner AT cygwin DOT com
Mail-Followup-To: cygwin AT cygwin DOT com
Delivered-To: mailing list cygwin AT cygwin DOT com
Authentication-Results: sourceware.org; auth=none
X-Spam-SWARE-Status: No, score=-0.9 required=5.0 tests=BAYES_00,KAM_LAZY_DOMAIN_SECURITY autolearn=no version=3.3.2 spammy=H*x:version, H*UA:version, H*Ad:D*jp
X-HELO: msc13.plala.or.jp
Date: Tue, 14 Aug 2018 11:31:35 +0900 (JST)
Message-Id: <20180814.113135.1571893395887584078.trueroad@trueroad.jp>
To: cygwin AT cygwin DOT com
Cc: trueroad AT trueroad DOT jp
Subject: strtod ("nan") returns negative NaN (was `std::stod ("nan")` returns negative NaN)
From: Masamichi Hosoda <trueroad AT trueroad DOT jp>
In-Reply-To: <20180814.100952.1684125661222835312.trueroad@trueroad.jp>
References: <20180813234603_dot_GA2310_at_dimstar_dot_local_dot_net> <CANnLRdii8mX71D936AhhEYm+S0s4gS5RGgpPhV_rB6=kzmXKsw AT mail DOT gmail DOT com> <20180814 DOT 100952 DOT 1684125661222835312 DOT trueroad AT trueroad DOT jp>
Mime-Version: 1.0
X-VirusScan: Outbound; mvir-ac13; Tue, 14 Aug 2018 11:31:41 +0900

>> On Mon, 13 Aug 2018 at 19:46, Duncan Roe <duncan_roe AT optusnet DOT com DOT au> wrote:
>>>
>>> On Mon, Aug 13, 2018 at 12:52:48PM -0400, Stephen John Smoogen wrote:
>>> > On Mon, 13 Aug 2018 at 11:16, Masamichi Hosoda <trueroad AT trueroad DOT jp> wrote:
>>> [...]
>>> > On Fedora 27 with 7.3.1 it gives
>>> > ```
>>> > stod ("nan") = nan
>>> > stod ("-nan") = nan
>>> > quiet_NaN () = nan
>>> > ```
>>> [...]
>> 
>> I tested a compile on Windows Subsystem for Linux Ubuntu 18.04 which
>> had gcc 7.3.0. The output was the same as everything but Cygwin. At
>> this point it is time to pull through the gdb debugger and try to
>> figure out where it is coming from.
> 
> I suspect `cygwin1.dll`'s `strtod ()` etc.
> Here's a code.
> 
> ```
> /* gcc foobar.c */
> 
> #include <math.h>
> #include <stdio.h>
> #include <stdlib.h>
> 
> int main (void)
> {
>   printf ("strtod (\"nan\", NULL) = %f\n", strtod ("nan", NULL));
>   printf ("strtod (\"-nan\", NULL) = %f\n", strtod ("-nan", NULL));
>   printf ("nan (\"\") = %f\n", nan (""));
> 
>   return 0;
> }
> ```
> 
> Cygwin 2.10.0 64 bit with gcc 7.3.0
> ```
> strtod ("nan", NULL) = -nan
> strtod ("-nan", NULL) = nan
> nan ("") = nan
> ```
> 
> Ubuntu 16.04 LTS 64 bit with gcc 5.4.0
> ```
> strtod ("nan", NULL) = nan
> strtod ("-nan", NULL) = nan
> nan ("") = nan
> ```

If I understand correctly,
`std::stod ()` uses cygwin1.dll's `strtod ()` for the conversion.

`std::stod ()` is defined in
/usr/lib/gcc/x86_64-pc-cygwin/7.3.0/include/c++/bits/basic_string.h L6388-.
It calls `__gnu_cxx::__stoa ()` with pointer of `std::strtod ()`.

```
  inline double
  stod(const string& __str, size_t* __idx = 0)
  { return __gnu_cxx::__stoa(&std::strtod, "stod", __str.c_str(), __idx); }
```

`__gnu_cxx::__stoa ()` is defined in
/usr/lib/gcc/x86_64-pc-cygwin/7.3.0/include/c++/ext/string_conversions.h L51-.
It calls the first parameter, `std::strtod ()`.

`std::strtod ()` is cygwin1.dll's `strtod ()`.

--
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

- Raw text -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019