Page 1 of 1

Automatic casting in float & double comparisons

Posted: Tue Apr 04, 2006 2:28 pm
by mike74
This is a request that PureBasic cast floats and doubles automatically in comparisons. It stems from a discussion in the bug report forum (http://www.purebasic.fr/english/viewtop ... 253#137253). Currently, the following line does not produce a message box:

x.f = 3: If x*0.05 = 0.15: MessageRequester("", "Ok"): EndIf

However, the line below does:

x.f = 3: x*0.05: If x = 0.15: MessageRequester("", "Ok"): EndIf

I would recommend that the casting take place at the latest possible time so that, for example, 9.12*1.13*4.47 = 4.47*1.13*9.12 (they may be equal now; it's just an example to show that if the casting takes place too early the loss of precision may produce unexpected results).

Edit: I take it back. There is probably no way of guaranteeing that, for example, 2.4*1.2=3.0*0.8*0.3*4.

Posted: Tue Apr 04, 2006 3:03 pm
by Dare2
Also an inbuilt cast function. Please.

AsDouble(var.f)
AsFloat(var.d)
AsQuad(var.f)

Or whatever words are beautiful and de-obsfucated enough. :)

Posted: Tue Oct 16, 2007 5:15 pm
by Godai
Definately cast to float! This is the source of untold bugs :)