Data update

This commit is contained in:
Ingy döt Net 2025-06-11 20:16:52 -04:00
parent 72eb4943cb
commit 4d5544505c
2347 changed files with 62432 additions and 16731 deletions

View file

@ -1,18 +1,4 @@
/*REXX pgm computes & shows the factorial of a non─negative integer, and also its length*/
numeric digits 100000 /*100k digits: handles N up to 25k.*/
parse arg n /*obtain optional argument from the CL.*/
if n='' then call er 'no argument specified.'
if arg()>1 | words(n)>1 then call er 'too many arguments specified.'
if \datatype(n,'N') then call er "argument isn't numeric: " n
if \datatype(n,'W') then call er "argument isn't a whole number: " n
if n<0 then call er "argument can't be negative: " n
!= 1 /*define the factorial product (so far)*/
do j=2 to n; !=!*j /*compute the factorial the hard way. */
end /*j*/ /* [↑] where da rubber meets da road. */
say n'! is ['length(!) "digits]:" /*display number of digits in factorial*/
say /*add some whitespace to the output. */
say ! /*display the factorial product──►term.*/
exit /*stick a fork in it, we're all done. */
/*──────────────────────────────────────────────────────────────────────────────────────*/
er: say; say '***error***'; say; say arg(1); say; exit 13
call time('r')
numeric digits 999999999
a = 10/3
say length(a) time('e')

View file

@ -1,22 +1,69 @@
/*REXX program computes the factorial of a non─negative integer, and it automatically */
/*────────────────────── adjusts the number of decimal digits to accommodate the answer.*/
numeric digits 99 /*99 digits initially, then expanded. */
parse arg n /*obtain optional argument from the CL.*/
if n='' then call er 'no argument specified'
if arg()>1 | words(n)>1 then call er 'too many arguments specified.'
if \datatype(n,'N') then call er "argument isn't numeric: " n
if \datatype(n,'W') then call er "argument isn't a whole number: " n
if n<0 then call er "argument can't be negative: " n
!= 1 /*define the factorial product (so far)*/
do j=2 to n; !=!*j /*compute the factorial the hard way. */
if pos(.,!)==0 then iterate /*is the ! in exponential notation? */
parse var ! 'E' digs /*extract exponent of the factorial, */
numeric digits digs + digs % 10 /* ··· and increase it by ten percent.*/
end /*j*/ /* [↑] where da rubber meets da road. */
!= !/1 /*normalize the factorial product. */
say n'! is ['length(!) "digits]:" /*display number of digits in factorial*/
say /*add some whitespace to the output. */
say ! /*display the factorial product ──►term*/
exit /*stick a fork in it, we're all done. */
/*──────────────────────────────────────────────────────────────────────────────────────*/
er: say; say '***error!***'; say; say arg(1); say; exit 13
-- 8 May 2025
include Settings
say 'FACTORIAL'
say version
say
call First20
call Imp 10,'1 10 100 1000 10000 100000 1000000 10000000 100000000 130202808'
call Rec 10,'1 10 100 1000 10000 100000 200000'
call Imp 100,'69'
call Imp 1000,'449'
call Imp 10000,'3248'
call Imp 100000,'25205'
exit
First20:
say 'First 20 factorials...'
numeric digits 30
do n = 1 to 20
say n'! =' Fact(n)
end
say
return
Imp:
glob. = ''
call Time('r')
arg d,p
numeric digits d; fact. = 0
say 'Imperative in' d 'digits precision...'
do i = 1 to Words(p)
call Time('r'); f = Word(p,i); h = Fact(f)
parse var h 'E' e
if e = '' then
say right(f'!',10) 'has exact' right(Length(h),9) 'digits' '('Format(Time('e'),,3)'s)'
else
say right(f'!',10) 'has about' right(e+1,9) 'digits' '('Format(Time('e'),,3)'s)'
end
say
return
Rec:
glob. = ''
call Time('r')
arg d,p
numeric digits d; fact. = 0
say 'Recursive in' d 'digits precision...'
do i = 1 to Words(p)
call Time('r'); f = Word(p,i); h = Recursive(f)
parse var h 'E' e
if e = '' then
say right(f'!',10) 'has exact' right(Length(h),9) 'digits' '('Format(Time('e'),,3)'s)'
else
say right(f'!',10) 'has about' right(e+1,9) 'digits' '('Format(Time('e'),,3)'s)'
end
say
return
Recursive:
procedure
arg xx
if xx = 0 then
return 1
else
return xx*Recursive(xx-1)
include Functions
include Special
include Abend

