(42S/DM42/Free42/Plus42) Multiply Large Numbers
06-12-2023, 12:58 AM
Post: #1
 Eddie W. Shore Senior Member Posts: 1,585 Joined: Dec 2013
(42S/DM42/Free42/Plus42) Multiply Large Numbers
The program LRG× multiplies to two large integers, allowing answers to extend beyond 12 digit capacity. The product is shown in the alpha register. How is this possible? One way is to split the multiplier and multiplicand (also known as factors) into groups of digits.

largemultiply.raw

Program Code:

Code:
00 { 156-Byte Prgm } 01▸LBL "LRG×" 02 ALL 03 XEQ 17 04 STO 02 05 XEQ 18 06 STO 01 07 R↓ 08 XEQ 17 09 STO 04 10 XEQ 18 11 STO 03 12 RCL 02 13 RCL× 04 14 STO 06 15 RCL 01 16 RCL× 03 17 STO 05 18 RCL 01 19 RCL× 04 20 RCL 02 21 RCL× 03 22 + 23 ENTER 24 ENTER 25 XEQ 17 26 STO+ 06 27 LASTX 28 FP 29 8 30 10↑X 31 × 32 STO+ 05 33 RCL 05 34 8 35 10↑X 36 X>Y? 37 GTO 16 38 ÷ 39 ENTER 40 ENTER 41 IP 42 STO+ 06 43 R↓ 44 FP 45 8 46 10↑X 47 × 48 STO 05 49 GTO 16 50▸LBL 17 51 4 52 10↑X 53 ÷ 54 IP 55 RTN 56▸LBL 18 57 LASTX 58 X<>Y 59 - 60 4 61 10↑X 62 × 63 RTN 64▸LBL 16 65 CF 29 66 CLA 67 ARCL 06 68 8 69 RCL 05 70 X≠0? 71 GTO 21 72 8 73 GTO 22 74▸LBL 21 75 LOG 76 1 77 + 78 IP 79 - 80▸LBL 22 81 STO 07 82 X=0? 83 GTO 19 84▸LBL 20 85 48 86 XTOA 87 DSE 07 88 GTO 20 89▸LBL 19 90 ARCL 05 91 AVIEW 92 SF 29 93 .END.

Notes:

The program LRG× takes two integers from the stack. This is meant to work on positive, non-zero integers.

Flag 29 is the thousands separator flag. Setting flag 29 turns them on while clearing it turns them off. In order to allow the alpha register have the long integer, flag 29 is cleared.

Memory register R5 represents units while R6 represents the part in hundred-millions.

The program switches the display to ALL mode.

Source

Hoffman, Dean and Mohler, Lee. Mathematical Recreations for the Programmable Calculator Hayden Book Company, Inc. Rochelle Park: New Jersey. 1982. pp 146-166.
 « Next Oldest | Next Newest »

User(s) browsing this thread: 1 Guest(s)