Post Reply 
Long Division program
08-25-2017, 06:47 AM (This post was last modified: 08-25-2017 07:35 AM by Gamo.)
Post: #1
Long Division program
Got this nice Long Division program from HP Key Notes newsletter (1977 issue)

Anyone have the idea on how to adapt this program to work on HP 12C will be nice.

001 *LBL A
002 /
003 LSTX
004 X<>Y
005 ENT^ (ENTER)
006 FRC (FRAC)
007 X<>Y
008 INT (INTG)
009 R down
010 x
011 EEX
012 4
013 /
014 R up (no key)
015 +
016 DSP4 (FIX4)
017 RTN (no key)
018 R/S

To use the routine press ENTER key in divisor and press A

Example:

4359 ENTER, 57 A ------ 76.0027

Quotient = 76, Remainder = 27


Gamo
Find all posts by this user
Quote this message in a reply
08-26-2017, 05:54 PM (This post was last modified: 08-26-2017 06:03 PM by Dieter.)
Post: #2
RE: Long Division program
(08-25-2017 06:47 AM)Gamo Wrote:  Anyone have the idea on how to adapt this program to work on HP 12C will be nice.

?!? – where's the problem, this HP67 program (I suppose) can be used almost 1:1 on the 12C. OK, the 12C has no labels, so remove the first line. And there is no roll up command, but that's the same as 3x roll down. Since there is no subroutine call the final RTN here works as a R/S, so simply ignore it.

So if you want to you can directly use this program on the 12C, just with these minor modifications.

Or consider this alternate solution:

Code:
01 ENTER
02 ENTER
03 CLX
04 x
05 +
06 /
07 LstX
08 x<>y
09 INTG
10 ENTER
11 R↓
12 x
13 -
14 GTO 00

Hint: the first five lines fill T, Z and Y with the dividend while X holds the divisor.
More important: this procedure calculates the remainder without the FRAC function which is the preferred method since it does not cause roundoff errors.

4359 ENTER 57 [R/S] => 27 [x<>y] 76

Add a final [x<>y] if you want to have it the other way round.

Or add...

Code:
14 EEX
15 4
16 /
17 +
18 FIX 4
19 GTO 00

....and the result is displayed as 76,0027.

Dieter
Find all posts by this user
Quote this message in a reply
08-26-2017, 06:17 PM
Post: #3
RE: Long Division program
(08-26-2017 05:54 PM)Dieter Wrote:  Or consider this alternate solution:

Code:
01 ENTER
02 ENTER
03 CLX
04 x
05 +
06 /
07 LstX
08 x<>y
09 INTG
10 ENTER
11 R↓
12 x
13 -
14 GTO 00

Hint: the first five lines fill T, Z and Y with the dividend while X holds the divisor.
More important: this procedure calculates the remainder without the FRAC function which is the preferred method since it does not cause roundoff errors.

4359 ENTER 57 [R/S] => 27 [x<>y] 76

Add a final [x<>y] if you want to have it the other way round.

Or add...

Code:
14 EEX
15 4
16 /
17 +
18 FIX 4
19 GTO 00

....and the result is displayed as 76,0027.

Same number of steps, but you always manage to cut a few off :-)

Code:

01 f RND
02 Rv
03 ENTER
04 ENTER
05 g LSTx
06 /
07 g LSTx
08 x<>y
09 g INTG
10 ENTER 
11 Rv
12 * 
13 -
14 EEX
15 4
16 /
17 +
18 f 4
19 GTO 00

Gerson.
Find all posts by this user
Quote this message in a reply
08-26-2017, 06:30 PM (This post was last modified: 08-27-2017 04:55 PM by Dieter.)
Post: #4
RE: Long Division program
(08-26-2017 06:17 PM)Gerson W. Barbosa Wrote:  Same number of steps, but you always manage to cut a few off :-)

Hmmm... that's another procedure for filling the stack in the desired way. But it also takes five steps.

Edit: one step can be saved. Replace the first five steps with these four:

Code:
01 ENTER
02 ENTER
03 -
04 +

If you want to minimize the step count it looks like you have to use a register:

Code:
01 x<>y
02 STO 0
03 x<>y
04 /
05 LstX
06 x<>y
07 INTG
08 x
09 STO-0
10 LstX
11 RCL 0
12 EEX
13 4
14 /
15 +
16 FIX 4
17 GTO 00

On the Woodstocks, Spices and similar devices a short and elegant method for storing X and Y simultaneously is  CLΣ Σ+. But as far as I can see a CLΣ on the 12C seems to clear the whole stack. Yuk!

Finally, as it has not been mentioned yet: if quotient and remainder are returned as qqqq,rrrr the divisor must not exceed 10 000.

Edit: Since the roundoff error of the FRAC method should not show up if the result is returned as qqqq,rrrr (this rounds away the last four digits of the calculated remainder) one could also do it this way:

Code:
01 ENTER
02 R↓
03 /
04 INTG
05 LstX
06 FRAC
07 R↓
08 R↓
09 R↓
10 x
11 EEX
12 4
13 /
14 +
15 FIX 4
16 GTO 00

That's three steps less than my original version. Or five steps less if there was a R↑ function to replace the three R↓. ;-)

Dieter
Find all posts by this user
Quote this message in a reply
08-27-2017, 11:51 AM
Post: #5
RE: Long Division program
Thank You for difference variation steps on how to solve this Long Division program. Very helpful to learn from your guys to see many difference ways to adapt these program from other HP calculator ( my example of Long Division program was from HP-41C ) because of the lack of many advance keys funtions of the HP 12C this make it to think harder for other way to program it.

Gamo
Find all posts by this user
Quote this message in a reply
08-27-2017, 12:17 PM (This post was last modified: 08-27-2017 12:43 PM by Dieter.)
Post: #6
RE: Long Division program
(08-27-2017 11:51 AM)Gamo Wrote:  Very helpful to learn from your guys to see many difference ways to adapt these program from other HP calculator ( my example of Long Division program was from HP-41C )

No, your example definitely was a program for the HP67/97. Only these calculators have a DSP command for setting the number of displayed digits independent from the display mode (FIX/SCI/ENG) and on the '41 "EEX 4" is a single line (1E4). The way the commands are written also resembles the output of an HP97 printer ("ENT↑", labels with asterisk, etc.). If all this still doesn't convice you: in 1977 there was no 41C yet – it was introduced in 1979. ;-)

BTW, in what 1977 Keynotes issue did you find this program?

Edit: I finally found it on page 6 of V3N2 – but that is May 1979, not 1977 !
And still two months before the 41C appeared.

Dieter
Find all posts by this user
Quote this message in a reply
08-28-2017, 05:10 AM
Post: #7
RE: Long Division program
Was searching on newsletter and though that it was
41C You're right!!

Gamo
Find all posts by this user
Quote this message in a reply
Post Reply 




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