1 /* recursion test of factorial
*/
2 /* note
: this implementation of rexx uses two kinds of
3 of numbers
integers (C
long (4-bytes
) numbers from
-2E9 upto
2E9
),
4 and
real (C double precision numbers
). It
's better
5 to use a real number ie 45.0 instead of 45 for large
6 factorials since the later will result to a factorial using
7 integer arithmetic resulting in a crazy result
8 (15 is the largest integer factorial that can be calculated
18 if datatype(num) ^= 'NUM
' | num < 0 then do
19 say 'Invalid number
"'num'"'
23 /* you can even translate the number to real with the following instr */
24 /* num = num + 0.0 /* so from now on num will be treated as real */ */
26 say num'! = 'fact(num)
30 if arg(1)<=0 then return 1
31 return fact(arg(1)-1)*arg(1)