Post Reply 
Example Program to calculate Factorial
02-02-2018, 03:15 PM
Post: #24
RE: Example Program to calculate Factorial
(02-02-2018 08:44 AM)Dieter Wrote:  
(02-02-2018 05:05 AM)Thomas Okken Wrote:  It is possible that the ROM uses a better algorithm, but in the case of n!, I think the basic multiplication is used everywhere.

Now take a real (hardware) HP35s and calculate a few factorials:

100! ... 120! ... 150! ... the calculation takes about one second until the result is displayed. Then continue:
155! ... 157! ... 158! ... again, it takes about 1½ seconds.
159! ... 160! ... and now the answer is returned almost immediately. Up to 253! it gets only slightly slower, finally about half a second is required. So 250! is about twice as fast as 150!.

What's going on there? Since the 35s factorial key also handles the Gamma function and Gamma is calculated faster than a simple factorial (yes – try 150! and 150,2!) I suspect this may be related to a fast Gamma code.

It sounds like it may have a hard-coded value for 160!, so calculations for n >= 160 would require only n - 160 multiplications. That could have been done keep the calculation time from becoming too long, or to keep the error from growing beyond the guard digits.

(02-02-2018 01:53 PM)Gerson W. Barbosa Wrote:  1) I cannot find X<Y anywhere on my HP-33C;

2) The stack is not properly handled.

What calculator was that program written for?

The HP-25 has X<Y. (Hmm, was it the only HP to have that function until the 41C?)
Visit this user's website Find all posts by this user
Quote this message in a reply
Post Reply 


Messages In This Thread
RE: Example Program to calculate Factorial - Thomas Okken - 02-02-2018 03:15 PM



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