Data update
This commit is contained in:
parent
81fd053722
commit
52a6ef48dd
10248 changed files with 63654 additions and 6775 deletions
12
Task/Nth-root/EMal/nth-root.emal
Normal file
12
Task/Nth-root/EMal/nth-root.emal
Normal file
|
|
@ -0,0 +1,12 @@
|
|||
fun nthRoot ← real by real n, real x, real precision
|
||||
Pair result ← real%real(x ⇒ x / n).named("previous", "current")
|
||||
while abs(result.current - result.previous) > precision
|
||||
result.previous ← result.current
|
||||
result.current ← ( (n - 1) * result.current + x / result.current ** (n - 1) ) / n
|
||||
end
|
||||
return result.current
|
||||
end
|
||||
writeLine("{ \"nthroot\": ", nthRoot(2, 152.2756, 0.00000000000001), ", \"builtin\": ", √152.2756, " }")
|
||||
writeLine("{ \"nthroot\": ", nthRoot(5, 34.0, 0.00000000000001), ", \"builtin\": ", 5 // 34.0, " }")
|
||||
writeLine("{ \"nthroot\": ", nthRoot(10, 42.0, 0.00000000000001), ", \"builtin\": ", 10 // 42.0, " }")
|
||||
writeLine("{ \"nthroot\": ", nthRoot(0.5, 7.0, 0.000000000001), ", \"builtin\": ", 0.5 // 7, " }")
|
||||
Loading…
Add table
Add a link
Reference in a new issue