delorie.com/archives/browse.cgi   search  
Mail Archives: cygwin/2018/04/09/08:51:18

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:from:to:subject:message-id:reply-to
:references:mime-version:content-type:in-reply-to; q=dns; s=
default; b=Fh/bSy6wJN002exCu6GL8XVlMCcX3tORvTsAGxQmmDiIF0WPPSe0K
nBDe9mjTsW03taSFcIO3mBleTNfUNAP0u9kNv/Y8xfxrM/urygRGN4LZCPpmEtqj
cuuRvtkzASt5zEPqV3O7T2ya38VbqsJBMgBEH1OpW8GlZI9eMm0vpA=
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:from:to:subject:message-id:reply-to
:references:mime-version:content-type:in-reply-to; s=default;
bh=+bn2OdQ11E9cP+MjlhrlLv3uK+Y=; b=rIjRD6qN2gsvfqi30wuuiKRdi2O/
phSejnr9E+PqmDPBdec9sxGN5V6lE1P7hX+koxn2f1LB0bd7VEhLI8azHtzH5a7G
gBjbV66c2Owi5/aiFJgM/kVNxCVhDYT0rI6H8eDRLbnKXx6uEdsfNl48daSAZov+
reU0Lz9MH1X8K/Y=
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-Virus-Found: No
X-Spam-SWARE-Status: No, score=-102.0 required=5.0 tests=AWL,BAYES_00,GOOD_FROM_CORINNA_CYGWIN,KAM_LAZY_DOMAIN_SECURITY,RCVD_IN_DNSWL_NONE autolearn=ham version=3.3.2 spammy=
X-HELO: mout.kundenserver.de
Date: Mon, 9 Apr 2018 14:51:02 +0200
From: Corinna Vinschen <corinna-cygwin AT cygwin DOT com>
To: cygwin AT cygwin DOT com
Subject: Re: Floating point exception in strtod()
Message-ID: <20180409125102.GC29703@calimero.vinschen.de>
Reply-To: cygwin AT cygwin DOT com
Mail-Followup-To: cygwin AT cygwin DOT com
References: <dd5e98ea-8f39-1c4b-116c-37968cb3a52d AT cornell DOT edu> <20180409094706 DOT GO18998 AT calimero DOT vinschen DOT de> <c4afb320-e963-adf8-ea74-4c625729336c AT cornell DOT edu>
MIME-Version: 1.0
In-Reply-To: <c4afb320-e963-adf8-ea74-4c625729336c@cornell.edu>
User-Agent: Mutt/1.9.2 (2017-12-15)
X-UI-Out-Filterresults: notjunk:1;V01:K0:qC+qzLblGEU=:RhaZitWUwL5NwJkPw5gWSx dRaKjwcvI7URooGqX+KMA/AhS2eO/NEKHn8Drv4iJsfGU2jdvqXbo8FoQtaqqNgno3XIx7VAk 8RYHoZgxx2Y68WIVgrB4VAuEU1GAKYSOHoYcycofOjCjXuXAaPrc8npvGxJh8ZCo2oaWtjb1o F7G6yn6MgmbTUiRifl8DVwyghbbGOvhKgbEmm6ewgjTyKSWMMmkb4+O91hJ/nb97ild8d1BQY oHkjX5dJ6TDrMsQS6YLS7hRpiuJcdnUH882tVOJs2q1XCxaMZKDK0Al8T04ncVvYR5ahlbSff cjimOgv46xkn8FQilyyrLjF+HCzSKAppDVSLdwzOPVAWtyPBxoOrFdhpZwcfchcDTi1WeaW1x OXL5edFx1vzYewC3FmKr92vuWajJnBKicjisPzUsWbARID9v2mkrYlXd9F5O1kx9sbaijxXlq G3UZ1j/9/7PGj4MU6NIt972cfnww1inwur863bVHpjA8gMGbElJ55oM2LRGeg/1AHBY+L9n9m 5HIHT9WFDa8A24qxNHStf/ZKQDkoA0zi1iBeR8p+5NNIeVtJxEN1Qb1e8CuM7v3hHEvNdr3ku u2AIACHOZUDcdW+lj2aI4EFS9aaQ4bj006oj58dqMlQN9OYZou8gYTFMWYyAdYDlHYmKrPHVg 3z3cmZHOOaGGVCC/WCYpWvR+g7ReMg9UaOFQnSpTFZK5LjvVzAub0DJvohWlRpcQrvWlDJZDW cW6v09Ma3ZC9i7uPBYvOVB174854p3zdyWdvYA==

--ikeVEW9yuYc//A+q
Content-Type: text/plain; charset=utf-8
Content-Disposition: inline
Content-Transfer-Encoding: quoted-printable

