From mboxrd@z Thu Jan 1 00:00:00 1970 X-Msuck: nntp://news.gmane.org/gmane.linux.lib.musl.general/14733 Path: news.gmane.org!.POSTED.blaine.gmane.org!not-for-mail From: "Anastasios" Newsgroups: gmane.linux.lib.musl.general Subject: Re: Bug report: strtod drops LSB Date: Wed, 25 Sep 2019 13:11:03 -0500 Message-ID: <78fbaffa-9dc5-4b80-b93f-98a329f0d3f6@getmailbird.com> References: <20190925155151.GV9017@brightrain.aerifal.cx> Reply-To: musl@lists.openwall.com Mime-Version: 1.0 Content-Type: multipart/alternative; boundary="----=_NextPart_9948257.380420994700" Injection-Info: blaine.gmane.org; posting-host="blaine.gmane.org:195.159.176.226"; logging-data="20771"; mail-complaints-to="usenet@blaine.gmane.org" User-Agent: Mailbird/2.6.1.0 Cc: "" To: "Rich Felker" Original-X-From: musl-return-14749-gllmg-musl=m.gmane.org@lists.openwall.com Wed Sep 25 20:46:00 2019 Return-path: Envelope-to: gllmg-musl@m.gmane.org Original-Received: from mother.openwall.net ([195.42.179.200]) by blaine.gmane.org with smtp (Exim 4.89) (envelope-from ) id 1iDCIa-0005Et-9n for gllmg-musl@m.gmane.org; Wed, 25 Sep 2019 20:46:00 +0200 Original-Received: (qmail 11336 invoked by uid 550); 25 Sep 2019 18:45:55 -0000 Mailing-List: contact musl-help@lists.openwall.com; run by ezmlm Precedence: bulk List-Post: List-Help: List-Unsubscribe: List-Subscribe: List-ID: Original-Received: (qmail 32506 invoked from network); 25 Sep 2019 18:11:27 -0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=yahoo.com; s=s2048; t=1569435075; bh=Edl2uhTExdeAJaWoG3w1bWdkUh2bnqdrV+VhEV/wkpg=; h=Date:Subject:From:To:Cc:In-Reply-To:References:From:Subject; b=iYixnDl3Kgr/3fO7VweEkNIMfW6mrHqLBbofS0iljsEsXQETEKKowwt2oa2fbonrxh07Y+bAsYGfCa+FjXnjzvDG1dNfxx1S1bN1QbHUPZVGOA4akv/sZkzbFl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YXXyQFOqnLMedA6CX8B5t5D8FreqR_dc In-Reply-To: X-Mailbird-ID: 78fbaffa-9dc5-4b80-b93f-98a329f0d3f6@getmailbird.com Xref: news.gmane.org gmane.linux.lib.musl.general:14733 Archived-At: ------=_NextPart_9948257.380420994700 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable For the record, this is the program I used to confirm that it's a duplicate: =C2=A0 =C2=A0=C2=A0#include =C2=A0 =C2=A0=C2=A0#include =C2=A0 =C2=A0=C2=A0void main() { =C2=A0 =C2=A0=C2=A0=C2=A0 =C2=A0 unsigned short control_word =3D 0x37f; =C2=A0 =C2=A0=C2=A0=C2=A0 =C2=A0=C2=A0asm ("fldcw %0" : : "m" (control_word= )); =C2=A0 =C2=A0=C2=A0=C2=A0 =C2=A0 printf("%lf\n", strtod("283686952306183", = NULL)); =C2=A0 =C2=A0 } Perhaps it can help if anyone on WSL reports this again. On 9/25/2019 12:56:35 PM, Anastasios wrote: Having looked into it more, I found this is due to being on WSL, and it is = a duplicate of=C2=A0https://github.com/microsoft/WSL/issues/830 [https://gi= thub.com/microsoft/WSL/issues/830], which, I see, you are already well awar= e of. Please excuse the noise. On 9/25/2019 10:51:53 AM, Rich Felker wrote: On Wed, Sep 25, 2019 at 09:32:35AM -0500, Anastasios wrote: > Hello, > > Consider this program, strtod.c: > > =C2=A0 =C2=A0=C2=A0#include > =C2=A0 =C2=A0=C2=A0#include > > =C2=A0 =C2=A0=C2=A0int main() > =C2=A0 =C2=A0=C2=A0{ > =C2=A0 =C2=A0=C2=A0=C2=A0 =C2=A0=C2=A0printf("%lf\n", strtod("28368695230= 6183", NULL)); > =C2=A0 =C2=A0=C2=A0} > > With current musl master from Git: > > =C2=A0 =C2=A0=C2=A0$ musl-gcc -static strtod.c -o a.musl > =C2=A0 =C2=A0 $ ./a.musl > =C2=A0 =C2=A0 283686952306176.000000 > > By comparison, with glibc: > > =C2=A0 =C2=A0 $ gcc -static strtod.c -o a.glibc > =C2=A0 =C2=A0 $ ./a.glibc > =C2=A0 =C2=A0 283686952306183.000000 > > The correct binary representation of this float is > > =C2=A0 =C2=A0 0x42f0203040506070 > > but musl strtod produces > > =C2=A0 =C2=A0 0x42f0203040506000 > > i.e., it fails to set the LSB. I examined this while ruling out printf as= the cause. I can't reproduce this. My test program for strtod shows, for the input "283686952306183": d: 283686952306183 [0x1.020304050607p+48] [42f0203040506070] I suspect you miscompiled musl, possibly by passing in CFLAGS (perhaps from defaults in your environment?) that break floating point semantics. We test for and refuse to build if __FAST_MATH__ is defined, but GCC only defines it if you use -ffast-math, not if you manually enable one or more of the individual broken options that -ffast-math enables. Alternatively, it's possible that you have a broken compiler version that miscompiles floating point code. Rich ------=_NextPart_9948257.380420994700 Content-Type: text/html; charset="utf-8" Content-Transfer-Encoding: quoted-printable
=0A =0A = =0A = =0A =0A = =0A For the record, th= is is the program I used to confirm that it's a duplicate:
=0A =0A =

    #include &= lt;stdlib.h>
   = ; #include <stdio.h>
