sqrt はまあ実用的
sqrt.bigq <- function(x, eps=1e-50)
{
x2 <- as.bigq(sqrt(as.double(x)))
repeat {
x3 <- (x2+x/x2)/2
if (abs(x2-x3) < eps) break
x2 <- x3
}
return(x3)
}
# as.double(sqrt.bigq(5000.45789))^2
# sqrt(as.bigq(3.456))
3 乗根
qubic.root <- function(x, eps=1e-50)
{
x2 <- as.bigq(as.double(x)^(1/3))
repeat {
x3 <- (x/(x2*x2)+2*x2)/3
if (abs(x2-x3) < eps) break
x2 <- x3
}
return(x3)
}
# as.double(qubic.root(123.4566789))^3
exp は取りあえず使えればよいものということで
exp.bigq <- function(x, eps=1e-50, n.term=1000)
{
ans <- xp <- fac <- as.bigq(1)
for (i in 1:n.term) {
xp <- xp*x
fac <- fac*i
old <- ans
ans <- ans+xp/fac
if (abs(old-ans) < eps) {
return(ans)
}
}
warnings("収束せず")
return(ans)
}
# log(as.double(exp.bigq(40.235)))
# exp(as.bigq(1.234))
※コメント投稿者のブログIDはブログ作成者のみに通知されます