Summation on HP 42S
09-26-2018, 10:10 AM
Post: #27
 Frido Bohn Member Posts: 57 Joined: Jan 2015
RE: Summation on HP 42S
(09-25-2018 04:47 PM)Dieter Wrote:  Simple. Add the (base 10) logs of 1...1000. The integer part of the sum is the tens exponent, 10^(fractional part) is the mantissa.
[...]
Dieter

Your program is really elegant as it uses the Y-register for the calculation of the logarithm as well as for decrementing n and counting in one pass.
Mine is a bit more clumsy as it uses the X-register for this purpose. The summation of the logarithm is then achieved through stack shifting and the use of LASTX.

Code:
01 LBL "FC2" 02 0 03 X<>Y 04 LBL 01 05 LOG 06 LASTX 07 Rv 08 + 09 R^ 10 DSE ST X 11 GTO 01 12 X<>Y 13 IP 14 LASTX 15 FP 16 10^X 17 END

I wouldn't have made the effort to list the code if it was not for the timing of the programs. Interestingly, my code takes for 1000! about 90 seconds while the more elegant code takes about 8 seconds longer in a real HP42S.

The result is (real HP42S) 4.02387322958 10^2567 for both codes. That is precise to the 5th decimal place. By using the natural logarithm (LN) instead of the decadic (LOG) the precision is increased by 1 decimal place.

Cheers!
Frido
 « Next Oldest | Next Newest »

 Messages In This Thread Summation on HP 42S - lrdheat - 09-23-2018, 06:14 PM RE: Summation on HP 42S - Didier Lachieze - 09-23-2018, 06:28 PM RE: Summation on HP 42S - lrdheat - 09-23-2018, 06:41 PM RE: Summation on HP 42S - lrdheat - 09-23-2018, 06:51 PM RE: Summation on HP 42S - ijabbott - 09-23-2018, 07:40 PM RE: Summation on HP 42S - burkhard - 09-25-2018, 12:58 PM RE: Summation on HP 42S - John Keith - 09-25-2018, 04:15 PM RE: Summation on HP 42S - Thomas Klemm - 09-23-2018, 08:29 PM RE: Summation on HP 42S - lrdheat - 09-23-2018, 09:25 PM RE: Summation on HP 42S - Didier Lachieze - 09-23-2018, 10:03 PM RE: Summation on HP 42S - lrdheat - 09-23-2018, 10:02 PM RE: Summation on HP 42S - lrdheat - 09-23-2018, 10:37 PM RE: Summation on HP 42S - Thomas Klemm - 09-24-2018, 12:56 AM RE: Summation on HP 42S - Albert Chan - 09-24-2018, 11:56 AM RE: Summation on HP 42S - Thomas Klemm - 09-24-2018, 01:17 AM RE: Summation on HP 42S - Thomas Klemm - 09-24-2018, 01:52 PM RE: Summation on HP 42S - Albert Chan - 09-24-2018, 04:20 PM RE: Summation on HP 42S - pier4r - 09-24-2018, 01:55 PM RE: Summation on HP 42S - Frido Bohn - 09-25-2018, 01:59 PM RE: Summation on HP 42S - Dieter - 09-25-2018, 04:47 PM RE: Summation on HP 42S - Frido Bohn - 09-26-2018 10:10 AM RE: Summation on HP 42S - Albert Chan - 09-26-2018, 03:13 PM RE: Summation on HP 42S - Albert Chan - 09-25-2018, 05:28 PM RE: Summation on HP 42S - lrdheat - 09-25-2018, 05:17 PM RE: Summation on HP 42S - lrdheat - 09-25-2018, 05:28 PM RE: Summation on HP 42S - Albert Chan - 09-25-2018, 07:17 PM RE: Summation on HP 42S - Valentin Albillo - 09-25-2018, 08:01 PM RE: Summation on HP 42S - Albert Chan - 09-25-2018, 08:59 PM RE: Summation on HP 42S - Gerson W. Barbosa - 09-26-2018, 12:36 PM RE: Summation on HP 42S - Albert Chan - 09-26-2018, 01:23 PM RE: Summation on HP 42S - Gerson W. Barbosa - 09-26-2018, 01:54 PM RE: Summation on HP 42S - pier4r - 09-26-2018, 04:09 PM RE: Summation on HP 42S - Thomas Klemm - 09-27-2018, 03:47 AM RE: Summation on HP 42S - Ángel Martin - 09-27-2018, 05:27 AM RE: Summation on HP 42S - pier4r - 09-27-2018, 10:37 PM RE: Summation on HP 42S - Thomas Okken - 09-28-2018, 12:33 AM RE: Summation on HP 42S - pier4r - 09-28-2018, 01:40 PM RE: Summation on HP 42S - ijabbott - 09-28-2018, 11:20 PM RE: Summation on HP 42S - Albert Chan - 09-29-2018, 12:51 AM RE: Summation on HP 42S - Valentin Albillo - 09-29-2018, 01:15 AM RE: Summation on HP 42S - Thomas Okken - 09-29-2018, 01:24 AM RE: Summation on HP 42S - ijabbott - 09-29-2018, 11:58 AM RE: Summation on HP 42S - Albert Chan - 09-29-2018, 12:49 PM RE: Summation on HP 42S - Thomas Okken - 09-29-2018, 01:50 PM RE: Summation on HP 42S - ijabbott - 09-29-2018, 04:06 PM RE: Summation on HP 42S - Thomas Okken - 09-29-2018, 06:15 PM RE: Summation on HP 42S - ijabbott - 09-29-2018, 09:10 PM RE: Summation on HP 42S - Thomas Okken - 09-29-2018, 09:33 PM RE: Summation on HP 42S - Albert Chan - 09-30-2018, 03:03 PM RE: Summation on HP 42S - ijabbott - 09-30-2018, 05:28 PM RE: Summation on HP 42S - brickviking - 10-01-2018, 08:40 AM RE: Summation on HP 42S - pier4r - 09-29-2018, 05:59 PM RE: Summation on HP 42S - Thomas Okken - 09-29-2018, 08:59 PM

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