On 04/27/2012 07:24 PM, Jussi Lahtinen wrote:
> 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
>
>
>
>
>
> 2012/4/28 Benoît Minisini<gam...@users.sourceforge.net>
>
>> Le 27/04/2012 20:44, Jussi Lahtinen a écrit :
>>> If Sin(0.5) ^ 2 + Cos(0.5) ^ 2<>   1 Then
>>> Print "This shouldn't be seen, but it is."
>>> Endif
>>>
>>>
>>> ? format((Sin(0.5) ^ 2 + Cos(0.5) ^ 2),"#.########################")
>>> 1
>>>
>>> What is going on?
>>>
>>>
>>> Jussi
>>>
>> It's very strange actually.
>>
>> There is optimization in the "^" operator. If the power is an integer
>> between -4 and +4, standard multiplication and division are used instead
>> of the pow() mathematical function.
>>
>> In other words, Sin(0.5) ^ 2 = Sin(0.5) * Sin(0.5).
>>
>> If you want to force the use of the pow() function, write 'Sin(0.5) ^ 2.0'.
>>
>> And then comes the strangeness: Sin(0.5) * Sin(0.5) does not return the
>> same value as Sin(0.5) ^ 2.0 ! And Sin(0.5) ^ 2.0 + Cos(0.5) ^ 2.0 does
>> return 1.0. But not Sin(0.5)*Sin(0.5) + Cos(0.5)*Cos(0.5), which should
>> be more accurate!
>>
>> If someone has an explanation...

What would I do without you guys to humiliate me into wisdom? If I could 
beat floating point math with a stick I'd have enough kindling for a 
long winter. I used this code instead and the math is happy:

     Case Key["-"]
       ' Zoom in.
       Zoom.Adjustment = Zoom.Adjustment / 2
       If Zoom.Adjustment >= Zoom.Maximum Then Zoom.Adjustment = 
Zoom.Maximum
     Case Key["="]
       ' Zoom out.
       Zoom.Adjustment = Zoom.Adjustment * 2
       If Zoom.Adjustment <= Zoom.Minimum Then Zoom.Adjustment = 
Zoom.Minimum

Thanks.

-- 
Kevin Fishburne
Eight Virtues
www: http://sales.eightvirtues.com
e-mail: sa...@eightvirtues.com
phone: (770) 853-6271


------------------------------------------------------------------------------
Live Security Virtual Conference
Exclusive live event will cover all the ways today's security and 
threat landscape has changed and how IT managers can respond. Discussions 
will include endpoint security, mobile security and the latest in malware 
threats. http://www.accelacomm.com/jaw/sfrnl04242012/114/50122263/
_______________________________________________
Gambas-user mailing list
Gambas-user@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/gambas-user

Reply via email to