<= br>
    void main() {
    &= nbsp;   unsigned short control_word =3D 0x37f;
    <= /span>    asm ("fldcw %0" : : "m" (cont= rol_word));
  &n= bsp;     printf("%lf\= n", strtod("283686952306183", NULL));
    }

Perhaps it can help if anyone on WSL reports this again.
=0A

On 9/25/2019 12:56:35 PM, Anastasios <= antonbachin@yahoo.com> wrote:

Having looked into it more, I found this= is due to being on WSL, and it is a duplicate of https://github.com/microsoft/WSL/issues= /830, which, I see, you are already well aware of. Please excuse the no= ise.
=0A

On 9/25/2019 10:51:53 AM, Rich Felker <dal= ias@libc.org> wrote:

On Wed, Sep 25, 2019 at 09:32:35AM -0500, Anastasios wrote:=0A
>= ; Hello,=0A
> =0A
> Consider this program, strtod.c:=0A
>= =0A
>     #include =0A
>    = ; #include =0A
> =0A
>     int mai= n()=0A
>     {=0A
>       &n= bsp; printf("%lf\n", strtod("283686952306183", NULL));=0A
> &nbs= p;   }=0A
> =0A
> With current musl master from Git:= =0A
> =0A
>     $ musl-gcc -static strtod.c -o a= .musl=0A
>     $ ./a.musl=0A
>     28368695= 2306176.000000=0A
> =0A
> By comparison, with glibc:=0A
>= =0A
>     $ gcc -static strtod.c -o a.glibc=0A
> &nb= sp;   $ ./a.glibc=0A
>     283686952306183.000000=0A> =0A
> The correct binary representation of this float is=0A> =0A
>     0x42f0203040506070=0A
> =0A
> b= ut musl strtod produces=0A
> =0A
>     0x42f020304050= 6000=0A
> =0A
> i.e., it fails to set the LSB. I examined this = while ruling out printf as the cause.=0A
=0A
I can't reproduce this. = My test program for strtod shows, for the=0A
input "283686952306183":=0A=
=0A
d: 283686952306183 [0x1.020304050607p+48] [42f0203040506070]=0A=
=0A
I suspect you miscompiled musl, possibly by passing in CFLAGS (p= erhaps=0A
from defaults in your environment?) that break floating point= =0A
semantics. We test for and refuse to build if __FAST_MATH__ is=0Adefined, but GCC only defines it if you use -ffast-math, not if you=0A
= manually enable one or more of the individual broken options that=0A
-ff= ast-math enables.=0A
=0A
Alternatively, it's possible that you have a= broken compiler version=0A
that miscompiles floating point code.=0A
= =0A
Rich=0A
------=_NextPart_9948257.380420994700--