Data update

This commit is contained in:
Ingy döt Net 2025-02-27 18:35:13 -05:00
parent 8e4e15fa56
commit 72eb4943cb
1853 changed files with 35514 additions and 9441 deletions

View file

@ -1,38 +0,0 @@
/*REXX program calculates the Nth root of X, with DIGS (decimal digits) accuracy. */
parse arg x root digs . /*obtain optional arguments from the CL*/
if x=='' | x=="," then x= 2 /*Not specified? Then use the default.*/
if root=='' | root=="," then root= 2 /* " " " " " " */
if digs=='' | digs=="," then digs=65 /* " " " " " " */
numeric digits digs /*set the decimal digits to DIGS. */
say ' x = ' x /*echo the value of X. */
say ' root = ' root /* " " " " ROOT. */
say ' digits = ' digs /* " " " " DIGS. */
say ' answer = ' root(x, root) /*show the value of ANSWER. */
exit /*stick a fork in it, we're all done. */
/*──────────────────────────────────────────────────────────────────────────────────────*/
root: procedure; parse arg x 1 Ox, r 1 Or /*arg1 ──► x & Ox, 2nd ──► r & Or*/
if r=='' then r=2 /*Was root specified? Assume √. */
if r=0 then return '[n/a]' /*oops-ay! Can't do zeroth root.*/
complex= x<0 & R//2==0 /*will the result be complex? */
oDigs=digits() /*get the current number of digs.*/
if x=0 | r=1 then return x/1 /*handle couple of special cases.*/
dm=oDigs+5 /*we need a little guard room. */
r=abs(r); x=abs(x) /*the absolute values of R and X.*/
rm=r-1 /*just a fast version of ROOT -1*/
numeric form /*take a good guess at the root─┐*/
parse value format(x,2,1,,0) 'E0' with ? 'E' _ . /* ◄────────────────────────────┘*/
g= (? / r'E'_ % r) + (x>1) /*kinda uses a crude "logarithm".*/
d=5 /*start with five decimal digits.*/
do until d==dm; d=min(d+d,dm) /*each time, precision doubles. */
numeric digits d /*tell REXX to use D digits. */
old=-1 /*assume some kind of old guess. */
do until old=g; old=g /*where da rubber meets da road─┐*/
g=format((rm*g**r+x)/r/g**rm,, d-2) /* ◄────── the root computation─┘*/
end /*until old=g*/ /*maybe until the cows come home.*/
end /*until d==dm*/ /*and wait for more cows to come.*/
if g=0 then return 0 /*in case the jillionth root = 0.*/
if Or<0 then g=1/g /*root < 0 ? Reciprocal it is! */
if \complex then g=g*sign(Ox) /*adjust the sign (maybe). */
numeric digits oDigs /*reinstate the original digits. */
return (g/1) || left('j', complex) /*normalize # to digs, append j ?*/

View file

@ -1,4 +0,0 @@
do until old=g; old=g /*where da rubber meets da road-+*/<br>
g=format((rm*g**r+x)/r/g**rm,, d-2) /* ?------ the root computation-+*/<br>
'''say 'g' g 'old' old'''<br>
end /*until old=g*/ /*maybe until the cows come home.*/<br>

View file

@ -10,49 +10,8 @@ numeric digits digs /*set the decimal digits to
say ' x = ' x /*echo the value of X. */
say ' root = ' root /* " " " " ROOT. */
say ' digits = ' digs /* " " " " DIGS. */
say ' answer = ' nroot(x, root) /*show the value of ANSWER. */
say ' answer = ' Nroot(x, root) /*show the value of ANSWER. */
exit /*stick a fork in it, we're all done. */
/*--------------------------------------------------------------------------------------*/
Nroot:
/* Nth root function = x^(1/n) */
procedure expose glob.
arg x,n
/* Fast values */
if x = 0 then
return 0
if x = 1 then
return 1
/* Formulas using faster methods */
if n = 2 then
return Sqrt(x)
if n = 3 then
return Cbrt(x)
if n = 4 then
return Qtrt(x)
/* Calculate */
sx = Sign(x); x = Abs(x)
p1 = Digits(); p2 = p1+2
numeric digits 3
/* First guess low accuracy */
y = 1/Exp(Ln(x)/n)
numeric digits p2
/* Dynamic precision */
d = p2
do k = 1 while d > 4
d.k = d; d = d%2+1
end
d.k = 4
/* Halley */
a = 1/n; b = n+1
do j = k to 1 by -1
numeric digits d.j
y = y*a*(b-x*y**n)
end
y = 1/y
if sx < 0 then
y = -y
numeric digits p1
return y+0
include Numbers
include Functions