Skip site navigation (1)Skip section navigation (2)
Date:      Sun, 25 Aug 1996 01:54:31 +1000
From:      Bruce Evans <bde@zeta.org.au>
To:        freebsd-hackers@FreeBSD.org, voisine@cioe.com
Subject:   Re: rintf broke?
Message-ID:  <199608241554.BAA01347@godzilla.zeta.org.au>

next in thread | raw e-mail | index | archive | help
>Umm... is the rintf function broken or what?
>I'm running it on an almost current freebsd system.
>here's the code:

>#include <stdlib.h>
>#include <iostream.h>
>#include <math.h>

>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]={



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?199608241554.BAA01347>