Automatic casting in float & double comparisons

Got an idea for enhancing PureBasic? New command(s) you'd like to see?
mike74
User
User
Posts: 60
Joined: Mon Nov 21, 2005 1:44 pm

Automatic casting in float & double comparisons

Post 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.
Dare2
Moderator
Moderator
Posts: 3321
Joined: Sat Dec 27, 2003 3:55 am
Location: Great Southern Land

Post 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. :)
@}--`--,-- A rose by any other name ..
Godai
Enthusiast
Enthusiast
Posts: 171
Joined: Thu Oct 05, 2006 8:13 pm

Post by Godai »

Definately cast to float! This is the source of untold bugs :)
Post Reply