I do expect the result of integer division to be a real number when
assigned to a float.
What we find though is:
a as float
a = 2 / 3 // result is 0.000
This is especially annoying when both values come in from integer functions, for example:
gScreenAspect = GetMaxDeviceHeight() / GetMaxDeviceWidth() // 900 / 1440 results on 0.00
So I made a helper function that will produce a float with 4 decimal places
Function fDiv(a as integer, b as integer)
// return a float result of integer division
ans as float
ans = (a * 10000) / b
ans = ans / 10000
EndFunction ans
so now:
gScreenAspect = fDiv( GetMaxDeviceHeight(), GetMaxDeviceWidth() ) // results in 0.625
Is there a better way? Perhaps, I have not found any way to cast an integer to a float so perhaps a simple castFloat() will do the trick?
Function castFloat(a as integer)
// return a float of an integer
ans as float
ans = a * 10
ans = ans / 10
EndFunction ans
Then we can do:
gScreenAspect = castfloat(GetMaxDeviceHeight()) / GetMaxDeviceWidth() // produces 0.625
Is there a built in cast function? Or a better way? Might multiplying and dividing by 8 perhaps be faster than 10?