by kbelder · 1w ago · 0 comments
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.
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.