A brief explanation

by Galleon

The variable k has nothing to do with how QBASIC processes the equation 640 * 360

The numbers 640 and 360 are both "small" numbers which fit into the range of INTEGER values, so QBASIC stores them as such. Then when QBASIC tries to calculate the answer to the equation it does the following.
i) load INTEGER value 640
ii) load INTEGER value 360
iii) INTEGER multiply these values
iv) Give an error if result is larger than an INTEGER
So annoying, but that's how it works. Now if one of those values wasn't an INTEGER, then that would change what happened significantly.

You can force QBASIC to think of a number as a LONG by appending a & symbol to it. Try...
k = 640& * 360
Now it does this:
i) load LONG value 640
ii) load INTEGER value 360
iii) convert INTEGER value to LONG value (I call this marking up!)
iii) LONG multiply these values
iv) Give an error if result is larger than a LONG

So why not always use LONG multiplication instead of INTEGER multiplication? SPEED

Posted on Mar 22, 2008, 5:25 AM
from IP address 58.106.166.186

Respond to this message   

Goto Forum Home


Response TitleAuthor and Date
* Got it. Thanks for the explanation :)petko10 on Mar 22