Multiplication Precision in 4 digit blocks

Developer(s): Steve Gunhouse
Date: 1991
Type: Program
Platform(s): TS 2068

Multiplies two whole numbers of any length with full precision. The numbers are typed as strings, split into blocks of four digits, multiplied block by block with carries, and the result is printed with each block padded to four digits. Working four digits at a time is much faster than the digit-by-digit “Multiplication Accuracy” program it answers.

Answer Y to “Another Number?” to go again; the new result is printed over the old one. Line 9999 saves to a Larken disk and is not needed from tape.

Published in Sinc-Link January-February 1991 (Re: Multiplication programs from last month).

Related Articles

One of our members, Steven Gunhouse, has written me a letter which, in part, is a follow-up to two mathematics routines I put in the last Sept/Oct newsletter issue.

Related Content

Image Gallery

Source Code

5 REM Multiplication Precision in 4 digit blocks
7 PRINT AT 1,3;"Precision Multiplication"''
8 PRINT TAB 6;"by Steven Gunhouse"
10 INPUT "First Number?"'a$
15 LET a$="   "+a$
16 REM the extra spaces are necessary in case there would be <4 digits in the first block
20 INPUT "Second Number?"'b$
25 LET b$="   "+b$
30 LET a=INT (LEN a$/4)
35 LET b=INT (LEN b$/4)
40 DIM a(a)
45 DIM b(b)
50 FOR i=LEN a$ TO 4 STEP -4
55 LET a(INT (i/4))=VAL a$(i-3 TO i)
60 NEXT i
70 FOR i=LEN b$ TO 4 STEP -4
75 LET b(INT (i/4))=VAL b$(i-3 TO i)
80 NEXT i
90 DIM c(a+b)
100 FOR i=a TO 1 STEP -1
105 LET t1=0
110 FOR j=b TO 1 STEP -1
115 LET c(i+j)=t1+c(i+j)+a(i)*b(j)
120 LET t1=INT (c(i+j)/1e4)
125 LET c(i+j)=c(i+j)-t1*1e4
130 NEXT j
140 LET c(i)=t1
150 NEXT i
200 PRINT a$(4 TO );"x";b$(4 TO );"="
205 LET i=1
210 IF c(1)=0 THEN  LET i=2
215 PRINT c(i);
220 FOR j=i+1 TO a+b
225 LET t$=STR$ c(j)
230 PRINT ("000"+t$)(LEN t$ TO );
235 REM Must add extra zeros if t$ is too small (<1000)
240 NEXT j
250 PRINT '"Done."
990 INPUT "Another Number? ";y$: IF y$="Y" OR y$="y" THEN  GO TO 1
999 STOP
9999 RANDOMIZE USR 100: SAVE "mult.B4" LINE 1

Note: Type-in program listings on this website use ZMAKEBAS notation for graphics characters.