[fpc-pascal] testing if a float has a fractional part

Jonas Maebe jonas at freepascal.org
Sun May 13 15:40:47 CEST 2018


On 11/05/18 23:59, Benito van der Zander wrote:

> after all these discussions about the frac function, what is the best 
> way to test if there is a fractional part? That is the most common thing 
> I use frac for
> 
> I have always used frac(x) = 0
> 
> Is that worse or better than int(x) = x  ?

The only proper way is to use something like Math.SameValue(x, int(x)). 
Never use equality tests with floating point values, unless you are 
checking for a specific bit pattern (or if you know that the value can 
always be represented exactly a sum of power-of-two's).


Jonas



More information about the fpc-pascal mailing list