INTEGER command bug

Previous topic - Next topic

FutureCow

Interesting little bug this one!  =D

If you run the following code, the last call to INTEGER (i.e. INTEGER(1) ) returns 0.
Code (glbasic) Select
FOR i = 0 TO 1 STEP .1
PRINT i + " - "+INTEGER(i), 0, i*200
PRINT INTEGER(1),100,100
NEXT
SHOWSCREEN
MOUSEWAIT


Yet if you run
Code (glbasic) Select
PRINT INTEGER(1),100,100
PRINT INTEGER(1.0),100,120
SHOWSCREEN
MOUSEWAIT
they both return 1 correctly. Just in case anyone gets a wierd result with one of these, I thought I got it to print 0 for INTEGER (1.0) originally but it doesn't print that when I run it now.

Moru

This is probably the usual floating point error that if you add .1 to a variable it doesn't add upp at EXACTLY 1 but 0.9999999999999 something and then INTEGER() will cut it down to 0. If you call INTEGER(1) it correctly returns 1.

Kitty Hello


FutureCow

Thanks! I'd forgotten about that bug!

Kitty Hello

no bug! It's a feature of the CPU.