View file

@ -1,27 +0,0 @@
/*REXX program computes & shows the factorial of an integer, striping trailing zeroes. */
numeric digits 200 /*start with two hundred digits. */
parse arg N . /*obtain an optional argument from CL. */
if N=='' | N=="," then N= 0 /*Not specified? Then use the default.*/
!= 1 /*define the factorial product so far. */
do j=2 to N /*compute factorial the hard way. */
old!= ! /*save old product in case of overflow.*/
!= ! * j /*multiple the old factorial with J. */
if pos(.,!) \==0 then do /*is the ! in exponential notation?*/
d= digits() /*D temporarily stores number digits.*/
numeric digits d+d%10 /*add 10% to the decimal digits. */
!= old! * j /*re─calculate for the "lost" digits.*/
end /*IFF ≡ if and only if. [↓] */
parse var ! '' -1 _ /*obtain the right-most digit of ! */
if _==0 then != strip(!, , 0) /*strip trailing zeroes IFF the ... */
end /*j*/ /* [↑] ... right-most digit is zero. */
z= 0 /*the number of trailing zeroes in ! */
do v=5 by 0 while v<=N /*calculate number of trailing zeroes. */
z= z + N % v /*bump Z if multiple power of five.*/
v= v * 5 /*calculate the next power of five. */
end /*v*/ /* [↑] we only advance V by ourself.*/
/*stick a fork in it, we're all done. */
!= ! || copies(0, z) /*add water to rehydrate the product. */
if z==0 then z= 'no' /*use gooder English for the message. */
say N'! is ['length(!) " digits with " z ' trailing zeroes]:'
say /*display blank line (for whitespace).*/
say ! /*display the factorial product. */

View file

@ -1,4 +0,0 @@
call time('r')
numeric digits 999999999
a = 10/3
say length(a) time('e')

View file

@ -1,67 +0,0 @@
include Settings
say version; say 'Factorial'; say
p = '10 20 52 104 208 416 1e3 1e4 1e5 1e6 1e7 1e8'
call Val 100
p = '10 20 52 104 208 416 1e3 1e4 1e5 1e6'
call Dig 100
call Dig 1000
call Dig 3000
p = '10 20 52 104 208 416 1e3 1e4 1e5'
call Dig 40000
call Dig 500000
p = '10 20 52 104 208 416 1e3 1e4'
call Dig 5000000
exit
Val:
call Time('r')
arg d
numeric digits d; fact. = 0
say 'Precision is' d 'digits'
do i = 1 to Words(p)
call Time('r');f = Word(p,i); say f'!' '=' Fact(f) '('Format(Time('e'),,3)'s)'
end
say
return
Dig:
call Time('r')
arg d
numeric digits d; fact. = 0
say 'Precision is' d 'digits'
do i = 1 to Words(p)
call Time('r'); f = Word(p,i); h = Fact(f)
parse var h 'E' e
if e = '' then
say f'!' 'has exact' Length(h) 'digits' '('Format(Time('e'),,3)'s)'
else
say f'!' 'has about' e+1 'digits' '('Format(Time('e'),,3)'s)'
end
say
return
Fact:
/* Factorial = n! */
procedure expose fact.
arg x
/* Current in memory? */
if fact.factorial.x <> 0 then
return fact.factorial.x
/* Previous in memory? */
w = x-1
if fact.factorial.w = 0 then do
/* Loop cf definition */
y = 1
do n = 2 to x
y = y*n
end
fact.factorial.x = y
end
else
/* Multiply */
fact.factorial.x = fact.factorial.w*x
return fact.factorial.x
include Functions
include Abend