[fpc-pascal] math round vs banker's round
    Sven Barth 
    pascaldragon at googlemail.com
       
    Wed Aug 14 10:28:28 CEST 2013
    
    
  
Am 14.08.2013 09:55, schrieb Michael Schnell:
> 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.
I wanted to write "x.5" instead of "0.5" :)
Regards,
Sven
    
    
More information about the fpc-pascal
mailing list