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...
>
> --
> Benoît Minisini
>
>
> ------------------------------------------------------------------------------
> 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
>
------------------------------------------------------------------------------
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