11 lines
266 B
Text
11 lines
266 B
Text
fcn nthroot(nth,a,precision=1.0e-5){
|
|
x:=prev:=a=a.toFloat(); n1:=nth-1;
|
|
do{
|
|
prev=x;
|
|
x=( prev*n1 + a/prev.pow(n1) ) / nth;
|
|
}
|
|
while( not prev.closeTo(x,precision) );
|
|
x
|
|
}
|
|
|
|
nthroot(5,34) : "%.20f".fmt(_).println() # => 2.02439745849988828041
|