[Gambas-user] could it be a BUG?

Benoit Minisini gambas at ...1...
Mon Jan 2 20:23:53 CET 2006


On Monday 02 January 2006 19:59, tetsuo wrote:
> tetsuo wrote:
> > hi Benoit,
> > i met this problem with aritmetical operations with gambas 1.9.23 and
> > OLD releases...
> >
> >
> > <CODE>
> >
> > DIM tempBUG AS Float
> >
> >   tempBUG = 200 * 0.07
> >   tempBUG = tempBUG - 14
> >   PRINT tempBUG
> >
> > </CODE>
> >
> > print-result on the gambas console is '1,7763568394E-15' , but it would
> >  be '0'
>
> i tried :
> 200 * 0.07 - 14
> in the xcalc application, and there is the same problem.... 1,776356e-15
>
> i tried also in a minimal c printf call:
> printf("%'.18f", (200 * 0.07) - 14)
>   and there is the same problem... 0.000000000000001776
>
> why?????
>
> ... i don't know where is the problem
>

The CPU computes by using binary , and not the base 10 like us, humans.

And in binary, 0.07 is like 1/3 in base 10. You cannot write it with a finite 
number of digits:

0.07 in base 2 is written 0.00[01000111101011100001]...

So the calcul can never be exact, and sometimes rounding errors can appear 
when displaying a Float in decimal.

Regards,

-- 
Benoit Minisini





More information about the User mailing list