Author Topic: INTEGER command bug  (Read 1810 times)

Offline FutureCow

  • HelpEditor
  • Prof. Inline
  • ******
  • Posts: 680
    • View Profile
INTEGER command bug
« 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.

Offline Moru

  • Administrator
  • Prof. Inline
  • *******
  • Posts: 1790
    • View Profile
    • Homepage
Re: INTEGER command bug
« Reply #1 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.

Offline Kitty Hello

  • code monkey
  • Administrator
  • Prof. Inline
  • *******
  • Posts: 10776
  • here on my island the sea says 'hello'
    • View Profile
    • http://www.glbasic.com
Re: INTEGER command bug
« Reply #2 on: 2009-Oct-07 »
Bingo Moru.

Offline FutureCow

  • HelpEditor
  • Prof. Inline
  • ******
  • Posts: 680
    • View Profile
Re: INTEGER command bug
« Reply #3 on: 2009-Oct-07 »
Thanks! I'd forgotten about that bug!

Offline Kitty Hello

  • code monkey
  • Administrator
  • Prof. Inline
  • *******
  • Posts: 10776
  • here on my island the sea says 'hello'
    • View Profile
    • http://www.glbasic.com
Re: INTEGER command bug
« Reply #4 on: 2009-Oct-07 »
no bug! It's a feature of the CPU.