From owner-freebsd-chat Wed Oct 21 14:40:21 1998 Return-Path: Received: (from majordom@localhost) by hub.freebsd.org (8.8.8/8.8.8) id OAA15780 for freebsd-chat-outgoing; Wed, 21 Oct 1998 14:40:21 -0700 (PDT) (envelope-from owner-freebsd-chat@FreeBSD.ORG) Received: from quackerjack.cc.vt.edu (quackerjack.cc.vt.edu [198.82.160.250]) by hub.freebsd.org (8.8.8/8.8.8) with ESMTP id OAA15731; Wed, 21 Oct 1998 14:40:07 -0700 (PDT) (envelope-from jobaldwi@vt.edu) Received: from sable.cc.vt.edu (sable.cc.vt.edu [128.173.16.30]) by quackerjack.cc.vt.edu (8.8.8/8.8.8) with ESMTP id RAA06458; Wed, 21 Oct 1998 17:39:27 -0400 (EDT) Received: from john.baldwinfamily.org (jobaldwi.campus.vt.edu [198.82.67.63]) by sable.cc.vt.edu (8.8.8/8.8.8) with ESMTP id RAA28100; Wed, 21 Oct 1998 17:39:24 -0400 (EDT) Message-ID: X-Mailer: XFMail 1.3 [p0] on FreeBSD X-Priority: 3 (Normal) Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 8bit MIME-Version: 1.0 In-Reply-To: <199810211828.LAA01093@dingo.cdrom.com> Date: Wed, 21 Oct 1998 17:39:25 -0400 (EDT) Reply-To: jobaldwi@vt.edu Organization: Virginia Tech From: John Baldwin To: Mike Smith Subject: Re: Bug in rintf()?... Cc: freebsd-chat@FreeBSD.ORG, bde@FreeBSD.ORG, Bruce Evans Sender: owner-freebsd-chat@FreeBSD.ORG Precedence: bulk X-Loop: FreeBSD.org -----BEGIN PGP SIGNED MESSAGE----- On 21-Oct-98 Mike Smith wrote: >> >> I've been having a problem with rintf() not rounding properly, and I >> >> don't >> >> understand the code in /usr/src/libm/common_source/floor.c well enough to >> >> figure out where it is going wrong. Here is the problem I'm having >> >> though: >> > >> >We actually use the Sun-supplied math library, so you should be looking >> >at src/lib/msun/src/s_rintf.c >> > >> >> rintf(3.5) returns 4.0 >> >> rintf(3910.5) returns 3910.0 (should return 3911.0) >> >> This seems to be correct. rintf() rounds to the nearest integer according >> to the prevailing rounding mode. The default prevailing rounding mode >> is round-to-even. rintf() even seems to get this right for all the >> other rounding modes (towards +Inf, towards -Inf and towards 0). > > Where do you set the rounding mode? The only reference I could find > was fpsetround(), which offers nearest, -inf, +inf and truncate. > > math(3) lists 3 types for ieee754 (+inf, -inf and 0). fpsetround(3) lists 4 types that are in an enum type. Here's a sample run demonstrating all four modes. v1=3.5 v2=4.5 r(x) = rintf(x): FP_RN: v1 = 3.500000 ; r(v1) = 4.000000 ; v2 = 4.500000 ; r(v2) = 4.000000 FP_RM: v1 = 3.500000 ; r(v1) = 3.000000 ; v2 = 4.500000 ; r(v2) = 4.000000 FP_RP: v1 = 3.500000 ; r(v1) = 4.000000 ; v2 = 4.500000 ; r(v2) = 5.000000 FP_RZ: v1 = 3.500000 ; r(v1) = 3.000000 ; v2 = 4.500000 ; r(v2) = 4.000000 Thus, for "normal" rounding, FP_RP (round to plus infinity) seems to be the desired mode. > -- > \\ Sometimes you're ahead, \\ Mike Smith > \\ sometimes you're behind. \\ mike@smith.net.au > \\ The race is long, and in the \\ msmith@freebsd.org > \\ end it's only with yourself. \\ msmith@cdrom.com - --- John Baldwin -- http://members.freedomnet.com/~jbaldwin/ PGP Key: http://members.freedomnet.com/~jbaldwin/pgpkey.asc ICna tpyr 100w rods pdr munuiet~!!1 -----BEGIN PGP SIGNATURE----- Version: 2.6.2 iQB1AwUBNi5UYYjYza302vYpAQEzxwL/RXF8u84SMWVB+FFl/ie2hFXLEjDx2woV Y34YoaddqVQfYLVGqHns1BJf+DJk/o1/wNFL0LulX/PE2QWNJqMiDcZVF6d3bv/y wG6nBzZhhkyDgydDuyUQcj2Rv+fS4Wvr =4eCa -----END PGP SIGNATURE----- To Unsubscribe: send mail to majordomo@FreeBSD.org with "unsubscribe freebsd-chat" in the body of the message