Skip site navigation (1)Skip section navigation (2)
Date:      Wed, 21 Oct 1998 17:39:25 -0400 (EDT)
From:      John Baldwin <jobaldwi@vt.edu>
To:        Mike Smith <mike@smith.net.au>
Cc:        freebsd-chat@FreeBSD.ORG, bde@FreeBSD.ORG, Bruce Evans <bde@zeta.org.au>
Subject:   Re: Bug in rintf()?...
Message-ID:  <XFMail.981021173925.jobaldwi@vt.edu>
In-Reply-To: <199810211828.LAA01093@dingo.cdrom.com>

next in thread | previous in thread | raw e-mail | index | archive | help
-----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 <jobaldwi@vt.edu> -- 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



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