delorie.com/archives/browse.cgi | search |
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=FDWpV3maGJvZLyxUkda8pNAwX/2oXzqfIZEB0MbU9d5e7I/GPlJq8 | |
Eq66Ld1/ZS5s8BBo/VenOfDfEJO3oKVPzx2K/F2qplRCXhNAW0ZPMCnfHBBxX8WN | |
b7EmBXgh63ink5MrOwAMIyvqRtT4QIrAcupM4BJ+pIMa11EN5lE2Ro= | |
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=mLtfQtfwoqLGL4gwD2sTKjT0tyQ=; b=cqForOdOsAbwg3rO/AJD34ZOUIxy | |
wYOL7hAKkvuWX786FpeBwiBqc05Cj3rV2fYX6wV8bXe/JabvS37qO/MYqEnJfege | |
Yg5cCPwOuIuQTtjgY/atotUspDKfx5IbxwGRvK2lKjyUKlX7yWpWhZ5LvO+6NcpX | |
4G+OwHUWf/w0Qec= | |
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.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 |
Date: | Mon, 9 Apr 2018 11:47:06 +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: | <20180409094706.GO18998@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> |
MIME-Version: | 1.0 |
In-Reply-To: | <dd5e98ea-8f39-1c4b-116c-37968cb3a52d@cornell.edu> |
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== |
--5I6of5zJg18YgZEa Content-Type: text/plain; charset=utf-8 Content-Disposition: inline Content-Transfer-Encoding: quoted-printable 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. 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" -----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--
webmaster | delorie software privacy |
Copyright © 2019 by DJ Delorie | Updated Jul 2019 |