[fpc-devel] format function

John Briggs "john at " at johneb47.id.au
Fri Oct 13 04:43:13 CEST 2006


On Thu, Oct 12, 2006 at 03:24:14PM +0200, Florian Klaempfl wrote:
> Andrea Mauri wrote:
> > Jonas Maebe wrote:
> >>
> >> Not only that, but -0.000 is different from 0.000 (at least for the fpu)
> >>
> >>
> >> Jonas
> > In a mathematical way of view I think that -0.000 has no meaning.

It does it means that the original number was negative before
rounding.
0 is neither positive or negative but -0.000 is both correct and
meaningful. The precision (4 digits) indicates that it is not exactly
0 but is slightly negative ie:

   x = -0.000 ==>  x < 0.000 and x > -0.0005  ( rounding towards zero )

where 

  x = 0.000  ==>  x > 0.000 and x < 0.0005  ( rounding towards zero )

It is the implied precision that is causing you the problems. Besides
the other problem is that converting decimal -1E-4 to binary results in
an irrational binary number ( similar to 1/3 in decimal).
 
As long as you use floating point numbers in normal computing tasks
you need to be aware of the implied precision problems and do error
checking in your code.

John

> 
> Well, despite the fact that -0.000 is probably indeed wrong in this case, a
> mathematical view is often wrong when using an fpu :)
> 
> > If I round something and the resulting value is zero, well zero is zero.
> > Not +0 or -0.
> > a.



More information about the fpc-devel mailing list