2

I only recently learned that the early MS BASICs had integer variables and do not have a machine that runs it. So perhaps someone with a PET or C64 could answer these questions?

For one, were there integer constants as well as variables? I'm not familiar with how MS stored constants like 10, were they always 40-bit FP or would it use an integer format if available? I seem to recall something about ints in DATA statements?

The second is about math over/underflow. As I understand it, when you applied math operators to int variables it used the FP code to do the calculations. So what happened if you did...

I%=32767+2
I%=65536+2

Did it give an error, or trim it, or something else?

1
  • 1
    You can run C64 BASIC on almost any machine: github.com/mist64/cbmbasic . The code itself is opaque, but the interpreter is intact
    – scruss
    Commented Jun 26, 2019 at 15:19

1 Answer 1

5

GW-BASIC 3.23 gave an error, "Overflow":

GW-BASIC Integer Overflow error

4
  • Superb, thanks. Now I have to figure out the constants. Commented Jun 26, 2019 at 14:52
  • 1
    I didn't add info on constants because I'm simply not sure and have no way to verify, but I believe that integer constants are stored in memory as 16-bit (signed) integers - not converted to the 40-bit float format. Conversion would only happen if necessary, e.g., if you wrote 10 + 0.0, the 10 would be converted to float for the purposes of the operation. If you attempted to then assign the result to an explicitly integer variable, it would get rounded in some implementations, truncated in others. Commented Jun 26, 2019 at 14:56
  • Ok that's useful Jeff. May I beg one more test? What if you do A=0.5, I%=I%+A? Is that allowed, and if so, what is the result? I guess I just need a DOS box... Commented Jun 26, 2019 at 16:37
  • 1
    It will do the calculation in float, and then convert the result back to integer. As above, some implementations will truncate before conversion back to integer, others will round - and there's always the question of which way a rounding implementation rounds. GW-BASIC appears to round up for 0.5, and this overflows. Commented Jun 26, 2019 at 16:43

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .