as_cf {contfrac} | R Documentation |
Converts a real number to continued fraction form using a standard simple algorithm
as_cf(x, n = 10)
x |
real number to be converted to continued fraction form |
n |
Number of partial denominators to evaluate; see Notes |
Has difficulties with rational values as expected
Robin K. S. Hankin
phi <- (sqrt(5)+1)/2 as_cf(phi,50) # loses it after about 38 iterations ... not bad ... as_cf(pi) # looks about right as_cf(exp(1),20) f <- function(x){CF(as_cf(x,30),TRUE) - x} x <- runif(40) plot(sapply(x,f))