tasks a-s
This commit is contained in:
parent
47bf37c096
commit
b83f433714
12433 changed files with 156208 additions and 123 deletions
19
Task/Nth-root/Go/nth-root.go
Normal file
19
Task/Nth-root/Go/nth-root.go
Normal file
|
|
@ -0,0 +1,19 @@
|
|||
func root(a float64, n int) float64 {
|
||||
n1 := n - 1
|
||||
n1f, rn := float64(n1), 1/float64(n)
|
||||
x, x0 := 1., 0.
|
||||
for {
|
||||
potx, t2 := 1/x, a
|
||||
for b := n1; b > 0; b >>= 1 {
|
||||
if b&1 == 1 {
|
||||
t2 *= potx
|
||||
}
|
||||
potx *= potx
|
||||
}
|
||||
x0, x = x, rn*(n1f*x+t2)
|
||||
if math.Abs(x-x0)*1e15 < x {
|
||||
break
|
||||
}
|
||||
}
|
||||
return x
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue