Skip to content

Commit

Permalink
Merge pull request #176 from jlp765/master
Browse files Browse the repository at this point in the history
rosetta file nth_root.flx added
  • Loading branch information
skaller committed Jan 1, 2023
2 parents f3b6a43 + 0370949 commit 3a47e71
Showing 1 changed file with 16 additions and 0 deletions.
16 changes: 16 additions & 0 deletions src/rosetta/nth_root.flx
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
//translated from Nim

fun nth_root (a: double, n: int): double = {
val dn = n.double;
var res = a;
var x = a / dn;
while abs(res - x) > 1.0e-15 do
x = res;
res = (1.0 / dn) * (((dn - 1.0) * x) + (a / pow(x, dn - 1.0)));
done
return res;
}

println$ f"%.15f" (nth_root(34.0, 5));
println$ f"%.15f" (nth_root(42.0, 10));
println$ f"%.15f" (nth_root(5.0, 2));

0 comments on commit 3a47e71

Please sign in to comment.