From owner-freebsd-bugs Mon Mar 29 22: 0:21 1999 Delivered-To: freebsd-bugs@freebsd.org Received: from freefall.freebsd.org (freefall.FreeBSD.ORG [204.216.27.21]) by hub.freebsd.org (Postfix) with ESMTP id 239A11595C for ; Mon, 29 Mar 1999 22:00:19 -0800 (PST) (envelope-from gnats@FreeBSD.org) Received: (from gnats@localhost) by freefall.freebsd.org (8.9.2/8.9.2) id WAA04455; Mon, 29 Mar 1999 22:00:02 -0800 (PST) (envelope-from gnats@FreeBSD.org) Date: Mon, 29 Mar 1999 22:00:02 -0800 (PST) Message-Id: <199903300600.WAA04455@freefall.freebsd.org> To: freebsd-bugs@FreeBSD.org Cc: From: Dave Bodenstab Subject: Re: bin/10863: rint(3) returns erratic results Reply-To: Dave Bodenstab Sender: owner-freebsd-bugs@FreeBSD.ORG Precedence: bulk X-Loop: FreeBSD.org The following reply was made to PR bin/10863; it has been noted by GNATS. From: Dave Bodenstab 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 > > 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 #include 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