Automatic casting in float & double comparisons
Posted: Tue Apr 04, 2006 2:28 pm
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.
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.