Special factorials: Difference between revisions

m
→‎{{header|REXX}}: simplified some code.
m (af(0) is 0)
m (→‎{{header|REXX}}: simplified some code.)
Line 186:
<lang rexx>/*REXX program to compute some special factorials: superfactorials, hyperfactorials,*/
/*───────────────────────────────────── alternating factorials, exponential factorials.*/
numeric digits 100 /*allowallows humonoushumongous numbersresults to be computedshown.*/
parsecall arghdr LO'super'; HI nef xef nrf xrf do j=0 to 9; $= $ /*obtainsf(j); optional arguments from theend; CL*/ call tell
ifcall hdr LO=='hyper'; | LO=="," then LO= do j=0 to 9; $= $ hf(j); end; /*Not specified? Then use thecall default.*/tell
ifcall hdr HI=='alternating '; | HI=="," then do HIj=0 to 9; $= $ af(j); end; /* " " " " " " call */tell
ifcall hdr nef=='exponential '; | nef=="," then nef do j=0 to 5; $= $ ef(j); end; /* " " " " " " call */tell
if xef=='' | xef=="," then xef= nef /* " " " " " " */
if nrf=='' | nrf=="," then nrf= 10 /* " " " " " " */
if nef=='' | nef=="," then nef= 5 /* " " " " " " */
if xrf=='' | xrf=="," then xrf= 119 /* " " " " " " */
num= HI-LO+1 /*calculate the # of numbers to be used*/
call hdr num, 'super'; do j=LO to HI; $= $ sf(j); end; call tell
call hdr num, 'hyper'; do j=LO to HI; $= $ hf(j); end; call tell
call hdr num, 'alternating '; do j=LO to HI; $= $ af(j); end; call tell
call hdr nef, 'exponential '; do j=0 for nef; $= $ ef(j); end; call tell
@= 'the number of decimal digits in the exponential factorial of '
say @ xef5 " is:"; $= ' 'commas( efn( ef( xef5) ) ); call tell
@= 'the inverse factorial of '
do j=1 for nrf10; fp=say @ || right(!(j);, 9) say @ fp " is: " rf(fp!(j))
end /*j*/
 
say @ xrf " is: " rf(xrf)
if nrf=='' | nrf=="," then nrf= 10 /* " " " " " say @ || right(119, 9) " is: " */rf(119)
exit 0 /*stick a fork in it, we're all done. */
/*──────────────────────────────────────────────────────────────────────────────────────*/
Line 213 ⟶ 205:
commas: parse arg ?; do jc=length(?)-3 to 1 by -3; ?=insert(',', ?, jc); end; return ?
ef: procedure; parse arg x; if x==0 | x==1 then return 1; return x**ef(x-1)
efn: procedure; parse arg x; numeric digits 9; x= x; parse var x 'E' d; return d+1
sf: procedure; parse arg x; != 1; do #=2 to x; != ! * !(#); end; return !
hf: procedure; parse arg x; != 1; do #=2 to x; != ! * #**#; end; return !
hdrrf: procedure; parse arg nn,what,,$x; say 'the first ' nndo #=0 until "f>=x; "what'factorials:'f=!(#); end; return rfr()
tellrfr: say substr($, 2); say; if x==f then return $=#; ?= 'undefined'; return return?
hdr: parse arg ?,,$; say 'the first ten '?"factorials:"; return
/*──────────────────────────────────────────────────────────────────────────────────────*/
iftell: xef=='' | xef=="say substr($," 2); then xef= nef say; /* " " $=; " " " " *return</lang>
rf: procedure; parse arg x,u; do #=0 until f>x; f=!(#); if x==f then return #; end
return 'undefined'</lang>
{{out|output|text=&nbsp; when using the internal default input:}}
<pre>