On Apr  9 08:09, Ken Brown wrote:
> On 4/9/2018 5:47 AM, Corinna Vinschen wrote:
> > On Apr  7 13:40, Ken Brown wrote:
> > > $ cat strtod_test.c
> > > #include <stdio.h>
> > > #include <stdlib.h>
> > > #include <fenv.h>
> > >=20
> > > int
> > > main ()
> > > {
> > >    /* The following number comes from /usr/share/asymptote/ode.asy.  =
*/
> > >    const char *str =3D "121645100408832000.0";
> > >    char *ptr;
> > >=20
> > >    feenableexcept (FE_INVALID);
> > >    strtod (str, &ptr);
> > >=20
> > >    /* If there was an exception, the following will not get executed.=
  */
> > >    printf ("No exception.\n");
> > > }
> > >=20
> > > $ gcc strtod_test.c
> > >=20
> > > $ ./a
> > > Floating point exception (core dumped)
> > >=20
> > > [The above was on x86.  On x86_64 there's simply no output.]
> > >=20
> > > I have no idea what's special about the number 121645100408832000.0, =
but the
> > > problem goes away if, for example, I replace the leading 1 by 2.
> >=20
> > GDB shows that the exception occurs in newlib/libc/stdlib/strtod.c
> > line 1189, in this statment, which looks rather inconspicious at
> > first glance:
> >=20
> >     L =3D (Long)aadj;
> >=20
> > L is of type Long =3D=3D int32_t, aadj is of type double.  The
> > value of aadj at this time is 2529648000.0 =3D=3D 0x96c75d80 which
> > appears to be perfectly valid for a 32 bit int.
> >=20
> > However, on 64 bit for example the assembler statement generating the FP
> > exception is
> >=20
> >    cvttsd2si %xmm0,%eax
> >=20
> > It is documented that this statemnt may raise FE_INVALID or FE_INEXACT
> > exceptions.  The problem is that the generated 32 bit value is a
> > negative signed int value, while the source operand is positive.  So the
> > conversion is, in fact, invalid.
> >=20
> > I applied a fix to newlib's strtod, to always use 64 bit ints in this
> > place.  This fixes the problem and no exception is raised.
>=20
> Thanks for the explanation and the quick fix.  I'm sorry for causing
> confusion by also sending this to the newlib list.

No, that's fine.  Actually it belonged to the newlib ML in the first
place, so it's good it's in the archives there.


Thanks,
Corinna

--=20
Corinna Vinschen                  Please, send mails regarding Cygwin to
Cygwin Maintainer                 cygwin AT cygwin DOT com
Red Hat

--ikeVEW9yuYc//A+q
Content-Type: application/pgp-signature; name="signature.asc"

-----BEGIN PGP SIGNATURE-----

iQIzBAEBCAAdFiEEoVYPmneWZnwT6kwF9TYGna5ET6AFAlrLYbYACgkQ9TYGna5E
T6DrTA/+PGL70sMGJoISCwwhRV9wtoIH7Tn4cK1Yu7RgApUX1nHCmdMR8xJYUcp0
W2dfq2/mldBldB6aLtu6Cgr+ITAmeRZFL5KyNU2GIGX9F49O7Qt5A/79uOYeLqK3
tqJzDF25tLCigP+6oFb4j1mnBGZqgQv0oRLMt/fuBhHRQHTvCjDyEJvafnKwT+Vc
FcloRqN8fnz9PTiHM4RtivaLxNvq6NDdy8KDLdVPm/LMNppfs383c7CMh2C97o9f
zfpONki06xxrtlMb5zWfJvTCgjDQnwP2sYGPBHOq0WZMARcS29sh//uPgrbNwdsq
+h8GTuv4jNLwXiEScUZj9o0I5QOl7rSXFsOcXRE7Mpagtd1g8s16lCYVww/9yd9Z
HOll4rOdNInDGTTbNJrAdvhz3Plh47ajQG9P+1VbJvjVpD/y3S653iCfKh+Wo0R0
2iBYsL4Rc3Lp0CnzlfjGAQ408y/fRCqgRoGatvRquRuyV3kjFWKVtKfBBoioLzpe
VdoRPDhoOWX9AJAscM9yW1kPLrW72XT51hWvYPZDGWkONiTrSmmZwNqkdbujF1fP
2Mq++nvDOjr6NndI2EpGU2O7or/lOSYFDxKivZObZUiGIQsKXiNj+bkRL2Q19+Pu
RZGKG1W8cemmOyqrbVfm5E08KXe5Ge2gFFkjlO5O7tgfyGa0K2g=
=ye5h
-----END PGP SIGNATURE-----

--ikeVEW9yuYc//A+q--

- Raw text -


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