[fpc-devel] FormatFloat bug

Jonas Maebe jonas.maebe at elis.ugent.be
Wed May 30 15:46:02 CEST 2007


On 30 mei 2007, at 15:08, Graeme Geldenhuys wrote:

> Yury, you are right!  I never spotted that, thanks.
>
> Running the example program below shows the difference in output. The
> currency type rounds to 0.01 and the extended type rounds to 0.00.
> Either way, I still believe this is a bug in FormatFloat.

No, then it is related to the generic float->string routines.  
However, you are mainly running into a precision issue with the fpu,  
because 0.005 cannot be represented exactly using any floating point  
type. This is especially clear since if you change the type from  
extended to double, you also get 0.01.

0.005, as extended, is actually 0.004999999999999999999898356046329484
As double, it is actually 0.0050000000000000001

It's possible that the float to string routines can be tweaked to  
produce 0.01 also for extended, but if so this will require extensive  
testing to ensure that they don't give wrong results again for other  
values.


Jonas



More information about the fpc-devel mailing list