Date: Mon, 29 Mar 1999 22:00:02 -0800 (PST) From: Dave Bodenstab <imdave@mcs.net> To: freebsd-bugs@FreeBSD.org Subject: Re: bin/10863: rint(3) returns erratic results Message-ID: <199903300600.WAA04455@freefall.freebsd.org>
index | next in thread | raw e-mail
The following reply was made to PR bin/10863; it has been noted by GNATS.
From: Dave Bodenstab <imdave@mcs.net>
To: twp@rootsweb.com
Cc: FreeBSD-gnats-submit@FreeBSD.ORG
Subject: Re: bin/10863: rint(3) returns erratic results
Date: Mon, 29 Mar 1999 23:59:48 -0600
twp@rootsweb.com wrote:
>
> >Number: 10863
> >Category: bin
> >Synopsis: rint(3) returns erratic results
> >Confidential: yes
> >Severity: serious
> >Priority: low
> >Responsible: freebsd-bugs
> >State: open
> >Quarter:
> >Keywords:
> >Date-Required:
> >Class: sw-bug
> >Submitter-Id: current-users
> >Arrival-Date: Mon Mar 29 14:20:01 PST 1999
> >Closed-Date:
> >Last-Modified:
> >Originator: Tim Pierce
> >Release: FreeBSD 2.2.7-RELEASE i386
> >Organization:
> RootsWeb Genealogical Data Cooperative
> >Environment:
>
>
>
> >Description:
>
> rint(3) appears to return inconsistent results for some inputs. For
> example, it rounds both 5.5 and 6.5 to 6. If rint always rounds up,
> it should round these numbers to 6 and 7; if it always rounds down, it
> should round these numbers to 5 and 6; if it always rounds to the
> nearest integer, it should round to 6 and 7. Is there any situation
> where it would be correct to round both 5.5 and 6.5 to 6?
>
> >How-To-Repeat:
>
> #include <math.h>
>
> main()
> {
> printf ("%f\n", rint(5.5));
> printf ("%f\n", rint(6.5));
> }
>
> >Fix:
See ieeefp.h and floatingpoint.h: this is the correct behaviour
for the default rounding mode of `round to nearest'. See the
Intel manuals for the exact definition of each rounding mode...
briefly, round to nearest chooses the even number if the difference
to the next higher/lower integer is the same.
Change your program to the following and inspect the results.
#include <math.h>
#include <floatingpoint.h>
main()
{
printf( "FP_RN:\n" );
fpsetround( FP_RN );
printf ("%f\n", rint(5.5));
printf ("%f\n", rint(6.5));
printf( "FP_RM:\n" );
fpsetround( FP_RM );
printf ("%f\n", rint(5.5));
printf ("%f\n", rint(6.5));
printf( "FP_RP:\n" );
fpsetround( FP_RP );
printf ("%f\n", rint(5.5));
printf ("%f\n", rint(6.5));
printf( "FP_RZ:\n" );
fpsetround( FP_RZ );
printf ("%f\n", rint(5.5));
printf ("%f\n", rint(6.5));
}
Dave Bodenstab
imdave@mcs.net
To Unsubscribe: send mail to majordomo@FreeBSD.org
with "unsubscribe freebsd-bugs" in the body of the message
help
Want to link to this message? Use this
URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?199903300600.WAA04455>
