AGK 10813
I was trying to figure out why my tiles weren't being placed properly and after some debugging I've found that floats are not what I expect them to be.
If you set a float = 2.2 then what is actually stored is 2.1999998...
Not sure if this is a bug or not, but it feels like it is to me. If you put 2.2 into a float variable I would expect 2.2000000 out.
Here's my testing code
for i# = 2.0 to 4.0 step 0.1
WriteDebug("float = " + Str(i# , 25))
myInt = trunc(i#*1000)
WriteDebug(" int = float x 1000 = " + Str(myInt))
next i#
END
function WriteDebug(text$)
dim debugLog[1]
debugLog[0] = OpenToWrite("debugLog.txt",1)
/*
time$ = Str(Getmilliseconds())
addZeros = 6 - len(time$)
if addZeros > 0
for i = 1 to addZeros
zero$ = "0" + zero$
next i
endif
time$ = zero$ + time$
text$ = time$ + " -- " + text$
*/
writeLine(debugLog[0],text$)
closeFile(debugLog[0])
endfunction
I tried a calculation of the float * 1000 to check to see if it was something odd with Str(), but the float value is definitely quite off.
Here's the log of results:
float = 2.0000000000000000000000000
int = float x 1000 = 2000
float = 2.0999999046325684000000000
int = float x 1000 = 2100
float = 2.1999998092651367000000000
int = float x 1000 = 2199
float = 2.2999997138977051000000000
int = float x 1000 = 2299
float = 2.3999996185302734000000000
int = float x 1000 = 2399
float = 2.4999995231628418000000000
int = float x 1000 = 2499
float = 2.5999994277954102000000000
int = float x 1000 = 2599
float = 2.6999993324279785000000000
int = float x 1000 = 2699
float = 2.7999992370605469000000000
int = float x 1000 = 2799
float = 2.8999991416931152000000000
int = float x 1000 = 2899
float = 2.9999990463256836000000000
int = float x 1000 = 2999
float = 3.0999989509582520000000000
int = float x 1000 = 3099
float = 3.1999988555908203000000000
int = float x 1000 = 3199
float = 3.2999987602233887000000000
int = float x 1000 = 3299
float = 3.3999986648559570000000000
int = float x 1000 = 3399
float = 3.4999985694885254000000000
int = float x 1000 = 3499
float = 3.5999984741210937000000000
int = float x 1000 = 3599
float = 3.6999983787536621000000000
int = float x 1000 = 3699
float = 3.7999982833862305000000000
int = float x 1000 = 3799
float = 3.8999981880187988000000000
int = float x 1000 = 3899
float = 3.9999980926513672000000000
int = float x 1000 = 3999