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

Jussi Lahtinen jussi.lahtinen at ...626...
Fri Apr 27 20:44:08 CEST 2012


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






2012/4/27 Benoît Minisini <gambas at ...1...>

> Le 27/04/2012 05:08, Kevin Fishburne a écrit :
> > I'm using the latest build and have this code:
> >
> >     If Zoom.Adjustment * 0.5>= Zoom.Maximum Then
> >       Zoom.Adjustment = Zoom.Adjustment * 0.5
> >     Endif
> >
> > Zoom.Adjustment and Zoom.Maximum are both singles. Zoom.Adjustment is 1
> > and Zoom.Maximum is 0.5. The expression with these values returns False,
> > which is blowing my mind. The same, untouched code worked fine before my
> > recompile this evening. Any insight into WTF is going on here?
> >
>
> ?CSingle(1) * 0.5 - CSingle(0.5)
> -1,1102230246252E-16
>
> 0.5 is a Float, so CSingle(1) * 0.5 is a Float before doing the comparison.
>
> You must write CSingle(0.5) to get a Single "0.5", and not a Float "0.5".
>
> AFAIK 0.5 should be the same as a Float or as a Single (1*2^-1) (a
> Gambas bug?), but anyway you must use CSingle for the other cases.
>
> Regards,
>
> --
> 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 at lists.sourceforge.net
> https://lists.sourceforge.net/lists/listinfo/gambas-user
>



More information about the User mailing list