[fpc-pascal] math round vs banker's round

Michael Schnell mschnell at lumino.de
Wed Aug 14 09:55:11 CEST 2013


On 08/14/2013 09:38 AM, Sven Barth wrote:
>
> - 0.5 does not always have a direct representation as a floating point 
> value and thus internally it might be 0.4999999 or something like that 
> and thus it will be rounded to 0.4 (see also 
> http://bugs.freepascal.org/view.php?id=24374 )
Hmmm

AFAIU, in hardware / memory, the binary representation of -0.5 is

(sign * mantissa * 2 ** exponent ) =  (-1) * 0.5 * 2 ** 1

so this seems to be "exact"

Maybe the compiler does not calculate exactly this value when doing the 
constant "-0.5". I don't consider this a problem, as IMHO, in fact any 
attempt to rely on an exact value of a floating point number is erroneous.

-Michael




More information about the fpc-pascal mailing list