Hacker News new | ask | show | jobs
by kbelder 14 days ago
I don't believe you gained any performance by declaring them as integers. They were converted to floats for all calculations, then converted back when stored. I think the only advantage was reduced storage space.
1 comments

In QBASIC, putting DEFINT A-Z at the beginning of your program did indeed speed it up. That's "DEFault variable type is INTeger (16-bit signed) for all variables with names beginning with A-Z".
Yep. QB veterans remember that you get significant performance gains by setting `DEFINT A-Z` so that variables without type suffixes auto-default to integers. Granted you could still do this by properly affixing a '%' but it was easy to forget.

In QBASIC, untyped variables default to single-precision floating-point values, so arithmetic operations use floating-point math. Assuming you can do everything with integer math, using `DEFINT` is a good way to make sure your calculations run entirely as integer math (very useful for things like basic arithmetic, indexes, loop counters, etc).

The QBASIC.EXE intrepreter doesn't even take advantage of a x87 floating-point coprocessor (even if the machine has one), making floating-point operations slower. I'm actually working on a pretty accurate QBasic virtual IDE, and ended up doing a pretty deep dive into this to ensure that its performance was on par with machines of the era.

I saw your reply was deleted, so I'm responding here just for future interesting info:

QuickBASIC 4.5 is not QBASIC. QB 4.5 will use a real x87 if it finds one.

On builds where DOSBox's FPU is only 64-bit (MSVC builds, ARM builds too), you'll get that drift you were describing describing. (X# 50, 49.99999999999)

I ran into the same thing when I was working on this a few months ago.

QBASIC.EXE is different. Its math is written as x87 code, but the linker swaps every FPU opcode for an INT 34h down to Microsoft's software emulator which is built into the interpreter.