neilsf / XC-BASIC

A compiling BASIC dialect for the Commodore-64
https://xc-basic.net/
MIT License
74 stars 15 forks source link

Strange behaviour of the ">" operator #124

Closed frenchfaso closed 4 years ago

frenchfaso commented 4 years ago

Hello there, the ">" operator behaves weirdly, the following code:

for x = -2776 to -2760 if x > 30000 then print "{LIGHT_GREEN}true ", x else print "{LIGHT_RED}false ", x endif next x

gives this output: vice-screen-20200902103639

changing 30000 "moves" the error, for instance with 29995 this is the output: vice-screen-20200902103839

The "<" operator doesn't seem to have similar issues, but I have not tested it thoroughly.

neilsf commented 4 years ago

Hi. It's somehow related to the number -2767: because 30000+2767=32767, the upper limit of the signed 16-bit integer, but the comparison result is indeed wrong. I'll have a look. Thanks for spotting it out!