8-Bit Software Online Conversion

Maxiply - Listing

10REM" * M A X I N F 0 * 20REM Information and instructions for "Maxiply" - program for multiplying very large numbers. 30MODE7:VDU23,1,0;0;0;0; 40PRINTTAB(3)"     50PRINTTAB(3)"     60PRINT" STRING 70PRINT" Seeing the references in 8 BS issues 35 and 36 to a routine for m ultiplying large numbers together, call ed Fermat, prompted me to haul out, dus t down, and polish up a program original ly worked out on an MSX." 80PRINT" This program, called Maxip ly, will multiply two numbers with, i n essence, an infinite number of digits . The only limitations are the amount o f memory available, and the length of time you want to run your computer." 90PRINT" With the memory available on the 32K Beeb, you can multiply any t wo numbers which give an answer up to 3 000 digits long, for example two 1500 d igit numbers, or a 2900 digit num ber by a 100 digit number." 100PROCpage 110PRINTTAB(13)" MAXINFO 2" 120PRINT" STRINGVDU 130PRINT" It doesn't matter whether the larger number is entered first or s econd - the only difference is that if i t's entered second there will be more pr ogress and time checks displayed." 140PRINT" The program works by multi plying and adding in groups, which gets a little complicated, but speeds thin gs up. On average, it runs about twice as fast as the Fermat routine, which al so seems to have a size limit."; 150PRINT" The program works its way through the numbers from left to righ t, to simplify the arrays." 160PRINT" Most of the program length is taken up with input and output rou tines and options, and checking proced ures.If you wanted more memory for even larger numbers, you could - careful ly - remove some of these, "; 170PRINT"and then just increase the DIM's and MAX%." 180PROCpage 190PRINTTAB(3)" MAXINFO 3 - INPUT INST RUCTIONS 1" 200PRINT" STRINGVDU 210PRINT" 1) Numbers can be entered di git by digit, in groups of 238, up to 3000 digits for the first number, and to (3000-1st no. digits) for th e second. A running total and total le ft ('max') is given at each stage."; 220PRINT" Each time you get to anoth er 238 digits (you can't enter more a t one go), enter these, and after a shor t checking pause, you will be prompted to continue the number. If you enter le ss than 238 digits in any section, "; 230PRINT"the program will then continu e to either the second number or the calculations." 240PRINT" 2) You can enter a decimal p oint at any stage (this was difficult!) in either the first or second numbers, or both, and carry on with additional groups of 238 digits.The section with the decimal point will be 237 digits lon g." 250PROCpage 260PRINTTAB(3)" MAXINFO 4 - INPUT INST RUCTIONS 2" 270PRINT" STRINGVDU 280PRINT" 3) You can enter just 'R' fo r either number and you will get a ra ndom number of a random length between 1 and 300 digits." 290PRINT" 4) To get a random number of a specific length, enter 'R' plus the n umber of digits you want. For example , R1275 will give you a random numbe r 1275 digits long." 300PRINT" 5) Entering 'R0'(zero) will give you a random number of a random le ngth between 1 and 1200 digits." 310PRINT" 6) You can square the first number, whether entered directly or as a random number, by just entering 'S' when prompted for the second numb er." 320PRINT" 7) Entering 'I' at the First Number prompt will return you to th ese notes." 330PRINT" 8) Escape gives you a new ru n option." 340PROCpage 350PRINTTAB(9)" MAXINFO 5 - NOTES 1" 360PRINT" STRINGVDU 370PRINT" 1) Inputs for the first and second numbers can be freely mixed. The first number, for example, can be direct input, and the second a rand om number." 380PRINT" 2) If you try to enter too m any digits at any stage, you will be to ld about it!" 390PRINT" 3) The checking procedure wi ll remove anything that isn't useful, such as stray letters, symbols, spac es and unwanted zeros. To see this, enter a mixture of a few digits and a lot of gobbledegook (except commas) "; 400PRINT"for the first number, and then square it." 410PRINT" 4) Don't worry if a large an swer zooms past at the end. The answer, and the original numbers, can be rec alled and displayed at the end, and th ere are also print options." 420PROCpage 430PRINTTAB(9)" MAXINFO 6 - NOTES 2" 440PRINT" STRINGVDU 450PRINT" 5) To get a large answer rel atively quickly, multiply a very lar ge number by a smallish one, rather th an two similar sized numbers." 460PRINT" 6) To aid rapid direct input , function keys 0 and 1 hold ten digit numbers." 470PRINT" 7) Squaring a lot of 9's pro duces interesting results, as do 3 's and 6's, and multiplying variations o n equal numbers of 3's, 6's, and 9's . This is also a good quick test of wh ether the program is working properly! " 480PRINT" 8) If you did a multiplicati on on a (rather large) piece of pape r which had an answer 3000 digits lo ng, that answer would be over sixty f eet long. And it would only take about a year..." 490PRINT" STRING 500PRINT'" PRESS: SPACE to run Maxiply . I to repeat Informat ion."; 510G$=GET$ 520IF G$="I" RUN ELSE CHAIN"MAXIPLY" 530DEFPROCpage 540PRINT" STRING 550PRINTTAB(24)"PRESS SPACE"; 560G=GET:CLS 570ENDPROC