Find rational approximations to the components of a real numeric object using a standard continued fraction method.
fractions(x, cycles = 10, max.denominator = 2000, …)
- Any object of mode numeric. Missing values are now allowed.
- The maximum number of steps to be used in the continued fraction approximation process.
An early termination criterion. If any partial denominator
max.denominatorthe continued fraction stops at that point.
- arguments passed to or from other methods.
Each component is first expanded in a continued fraction of the
x = floor(x) + 1/(p1 + 1/(p2 + …))) where
p2, … are positive integers, terminating either
cycles terms or when a
pj > max.denominator. The
continued fraction is then re-arranged to retrieve the numerator
and denominator as integers. The numerators and denominators are then combined into a
character vector that becomes the
"fracs" attribute and used in
printed representations. Arithmetic operations on
"fractions" objects have full floating
point accuracy, but the character representation printed out may
An object of class
"fractions". A structure with
the same as the input numeric
x, but with the rational
approximations held as a character vector attribute,
Arithmetic operations on
"fractions" objects are possible.
Venables, W. N. and Ripley, B. D. (2002) Modern Applied Statistics with S. Fourth Edition. Springer.
X <- matrix(runif(25), 5, 5) zapsmall(solve(X, X/5)) # print near-zeroes as zero fractions(solve(X, X/5)) fractions(solve(X, X/5)) + 1