Just another update

This commit is contained in:
Ingy döt Net 2015-02-20 00:35:01 -05:00
parent a25938f123
commit 00a190b0a6
6591 changed files with 94363 additions and 23227 deletions

View file

@ -0,0 +1,11 @@
(define (nth-root n a)
(let ((x1 a)
(x2 (div a n)))
(until (= x1 x2)
(setq x1 x2
x2 (div
(add
(mul x1 (- n 1))
(div a (pow x1 (- n 1))))
n)))
x2))

View file

@ -0,0 +1,18 @@
class NthRoot {
function : Main(args : String[]) ~ Nil {
NthRoot(5, 34, .001)->PrintLine();
}
function : NthRoot(n : Int, A: Float, p : Float) ~ Float {
x := Float->New[2];
x[0] := A;
x[1] := A / n;
while((x[1] - x[0])->Abs() > p) {
x[0] := x[1];
x[1] := ((n - 1.0) * x[1] + A / x[1]->Power(n - 1.0)) / n;
};
return x[1];
}
}

View file

@ -12,6 +12,6 @@
N ) ) )
X2 ) )
(prinl (format (nthroot 2 2.0) *Scl))
(prinl (format (nthroot 3 12.3) *Scl))
(prinl (format (nthroot 4 45.6) *Scl))
(prinl (format (nthRoot 2 2.0) *Scl))
(prinl (format (nthRoot 3 12.3) *Scl))
(prinl (format (nthRoot 4 45.6) *Scl))

View file

@ -21,7 +21,7 @@ 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 "logrithm". */
g= (? / r'E'_ % r) + (x>1) /*kinda uses a crude "logarithm".*/
numeric fuzz 3 /*fuzz digits for higher roots. */
d=5 /*start with only five digits. */
do until d==dm; d=min(d+d,dm) /*each interation doubles prec. */