Just another update
This commit is contained in:
parent
a25938f123
commit
00a190b0a6
6591 changed files with 94363 additions and 23227 deletions
|
|
@ -1,34 +1,27 @@
|
|||
/*REXX program computes the factorial of a non-negative integer, and */
|
||||
/* automatically adjusts the number of digits to accommodate the answer.*/
|
||||
|
||||
/*This version allows for faster multiplying of #s (no trailing zeros).*/
|
||||
numeric digits 100 /*start with 100 digits. */
|
||||
numeric form /*indicates we want scientric form*/
|
||||
parse arg n .; if n=='' then n=0 /*get argument from command line. */
|
||||
|
||||
/*════════════════════════════════════where the rubber meets the road. */
|
||||
!=1 /*define factorial product so far.*/
|
||||
do j=2 to n /*compute factorial the hard way. */
|
||||
o!=! /*save old ! in case of overflow. */
|
||||
!=!*j /*multiple the factorial with J, */
|
||||
/* and strip all trailing zeroes. */
|
||||
if pos('E',!)\==0 then do /*is ! in exponential notation? */
|
||||
d=digits() /*D is current digs*/
|
||||
numeric digits d+d%10 /*add ten percent. */
|
||||
!=o!*j /*recalculate for the lost digit. */
|
||||
end
|
||||
!=strip(!,'tail-end',0) /*kill some electrons, strip 0's. */
|
||||
end /*(above) only 1st letter is used.*/
|
||||
/*let's perform some housekeeping.*/
|
||||
if pos('E',!)\==0 then !=strip(!/1,"T",0) /*! in exponential notation?*/
|
||||
v=5; tz=0
|
||||
do while v<=n /*calculate # of trailing zeroes. */
|
||||
tz=tz+n%v
|
||||
v=v*5
|
||||
end /*while v≤n*/
|
||||
!=! || copies(0,tz) /*add some water to rehydrate !. */
|
||||
/*REXX program computes the factorial of a number, striping trailing 0's*/
|
||||
numeric digits 200 /*start with two hundred digits. */
|
||||
parse arg N .; if N=='' then N=0 /*get argument from command line.*/
|
||||
!=1 /*define factorial produce so far*/
|
||||
/*═══════════════════════════════════════where the rubber meets the road*/
|
||||
do j=2 to N /*compute factorial the hard way.*/
|
||||
old!=! /*save old ! in case of overflow.*/
|
||||
!=!*j /*multiple old factorial with J.*/
|
||||
if pos('E',!)\==0 then do /*is ! in exponential notation?*/
|
||||
d=digits() /*D temporarly stores # digits.*/
|
||||
numeric digits d+d%10 /*add 10% do digits.*/
|
||||
!=old!*j /*recalculate for the lost digits*/
|
||||
end /*IFF ≡ if and only if. [↓] */
|
||||
if right(!,1)==0 then !=strip(!,,0) /*strip trailing zeroes IFF the*/
|
||||
end /*j*/ /* [↑] right-most digit is zero.*/
|
||||
z=0 /*the number of trailing zeroes. */
|
||||
do v=5 by 0 while v<=N /*calculate # of trailing zeroes.*/
|
||||
z=z+N%v /*bump Z if multiple power of 5. */
|
||||
v=v*5 /*calculate the next power of 5. */
|
||||
end /*while v≤N*/ /* [↑] advance V by ourselves.*/
|
||||
/*══════════════════════════════════════════════════════════════════════*/
|
||||
|
||||
say n'! is ['length(!) "digits]:" /*display # of digits in factorial*/
|
||||
say /*add some whitespace to output, */
|
||||
say ! /* ... and display the ! product.*/
|
||||
!=! || copies(0,z) /*add water to rehydrate the !. */
|
||||
if z==0 then z='no' /*use gooder English for message.*/
|
||||
say N'! is ['length(!) " digits with " z ' trailing zeroes]:'
|
||||
say /*display blank line (whitespace)*/
|
||||
say ! /* ··· and display the ! product.*/
|
||||
/*stick a fork in it, we're done.*/
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue