Authors
Publication
Pub Details
Date
Pages
BASIC Terms
It you look at the program below, you are inclined to doubt the good judgement of the author, putting “VAL” all over. But when you program it and compare it with the way it is normally written, you find that it uses 14 BASIC bytes (12 %) less than the conventional program with 139 bytes.
This is a consequence of the way in which numbers are programmed by the T/S computers. In order to save execution time, the BASIC program contains both the original number and the normalized floating point equivalent. If you use the VAL function, this is not the case. You add the 3 codes for VAL and 2 quotation marks but you gain 6 code bytes (one for the number indicator, and five for the normalized floating point number).
While the running time for the standard program is 5 seconds, the one with the VAL requires 13 seconds.
This example shows that in order to save 14 memory spaces (12%) you sacrifice 8 seconds (160 %) execution time.
Listing: Standard Floating Point Variables
200 LET A=2.5
210 FOR I=1 TO 255
220 IF I>200 THEN GO TO 250
230 LET A=A-I/2
240 GO TO 260
250 LET A=A+I+1.5
260 NEXT
270 PRINT A
Listing: VAL Variables
200 LET A=VAL "2.5"
210 FOR I=VAL "1" TO VAL "255"
220 IF I>VAL "200" THEN GO TO VAL "250"
230 LET A=A-I/VAL "2"
240 GO TO VAL "260"
250 LET A=A+I+VAL "1.5"
260 NEXT I
270 PRINT A
Products
Media
Image Gallery
Source Code
Note: Type-in program listings on this website use ZMAKEBAS notation for graphics characters.