[Gambas-user] Problem with float value

Benoît Minisini gambas at ...1...
Sun Apr 25 19:53:25 CEST 2010


> Hi!
> I have problem with my code, there is point where x = rx[31-ii] should
> be true, but it's not.
> So I added this for debug (variables x and rx are float and ii is integer):
> 
> Print x - rx[31 - ii]
> Print rx[31 - ii]
> Print x
> 
> Result:
> 1.110223024625E-16
> 0.377913931573
> 0.377913931573
> 
> So, I tried this:
> Print x - rx[31 - ii]
> Print Format$(rx[31 - ii], "#.###########################")
> Print Format$(x, "#.###########################")
> 
> Result:
> 1.110223024625E-16
>  .377913931572549
>  .377913931572549
> 
> So, I guess my problem is how to print whole content of float variable?
> Mean while I'm trying to guess where is my error with math...
> 
> Jussi
> Gambas3 rev 2879
> Ubuntu 9.10 64bit
> 

Format$() does not print more digits than the precision given by the Float 
format.

But as floating point numbers are stored in binary, the precision is actually 
a bit greater. So I will add one more possible digit in the next revision, and 
you will be able to see that the two numbers you thought equal actually differ 
by the 16th digit.

Regards,

-- 
Benoît Minisini




More information about the User mailing list