From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 119590 invoked by alias); 14 Aug 2018 21:45:05 -0000 Mailing-List: contact cygwin-help@cygwin.com; run by ezmlm Precedence: bulk List-Id: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: cygwin-owner@cygwin.com Mail-Followup-To: cygwin@cygwin.com Received: (qmail 119542 invoked by uid 89); 14 Aug 2018 21:45:03 -0000 Authentication-Results: sourceware.org; auth=none X-Spam-SWARE-Status: No, score=-1.9 required=5.0 tests=AWL,BAYES_00,SPF_HELO_PASS autolearn=ham version=3.3.2 spammy=international, International X-HELO: mx1.redhat.com Received: from mx3-rdu2.redhat.com (HELO mx1.redhat.com) (66.187.233.73) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Tue, 14 Aug 2018 21:45:01 +0000 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.rdu2.redhat.com [10.11.54.5]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 409A741C31 for ; Tue, 14 Aug 2018 21:45:00 +0000 (UTC) Received: from [10.10.120.153] (ovpn-120-153.rdu2.redhat.com [10.10.120.153]) by smtp.corp.redhat.com (Postfix) with ESMTP id 12B311C731 for ; Tue, 14 Aug 2018 21:44:59 +0000 (UTC) Subject: Re: strtod ("nan") returns negative NaN To: cygwin@cygwin.com References: <20180814132301.GX3747@calimero.vinschen.de> <5b730d82.1c69fb81.f063b.d706@mx.google.com> <8636vgac6e.fsf@gmail.com> From: Eric Blake Message-ID: <06e75f75-6a5f-2140-7557-849290225f79@redhat.com> Date: Wed, 15 Aug 2018 00:02:00 -0000 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:52.0) Gecko/20100101 Thunderbird/52.8.0 MIME-Version: 1.0 In-Reply-To: Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 7bit X-IsSubscribed: yes X-SW-Source: 2018-08/txt/msg00195.txt.bz2 On 08/14/2018 04:31 PM, Stephen John Smoogen wrote: >> The C standard disagrees with you [ISO:IEC 9899:2011, section 5.2.4.2.2]: >> >> "An implementation may give zero and values that are not floating-point >> numbers (such as infinities and NaNs) a sign or may leave them unsigned. >> Wherever such values are unsigned, any requirement in this International >> Standard to retrieve the sign shall produce an unspecified sign, and any >> requirement to set the sign shall be ignored." >> > > Does it disagree? I would say it did if it said MUST.. but it says MAY > I thought usually meant "be consistent with what you think is right > for your environment but yeah whatever". Read conversely, if the implementation lets NaN have a sign (which Cygwin does), then retrieving and setting the sign is defined. > > And one can read the "any requirement to set the sign shall be > ignored" as being -NaN should come back as NaN. I don't know how this > is also affected by https://en.wikipedia.org/wiki/ISO/IEC_10967 which > goes to the IEEE 754 NaN is not a number (except when it is). [ > > It looks from my layman point of view that Cygwin is ok with sending > whatever they want back if it is implementation defined. However the > bigger case is whether they want to be similar to how the other > environments report things. Currently Cygwin reports -NaN for positive > NaN and 'NaN' for '-NaN'.. which may be ok but doesn't match the other > environments which all report NaN. [Does that make sense?] Cygwin is indeed buggy for turning "NaN" into -NaN; that's easy enough to fix. The remaining question is whether it should turn "-NaN" into -NaN; and the argument that glibc JUST fixed their bug 23007 to make strtod("-nan") return -NaN means that Cygwin should, indeed, preserve the negative sign bit when parsing "-nan". https://sourceware.org/bugzilla/show_bug.cgi?id=23007 So, the desired behavior: strtod("nan") -> NaN strtod("-nan") -> -NaN printf("%f", NaN) -> "NaN" printf("%f", -NaN) -> "-NaN" and similarly for float and long double. -- Eric Blake, Principal Software Engineer Red Hat, Inc. +1-919-301-3266 Virtualization: qemu.org | libvirt.org -- 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