Data update

This commit is contained in:
Ingy döt Net 2025-02-27 18:35:13 -05:00
parent 8e4e15fa56
commit 72eb4943cb
1853 changed files with 35514 additions and 9441 deletions

View file

@ -0,0 +1,24 @@
#!/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(a, n, x, y, a_n, n1_n) {
# no need for eps, the values are monotonically decreasing
# until the root is found (if the initial value is above the root)
x = 1 + a / n # starting value above the root
a_n = a/n # precompute loop invariants
n1_n = (n - 1) / n
do {
y = x
x = n1_n * x + a_n / x^(n-1)
} while (x < y)
# no harm to use average if x = y
return (x + y) / 2
}

View file

@ -0,0 +1,8 @@
{
x = $0
do {
y = x
x = (x + $0/x)/2
} while (x < y)
print "sqrt(" a ")=" x
}