Data commit
This commit is contained in:
parent
7387c8f97b
commit
cb5bb5e222
199093 changed files with 3378972 additions and 0 deletions
22
Task/Nth-root/AWK/nth-root.awk
Normal file
22
Task/Nth-root/AWK/nth-root.awk
Normal file
|
|
@ -0,0 +1,22 @@
|
|||
#!/usr/bin/awk -f
|
||||
BEGIN {
|
||||
# test
|
||||
print nthroot(8,3)
|
||||
print nthroot(16,2)
|
||||
print nthroot(16,4)
|
||||
print nthroot(125,3)
|
||||
print nthroot(3,3)
|
||||
print nthroot(3,2)
|
||||
}
|
||||
|
||||
function nthroot(y,n) {
|
||||
eps = 1e-15; # relative accuracy
|
||||
x = 1;
|
||||
do {
|
||||
d = ( y / ( x^(n-1) ) - x ) / n ;
|
||||
x += d;
|
||||
e = eps*x; # absolute accuracy
|
||||
} while ( d < -e || d > e )
|
||||
|
||||
return x
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue