From owner-freebsd-hackers Sat Aug 24 08:57:02 1996 Return-Path: owner-hackers Received: (from root@localhost) by freefall.freebsd.org (8.7.5/8.7.3) id IAA12183 for hackers-outgoing; Sat, 24 Aug 1996 08:57:02 -0700 (PDT) Received: from godzilla.zeta.org.au (godzilla.zeta.org.au [203.2.228.19]) by freefall.freebsd.org (8.7.5/8.7.3) with SMTP id IAA12178 for ; Sat, 24 Aug 1996 08:56:58 -0700 (PDT) Received: (from bde@localhost) by godzilla.zeta.org.au (8.6.12/8.6.9) id BAA01347; Sun, 25 Aug 1996 01:54:31 +1000 Date: Sun, 25 Aug 1996 01:54:31 +1000 From: Bruce Evans Message-Id: <199608241554.BAA01347@godzilla.zeta.org.au> To: freebsd-hackers@FreeBSD.org, voisine@cioe.com Subject: Re: rintf broke? Sender: owner-hackers@FreeBSD.org X-Loop: FreeBSD.org Precedence: bulk >Umm... is the rintf function broken or what? >I'm running it on an almost current freebsd system. >here's the code: >#include >#include >#include >int main() { > cout << rintf(12.3456789) << endl; >} >///////////EOF/////////// >here's the output: >12.125 This is caused by an old bug in the i386 version of gcc. rint() would be broken in the same way if double expressions were evaluated in long double precision, but FreeBSD defaults to double precision to avoid the gcc bug. Bruce *** s_rint.c~ Wed May 31 19:13:27 1995 --- s_rint.c Sun Aug 25 01:21:39 1996 *************** *** 28,35 **** #include "math_private.h" #ifdef __STDC__ ! static const double #else ! static double #endif TWO52[2]={ --- 28,42 ---- #include "math_private.h" + /* + * TWO23 is long double instead of double to avoid a bug in gcc. Without + * this, gcc thinks that TWO23[sx]+x and w-TWO23[sx] already have double + * precision and doesn't clip them to double precision when they are + * assigned and returned. Use long double even in the !__STDC__ case in + * case this is compiled with gcc -traditional. + */ #ifdef __STDC__ ! static const long double #else ! static long double #endif TWO52[2]={ *** s_rintf.c~ Wed May 31 19:13:28 1995 --- s_rintf.c Sun Aug 25 01:19:18 1996 *************** *** 21,28 **** #include "math_private.h" #ifdef __STDC__ ! static const float #else ! static float #endif TWO23[2]={ --- 21,34 ---- #include "math_private.h" + /* + * TWO23 is double instead of float to avoid a bug in gcc. Without + * this, gcc thinks that TWO23[sx]+x and w-TWO23[sx] already have float + * precision and doesn't clip them to float precision when they are + * assigned and returned. + */ #ifdef __STDC__ ! static const double #else ! static double #endif TWO23[2]={