rat.RdGenerate continuous fractions for numeric values.
rat(x, tol = 1e-06)
rats(x, tol = 1e-06)rat generates continuous fractions, while rats prints the
the corresponding rational representation and returns the numeric values.
rat returns a character vector of string representations of
continuous fractions in the format [b0; b1, ..., b_{n-1}].
rats prints the rational number and returns a numeric vector.
Essentially, these functions apply contfrac.
numbers::contfrac
rat(pi)
#> [1] "[ 3; 7, 15, 1]"
rats(pi)
#> 355/113
rat(sqrt(c(2, 3, 5)), tol = 1e-15)
#> [1] "[ 1; 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2]"
#> [2] "[ 1; 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1]"
#> [3] "[ 2; 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4]"
rats(sqrt(c(2, 3, 5)), tol = 1e-15)
#> 54608393/38613965
#> 50843527/29354524
#> 70711162/31622993