(12C) Factorial in Stack

04072023, 08:10 AM
(This post was last modified: 04072023 08:11 AM by Gamo.)
Post: #1




(12C) Factorial in Stack
Been a long time, anyway here is a little 10 steps program
to calculate Factorial using only the stack in program. The computation speed is really good but can not compare with the [n!] function. Program Quote:01 INTG // Additional INTG corrects fractions.Example: FIX 0 12 [R/S] 479,001,600 69 [R/S] 1.711224 98 Gamo 4/7/2023 

04172023, 12:22 PM
Post: #2




RE: (12C) Factorial in Stack
Hi. Why do you do INTG twice?


04172023, 06:34 PM
Post: #3




RE: (12C) Factorial in Stack  
04182023, 06:13 AM
Post: #4




RE: (12C) Factorial in Stack
This program works nicely on the HP25 too. It is the same number of steps as the Factorial program included in the HP25 Applications Programs book but that uses Reg 0 and will return incorrect results if the input is not an integer.


04182023, 07:01 AM
Post: #5




RE: (12C) Factorial in Stack
3 steps version without n! here:
https://www.hpmuseum.org/forum/thread10...l#pid90191 If you want some user friendly interaction, 9 steps, also included on the link. Cs. 

04222023, 04:36 AM
Post: #6




RE: (12C) Factorial in Stack
Yes, the builtin n! function is much quicker but may not be as accurate. The OP’s program takes 28 seconds to calculate 69! on my 1987 USA HP12C. The builtin n! function takes less than a second. When I subtract the results I get a difference of 2.E89. I am not 100% sure which result is more correct. I would expect the brute force program listed here would be more accurate since it only employs multiplication but the result is beyond 10 digits in this case so rounding is occurring.


04222023, 07:32 AM
Post: #7




RE: (12C) Factorial in Stack
The value of 69! in full is
171 122 452 428 141 311 372 468 338 881 272 839 092 270 544 893 520 369 393 648 040 923 257 279 754 140 647 424 000 000 000 000 000 Can you tell which is closer? Perhaps see also (12C Platinum) Internal Precision Test 

04222023, 07:53 AM
Post: #8




RE: (12C) Factorial in Stack
EdS2,
The builtin n! function is closer. It’s final result is accurate to 10digits (1711224524). The program returns 1711224522 so it is only accurate to 9digits. Rounding off to 10 significant digits after each multiplication and using that for the next multiplication takes its toll. 

« Next Oldest  Next Newest »

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