[Gambas-user] floating point and single datatype precision...

Benoit Minisini gambas at ...1...
Sat Aug 5 16:57:54 CEST 2006


On Saturday 05 August 2006 06:28, sbungay wrote:
>   Um... yeah... right...
>   So exactly HOW does the storage mechanism work such that it returns an
> incorrect result? If one was to store the value 22.79 into a variable of
> type single in C would one expect it to return a value other than 22.79?
> This means variables of type single and float can not be relied upon to
> return the value we store to them. IMHO that is not a good thing.
>

Because 22.79 is not writeable in binay, exactly like 1/3 in decimal. The 
problem comes from the fact that by default transforming Single into Double 
asks for more digit than the a Single can store. You must round the number 
with Round() or Format() before printing it.

Maybe I should use less digit when converting a Single into String, and keep 
the all precision only with Float. I will see...

Regards,

-- 
Benoit Minisini





More information about the User mailing list