GLBasic forum

Main forum => Bug Reports => Topic started by: FutureCow on 2009-Oct-07

Title: INTEGER command bug
Post by: FutureCow on 2009-Oct-07
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.
Title: Re: INTEGER command bug
Post by: Moru on 2009-Oct-07
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.
Title: Re: INTEGER command bug
Post by: Kitty Hello on 2009-Oct-07
Bingo Moru.
Title: Re: INTEGER command bug
Post by: FutureCow on 2009-Oct-07
Thanks! I'd forgotten about that bug!
Title: Re: INTEGER command bug
Post by: Kitty Hello on 2009-Oct-07
no bug! It's a feature of the CPU.