neilsf / XC-BASIC

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

Number Formatting #133

Closed Pontiac76 closed 3 years ago

Pontiac76 commented 3 years ago

I just found out about XCBasic this afternoon, and right after work, I started some basic (no pun) investigation to speed differences. I plan on writing a simple program that I wrote in college for the PC/DOS, and the text animation I plan on having is probably going to be best suited for XCBasic instead of my writing ASM for the UI. :)

I wrote the following program:

10 print "{CLR}";
20 x=0
30 x=x+1
40 print "{HOME}";
50 print x
60 goto 30

I pasted this code into VICE (x64sc.exe) with appropriate fixes for {CLR} and {HOME}, and then compiled it into a PRG using xcbasic.

What I noticed is that the typed in variant running in C64 BASIC, there's a space before the number to indicate the sign of the number. Positive in this case. In the image on the right, the compiled code, there is no space. Is this something intentional?

image

neilsf commented 3 years ago

Hi Thanks for trying XC=BASIC! Yes, it's intentional. CBM BASIC starts the number with space (positive) or - (negative) while XC=BASIC puts no space if it's positive. However when you print floating point numbers in XC=BASIC, they'll be printed just like in CBM BASIC. Although you should try to avoid using floating point, it's very slow compared to integers.

Pontiac76 commented 3 years ago

Alright, thanks.