[fpc-pascal] round(2.5)=2

Michael Schnell mschnell at lumino.de
Tue Jun 12 10:17:51 CEST 2018


On 12.06.2018 09:01, Mattias Gaertner wrote:
> Floats can represent 1.5 exactly.
Of course I do know how the binary representation of floats is done on 
X86 and similar architectures, and hence that same provides a bit 
combination that exactly defines 1.5.

That is why I did say *relying* on the exact value of a real number is 
erroneous. (Supposedly with the common archs, no representation of a 
rational a/b will be exact but those with b = 2**n).

But for an application programmer it should not be considered common 
knowledge, that on the architecture his program is to run on, 3/2 can be 
represented exactly while 2/3 can't.

That is why an application programmer should be trained not to do any 
assumptions which float value is to be considered  to be exact and which 
is not.

-Michael



More information about the fpc-pascal mailing list