[Gambas-user] gb3: incorrect solution to If...Then condition

Benoît Minisini gambas at ...1...
Sat Apr 28 17:11:47 CEST 2012


Le 28/04/2012 04:52, Benoît Minisini a écrit :
> Le 28/04/2012 01:24, Jussi Lahtinen a écrit :
>> At least the problem is unrelated to sin and cos...
>>
>> ? format(0.47942553860420300027 ^ 2 -
>> 0.22984884706593014129,"#.######################")
>> - .0000000000000012212453
>>
>> ? format(0.47942553860420300027 ^ 2.0 - 0.22984884706593014129
>> ,"#.######################")
>> - .0000000000000011379786
>>
>>
>> Jussi
>>
>>
>
> Hi,
>
> OK, I found the bug.
>
> The gambas floating point parser incorrectly took into account the
> leading zero decimal digits.
>
> In other words 2.0 was computed as 20 * 10 ^ -1, 2.00 as 200 * 10 ^ -2.
> Now it is just 2.
>
> Consequently, now 2.0 - 2 = 0, and cos(0.5) ^ 2.0 - cos(0.5) ^ 2 = 0.
>
> But cos(0.5) ^ 2 + sin(0.5) ^ 2 keeps being not exactly 1.0. Because the
> gambas algorithm is not the same as the libc algorithm. In gambas 0.5 is
> computed as 5 * 10 ^ -1, which does not give the exact binary
> representation of 2 ^ -1.
>
> I will investigate...
>

Hi,

Precision bugs should be fixed now since revision #4688.

?cos(0.5)^2+sin(0.5)^2
1

?0.5 - 1/2
0

Regards,

-- 
Benoît Minisini




More information about the User mailing list