Multiply Function [x]
08-03-2018, 02:40 PM (This post was last modified: 08-03-2018 05:32 PM by Dieter.)
Post: #7
 Dieter Senior Member Posts: 2,397 Joined: Dec 2013
RE: Multiply Function [x]
(08-03-2018 09:27 AM)Gamo Wrote:  I'm wondering what algorithm is use in calculator for the multiply function.

There was a series of HP Journal articles that described how calculators do their calculations. I remember something about log, exponential and trig functions, and maybe there also was something about multiplication and division.

(08-03-2018 09:27 AM)Gamo Wrote:  Example: 6903 x 103

6903 [ENTER] 103 [R/S] ---> 711009

When I ran this it returned 711012,14.

Why is that? Register 2 happened to have pi stored in it (from a previous calculation â€“ the 12C has continuous memory). And your program does not clear this register before it starts adding! I have mentioned this point several times: always clear a sum before you start adding data! Clearing the sum afterwards, as your program does it, is not a solution.

(08-03-2018 09:27 AM)Gamo Wrote:  Step can be reverse: 103 [ENTER] 6903 [R/S] ---> 711009

But the program takes much longer to finish. You should start with the smaller number in X. Why not have the program care for this? Simply start with

X<=Y?
X<>Y
X<>Y

You can also speed up (and shorten) the program by using storage arithmetics.

Edit: here's my attempt of such a program. Only one data register is required.

Code:
01 X<=Y? 02 X<>Y    // this way the larger factor is in X 03 X<>Y    // and now it's the smaller factor 04 INTG    // this must be an integer 05 STO 0   // store smaller factor as counter 06 X<>Y    // the larger factor (may be fractional) 07 INTG    // is moved into LastX (INTG used only for this purpose) 08 0       // initialize sum to zero 09 RCL 0   // check counter 10 X=0?    // has it become zero? 11 GTO 19  // then exit 12 1 13 STO-0   // else decrement counter 14 Râ†“ 15 Râ†“      // pop back sum (was in Z) 16 LstX 17 +       // add larger factor 18 GTO 09 19 +       // sum was in Y while X=0, so this returns the result in X

Note: the smaller (!) of the two factors must be an integer â‰¥0. If there is a fractional part it is discarded.
The larger factor may be fractional.

123,4 [ENTER] 17 [R/S] => 2097,80
17 [ENTER] 123,4 [R/S] => 2097,80

Dieter
 « Next Oldest | Next Newest »

 Messages In This Thread Multiply Function [x] - Gamo - 08-03-2018, 09:27 AM RE: Multiply Function [x] - Massimo Gnerucci - 08-03-2018, 11:31 AM RE: Multiply Function [x] - Pekis - 08-03-2018, 01:04 PM RE: Multiply Function [x] - rprosperi - 08-03-2018, 01:13 PM RE: Multiply Function [x] - wynen - 08-03-2018, 01:07 PM RE: Multiply Function [x] - Dave Britten - 08-03-2018, 02:10 PM RE: Multiply Function [x] - Dieter - 08-03-2018 02:40 PM RE: Multiply Function [x] - Thomas Klemm - 08-03-2018, 05:33 PM RE: Multiply Function [x] - Thomas Klemm - 08-03-2018, 06:45 PM RE: Multiply Function [x] - Leviset - 08-03-2018, 10:54 PM RE: Multiply Function [x] - ijabbott - 08-03-2018, 11:05 PM RE: Multiply Function [x] - Gamo - 08-04-2018, 01:41 AM RE: Multiply Function [x] - Gamo - 08-04-2018, 04:23 AM RE: Multiply Function [x] - Namir - 08-04-2018, 08:26 AM RE: Multiply Function [x] - Thomas Puettmann - 08-04-2018, 09:03 AM RE: Multiply Function [x] - brickviking - 08-05-2018, 03:12 AM RE: Multiply Function [x] - Gamo - 08-05-2018, 03:33 AM RE: Multiply Function [x] - Thomas Klemm - 08-05-2018, 04:07 PM

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