[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: operation of 'round' function

From: Francesco Potorti`
Subject: Re: operation of 'round' function
Date: 08 Feb 2002 10:29:26 +0100
User-agent: Gnus/5.09 (Gnus v5.9.0) Emacs/21.1.90

address@hidden (Ronan Waide) writes:

   Okay, I retract that, it makes partial sense:

In my opinion, that page is simply wrong.  Among other things, it

 Example #4 - Round 24.8514 to three significant figures. Look at the
 fourth figure. It is a 5, so now you must also look at the third
 figure. It is 8, an even number, so you simply drop the 5 and the
 figures that follow it. The original number becomes 24.8.

This is wrong, because 24.9 is nearer to the original number than 24.8

As far as I can understand, the only case where this rule makes sense is
when you have an *exact* number whose last significant digit is 5.  When
rounding to an integer, it makes sense for exact numbers of the form 2.5.

Also interesting is that the documentation about this fact in the libc
manual is incomplete.  I can read this:

 - Function: double round (double X)
 - Function: float roundf (float X)
 - Function: long double roundl (long double X)
     These functions are similar to `rint', but they round halfway
     cases away from zero instead of to the nearest even integer.

but the documentation for rint does not mention even integers anywhere.
Rather, it makes reference to the current rounding mode:

 - Function: double rint (double X)
 - Function: float rintf (float X)
 - Function: long double rintl (long double X)
     These functions round X to an integer value according to the
     current rounding mode.  *Note Floating Point Parameters::, for
     information about the various rounding modes.  The default
     rounding mode is to round to the nearest integer; some machines
     support other modes, but round-to-nearest is always used unless
     you explicitly select another.

Which again says nothing about even integers.  It mentions the "nearest
integer", which is ambiguous.  The Floating Point Parameters page only
adds that the "nearest integer" notion is defined by IEEE, but does not
describe it.

reply via email to

[Prev in Thread] Current Thread [Next in Thread]