This program calculates and displays the factorial for any integer value between 0 and 253 inclusive. See notes below on what limitations there are on using numbers of 10^{100} and above. There is no error trap for non-integer values of 70 or greater. In this case the value returned will be the factorial of the integer value below the value entered. There is also no error trap for input values greater than 253. In this case the returned value is zero.
The program should run on the FX-501P if all references to M1F are replaced with an otherwise unused memory that that calculator has, such as M1.
Calculate factorial 253.
Data Input Operation | Read-out | Remark |
---|---|---|
Mode 1 | 0. | Reset |
253 P2 | 5.17346099^{499} | The answer to 253!.See screen shot (86kB) (My HP48S, which can do 253! without programming, confirms the answer as 5.17346099264×10^{499}) |
Instead of typing in the below, if you've got the cassette adaptor try the *.wav files for both the program and the memories.
Program for Factorials to 253! | ||
---|---|---|
Program | Remark | |
MODE, 2, | Go to program mode | |
P2 | Abitrary choice of program number | |
Min3, 7, 0, MinF, Min0, MR3, INV x>=F, GOTO 0, INV x!, GOTO 3, | Store input number and determine if it's less than 70. If it is then use built in factorial function and go to the end of the program. If it isn't then continue at label 1. | |
LBL 0, | MinF, MR1F, ×, 6, 9, INV x!, ×, MR0, ÷, ÷, 1, EXP, 5, 0, X<->Y, =, =, | Put the input number into MF. Generate factorial 70 by calculating 10^{100}×69!×70÷10^{50}÷10^{50}. See note on use of large numbers below to see why it is done like this. |
LBL 1, | ×, INV ISZ, MR0, INV x>=F, GOTO 2, =, GOTO 1, | Loop round multiplying by an incrementing counter from 71 to the number input until the number input has been reached, then go to label 2. |
LBL 2, | INV x=F, GOTO 3, 1, | The incrementing counter has reached the number input but check that it was not exceeded. It will only have been exceeded if the input number is 70 or has a fractional component, so kill the last multiplication by replacing it by 1. |
LBL 3, | =, ENG | Force display of answer in engineering form to cope with answers whose exponent has zero in the tens column. |
Total number of steps = 43 |
Contents in memories | |||
---|---|---|---|
0 | Counter | .0 | not used |
1 | not used | .1 | not used |
2 | not used | .2 | not used |
3 | Input number | .3 | not used |
4 | not used | .4 | not used |
5 | not used | .5 | not used |
6 | not used | .6 | not used |
7 | not used | .7 | not used |
8 | not used | .8 | not used |
9 | not used | .9 | not used |
F | 70 or input number | .F | 1×10^{100}. (This is a constant that has to be present at the start of program. It can be generated as shown below.) |
Generation of 1×10^{100} on the FX-502P (but not the FX-602P) | |
---|---|
Interactive Input | Remark |
MODE, 1, | Go to run mode. |
3, 2, Min0, AC, INV IND, MR0, | Put 32 into a memory and then try to recall M32 - a memory that the calculator doesn't have. |
× 1, ÷ 1, ., 6, 6, 5, +/- = | Get rid of the space characters. |
÷÷1,EXP,99,X<->Y,=,=,=,÷1,EXP,85,= | Reduce the exponent to 100. (Note that you'll have to press ENG to show the exponent because the tens column of the exponent is zero) |
Notes on Numbers of 10^{100} and above | |
---|---|
1 | If the answer would be 1×10^{500} or greater, after the multiplication with a number under 10^{100}, then the value 0 is returned. No error is reported. |
2 | If the answer is 1×10^{100} or greater and the tens column of the exponent is 0 then the number is displayed as though there were no hundreds in the exponent. This can be put right by pressing ENG to display the true value. (e.g. an answer of 1×10^{206} would be displayed as 1000000.) |
3 | If you multiply 2 numbers that are higher than 10^{100} the result is wrong by being too big by a factor of 10^{100} (e.g. on the FX-502P 1×10^{100} × 1×10^{100} = 1×10^{300}) |
4 | If you divide 2 numbers that are higher than 10^{100} the result is wrong by being too small by a factor of 10^{100} (e.g. on the FX-502P 1×10^{300} ÷ (1×10^{100}) = 1×10^{100}) |
5 | An 'E' error is caused if a division operation using a number above, and a number below, 10^{100} takes a number below the 10^{100}. (e.g. an error would be caused by 1×10^{110} ÷ (1×10^{30}) |
6 | An 'E' error is caused if a division operation using 2 numbers above 10^{100} takes a number below the 10^{100} using the the extra 1×10^{100} referred to in Note 4. (e.g. an error would be caused by 1×10^{250} ÷ (1×10^{100}) |
7 | If 2 values above 10^{100} are multiplied together and the result should be between 10^{501} and 10^{700} exclusive then the answer will be returned between -1^{-99} and -1^{100} exclusive (e.g. 10^{250}×10^{300}=-10^{-50}.) |
8 | If 2 values above 10^{100} are multiplied together and the result should be between 10^{700} and 10^{800} exclusive then the result is an E error. |
9 | If 2 values above 10^{100} are multiplied together and the result should be between 10^{800} and 10^{1000} then the answer will be returned between -10^{100} and -10^{300} exclusive (e.g. 10^{450}×10^{450}=-10^{200}.) |