From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 121371 invoked by alias); 9 Apr 2018 09:47:15 -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 121312 invoked by uid 89); 9 Apr 2018 09:47:12 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-102.2 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 Received: from mout.kundenserver.de (HELO mout.kundenserver.de) (212.227.126.130) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Mon, 09 Apr 2018 09:47:11 +0000 Received: from calimero.vinschen.de ([217.91.18.234]) by mrelayeu.kundenserver.de (mreue005 [212.227.15.167]) with ESMTPSA (Nemesis) id 0LfFgy-1ehMup2OMK-00on8Z for ; Mon, 09 Apr 2018 11:47:07 +0200 Received: by calimero.vinschen.de (Postfix, from userid 500) id 942AAA81ECA; Mon, 9 Apr 2018 11:47:06 +0200 (CEST) Date: Mon, 09 Apr 2018 09:47:00 -0000 From: Corinna Vinschen To: cygwin@cygwin.com Subject: Re: Floating point exception in strtod() Message-ID: <20180409094706.GO18998@calimero.vinschen.de> Reply-To: cygwin@cygwin.com Mail-Followup-To: cygwin@cygwin.com References: MIME-Version: 1.0 Content-Type: multipart/signed; micalg=pgp-sha256; protocol="application/pgp-signature"; boundary="5I6of5zJg18YgZEa" Content-Disposition: inline In-Reply-To: User-Agent: Mutt/1.9.2 (2017-12-15) X-UI-Out-Filterresults: notjunk:1;V01:K0:XyZk/y6R9Tg=:u0IkasZzkf6zUTSSQJO+rc uTsK7agH0lUHEaPEIyyHh+36gCnI5+VeMLUlcsGk40Fn/RrQEjETrrdyGba0JkwMvZ6l+EIW2 swRG2jy8eLfs0HHgxKfBUQdOioJGs7RQOv1cATgY8G3wZlmW7JZ8CnhUqXrwYL9Rx8B8qo4I/ 5mScD+69zFNoai/rzdzKBnPXHkc1dyeIUyUtipvxniFDy0DteHN92WH1ToUf5xHNxfMExSxdQ RrOkQZZG4v4WNUZFz0nCP8znw7Q4bKUK0YDFkUTvuwlKN19yiMaIJq+On1msTwBdPkf+00n8L JeghBT3W/cp1eEggAcBYyd02Nu9JQibGASsXFh8AVtSxzggONEvYAJG3dO4jVK77QeklqI8Uu /mYiO0/JSr9ESboBp1pb2276M8cdH8PkBDSKliPXCJmYIuJJ7OfPalZ9/s7ijmKokumXFBQGh 8cMX+fRH6ADfH5nmGVeWDEokA7+6kI1QfbXcy/VowRpfDn3Oef7s9XJQGb7hW1MD0BJ8mJfG5 bliw15Uc6COrhUuLsPqZCBVMJKUMSdEuCsvaclYJx91oWXala3btyojJr0iXnxH945MOzHVxS X6zg3JLwbMKXsbnaKa6NPO1iWCOb9aDDEqQlRg4jsnfzlZo+BgPGaV+dtZ+eHpvBbTp9vKj4u pgh+fkGCDC8sI9rTB6sjf1U4lWosAmC8zAWjmd2pfp24KFWQAUYhpyC2kR5vf84LnZpT+owgg 72wc1xzCgPZmiZqOpgvK8uRuRUCtsyYHVQE1Xw== X-SW-Source: 2018-04/txt/msg00067.txt.bz2 --5I6of5zJg18YgZEa Content-Type: text/plain; charset=utf-8 Content-Disposition: inline Content-Transfer-Encoding: quoted-printable Content-length: 1948 On Apr 7 13:40, Ken Brown wrote: > $ cat strtod_test.c > #include > #include > #include >=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. GDB shows that the exception occurs in newlib/libc/stdlib/strtod.c line 1189, in this statment, which looks rather inconspicious at first glance: L =3D (Long)aadj; 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. However, on 64 bit for example the assembler statement generating the FP exception is cvttsd2si %xmm0,%eax 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. 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. I'm just generating new developer snapshots. They should be available in half an hour or so on https://cygwin.com/snapshots/ FTR, the somewhat more complex strtold implementation is not affected. Corinna --=20 Corinna Vinschen Please, send mails regarding Cygwin to Cygwin Maintainer cygwin AT cygwin DOT com Red Hat --5I6of5zJg18YgZEa Content-Type: application/pgp-signature; name="signature.asc" Content-length: 833 -----BEGIN PGP SIGNATURE----- iQIzBAEBCAAdFiEEoVYPmneWZnwT6kwF9TYGna5ET6AFAlrLNpoACgkQ9TYGna5E T6D+7xAAiyS6u6tJgqH1YenrPhXz2FTsbW2YC71wqpFBi6oBlzvbZqMsBHi7t5BQ jVJt6Ctl+HYn1dNqS7rc7bcrt+4B/Ges1DsRkAXrNmxp1AClH007DM4poQAmztWo HCbSHKT/hvRtZNkyfs1vS7VG6L9UvJm4K8ijSjhvYXRDq1lXGogW0RqGsCPjB9P8 BGD5q5MaLEKCFBEOBuFO4Aafej9iuD+jsi0VITs2XdFP1u9aH2bmtS1zERnD+N9/ wtwMYE1FeqX8fbHpPZqDpcjVkOLyxdmzFAaqzlY7AIUWUypqep+0kxZpDA6VA5Wv LsN10SdKIOG3QpBCB54uYt6Z+MmIc2QM4NH21G6Aks1611A/rGrd8bnmwU/CvIpM 2igZPkj0auH5qWDAxIgzQGcp69ZB//AppllD+P5I1pJ29ChN8zYC1LTlY1YipN6q 1xMGFl9DaAlhaws5mjTxiU7tVNv5Q6mipSOrzWZZZpk34HZmJYk7WMi9Iy7OETx3 4sZyjtI2SjzOAXFdOzIBoyamDRi0ZmYVMNOETojZbK6p6OVOt521C3v942EcF9j1 DR4cBcHKIHjRSGxU/XVIITI88pjmveqz6tO4w4jMQQbbUUoIT6pngmKJ5kXN2JUO PeKC6IqRKFKPxyAf2+fSu9Yo+uDkucPGj2p8VTYuYaTODzWCWlw= =YBdK -----END PGP SIGNATURE----- --5I6of5zJg18YgZEa--