The Museum of HP Calculators


Calculating the Factorials of Large Numbers for the HP-11C

This program is supplied without representation or warranty of any kind. Gordon Dyer and The Museum of HP Calculators therefore assume no responsibility and shall have no liability, consequential or otherwise, of any kind arising from the use of this program material or any part thereof.

Overview

The HP-10 series calculators and most others with a built in factorial function can only calculate factorials of numbers less than 70. This is because 69≈1.71122E98. Higher factorials overflow the exponent because it is limited to 99.

This program uses the Sharpened Stirling’s Formula to approximate the Factorial of a large number (up to 108). The mantissa and exponent are each calculated and displayed separately to give the complete result. The accuracy is better than 5 decimal places.

If anyone has a good use for large factorials let me know!

FORMULAE, where N is the integer whose factorial will be calculated:

S = 1/(12×N) + 1/(288×N2) – 139/(51840×N3)

L = LOG(√(2xPI×N)) + NxLOG(N/e) + LOG(1 + S)

B = 10FRAC(L)        1 < B < 10

Q = INT(L)

N! = B × 10Q        - result

The program calculates B displayed to 5 decimal places, then Q.

INSTRUCTIONS:

Type in the program, come out of program mode with g P/R, press f CLEAR PRGM.

Type in the value for N and press R/S.

After a few seconds the Mantissa will be displayed to 5 decimal places.

Press R/S, then the Exponent will be displayed. Switch between Mantissa and Exponent display by pressing x⇔y.

HP-11C Program

001 STO 0
002 1
003 2
004 ×
005 1/x
006 RCL 0
007 x2
008 2
009 8
010 8
011 ×
012 1/x
013 +
014 RCL 0
015 3
016 yx
017 5
018 1
019 8
020 4
021 0
022 ×
023 1
024 3
025 9
026 x⇔y
027 ÷
028 -
029 1
030 +
031 LOG
032 RCL 0
033 1
034 ex
035 ÷
036 LOG
037 RCL 0
038 ×
039 +
040 RCL 0
041 π
042 ×
043 2
044 ×
045 √x
046 LOG
047 +
048 STO 1
049 FRAC
050 10x
051 FIX 5
052 R/S
053 RCL 1
054 INT
055 FIX 0
056 PSE
057 FIX 5

Adapted by Gordon Dyer from the HP-41C program given in:
IEEE Transactions on Reliability, vol. R-33, no.4, October 1984, page313-314.

HP-41C Program

001 LBL FF
002 N=?
003 PROMPT
004 STO 00
005 12
006 ×
007 1/x
008 RCL 00
009 x2
010 288
011 ×
012 1/x
013 +
014 RCL 00
015 3
016 yx
017 51840
018 ×
019 139
020 x⇔y
021 ÷
022 -
023 1
024 +
025 LOG
026 RCL 00
027 1
028 ex
029 ÷
030 LOG
031 RCL 00
032 ×
033 +
034 RCL 0
035 π
036 ×
037 2
038 ×
039 √x
040 LOG
041 +
042 STO 01
043 FRC
044 10x
045 FIX 5
046 STOP
047 RCL 01
048 INT
049 FIX 0
050 EXP=
051 ARCLx
052 AVIEW
053 END

Go back to the software library
Go back to the main exhibit hall