From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 33985 invoked by alias); 9 Jul 2018 19:07:35 -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 33962 invoked by uid 89); 9 Jul 2018 19:07:35 -0000 Authentication-Results: sourceware.org; auth=none X-Spam-SWARE-Status: No, score=-101.3 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 Jul 2018 19:07:33 +0000 Received: from calimero.vinschen.de ([24.134.7.25]) by mrelayeu.kundenserver.de (mreue001 [212.227.15.167]) with ESMTPSA (Nemesis) id 0MfvWO-1fQYnX0TBs-00NBNM for ; Mon, 09 Jul 2018 21:07:31 +0200 Received: by calimero.vinschen.de (Postfix, from userid 500) id 089BFA8061D; Mon, 9 Jul 2018 21:07:30 +0200 (CEST) Date: Mon, 09 Jul 2018 19:07:00 -0000 From: Corinna Vinschen To: cygwin@cygwin.com Subject: Re: FPE in localtime.cc Message-ID: <20180709190729.GF27673@calimero.vinschen.de> Reply-To: cygwin@cygwin.com Mail-Followup-To: cygwin@cygwin.com References: <20180709164947.GE27673@calimero.vinschen.de> MIME-Version: 1.0 Content-Type: multipart/signed; micalg=pgp-sha256; protocol="application/pgp-signature"; boundary="RYJh/3oyKhIjGcML" Content-Disposition: inline In-Reply-To: User-Agent: Mutt/1.9.2 (2017-12-15) X-SW-Source: 2018-07/txt/msg00086.txt.bz2 --RYJh/3oyKhIjGcML Content-Type: text/plain; charset=utf-8 Content-Disposition: inline Content-Transfer-Encoding: quoted-printable Content-length: 2075 On Jul 9 11:16, Brian Inglis wrote: > On 2018-07-09 10:49, Corinna Vinschen wrote: > > On Jul 9 15:47, Lavrentiev, Anton (NIH/NLM/NCBI) [C] wrote: > >> Hello, > >> > >> the following sample coredumps with FPE at localhost.cc:1962 with the = latest snapshot (6/29/2018): > ... > > You can simplify your testcase by not calling any time functions: > >=20 > > #define _GNU_SOURCE > > #include > > #include > > #include > >=20 > > #define SECSPERDAY 86400 > >=20 > > int main(int argc, char **argv) > > { > > feenableexcept(FE_ALL_EXCEPT); > > long tdays =3D argc > 1 ? strtol (argv[1], NULL, 10) : 189; > > long seconds =3D tdays * SECSPERDAY + 0.5; > > printf ("%ld\n", seconds); > > } > >=20 > > This generates a SIGFPE on Linux as well. > >=20 > > The line computing seconds is the same line as used by the localtime > > function. Cygwin shares the entire localtime code with the various > > BSDs, so I guess they would have the same problem. > What is that line meant to do? Am I missing something? > It should be the equivalent of (tdays*SECSPERDAY*2 + 1)/2! > It converts an integer value to double, adds 1/2, and throws it away on > conversion back, unless the intermediate has insufficient mantissa bits, = in > which case, it loses the low bits? You may want to ask the original author why he used FP arithmetic in this place. Maybe it's a way to avoid integer overflow. I'm reluctant to change this given that this code is still used in BSD as well. > > Bottom line is, don't bulk enable FP exceptions, but only if you really > > need it for certain parts of your code. Don't expect library functions > > to be SIGFPE clean under all circumstances. >=20 > Maybe selectively enable specific FPEs to check for where needed. > Or be careful what you wish for, as you just might get a lot more than you > bargained for ;^> That's what I meant. Corinna --=20 Corinna Vinschen Please, send mails regarding Cygwin to Cygwin Maintainer cygwin AT cygwin DOT com Red Hat --RYJh/3oyKhIjGcML Content-Type: application/pgp-signature; name="signature.asc" Content-length: 833 -----BEGIN PGP SIGNATURE----- iQIzBAEBCAAdFiEEoVYPmneWZnwT6kwF9TYGna5ET6AFAltDsnEACgkQ9TYGna5E T6Dazg//R9tlHG5qVRKSI8jtW7bnzvjPExX164/Xkht4GdJF4CUeGEk3QNwyEEKc bo4V02W3u5TzlJZVae65tmDZ0DTkhHoF+bxWnD6VcjCCZn2Ezd+oW2+gk8SYSZyy lKKKJSW2Kyyg+qW3wlAviP6UBXbZ0M25BUhI6qzCVW4/9NxEZxPkvkJZHyMS/AID NqtAV6LfUyCb0oeyMacKAngVVj943bVeZMttVldiILlaiHIE9vtS8EqflfxJUwTb R1UG0SJyueK0gzg8XcIa/kOKn6mArjA2RamzK9F+TlK4yQI9KD1s6QEJCCMAxSt7 0Qdu0R6Ji42Yy9NuEF4Db2q58RE0OMgfwwJXojtfJHBkSRDDb6ZyIDsrDLsnb6aO HZkTWfBVs+F61QETw/moDw1WfB7fhlG7dAHC5EkSpiSsc1wi+9tUtVAwCmgk6ShK 3UmXDrW1IPBWuaCgcHdBvWixqV2M6Ns9ddM/z1PMu45JNf3QQn6yrAFuGBFNbt48 JudTd5SA7jC7hu+FKpppkHRPBG7fWxmnVREq+qNwlO+yxhBQ7+TTvKpb079jmcI/ /85xfTiDV9YP5BjAD1cGeZxQmS5ducnl/WwFdmYVS+iOBYcHdtDaxsgyOdyd0qh7 +8Cr54Hqkb0pvc51KHe2B5ALUGnxycuF0hsWNOE2qugOYuuMRwY= =w5Hc -----END PGP SIGNATURE----- --RYJh/3oyKhIjGcML--