\HeaderA{fractions}{Rational Approximation}{fractions}
\aliasA{as.character.fractions}{fractions}{as.character.fractions}
\aliasA{as.fractions}{fractions}{as.fractions}
\aliasA{is.fractions}{fractions}{is.fractions}
\aliasA{Math.fractions}{fractions}{Math.fractions}
\aliasA{Ops.fractions}{fractions}{Ops.fractions}
\aliasA{print.fractions}{fractions}{print.fractions}
\aliasA{Summary.fractions}{fractions}{Summary.fractions}
\aliasA{t.fractions}{fractions}{t.fractions}
\aliasA{[.fractions}{fractions}{[.fractions}
\aliasA{[<\Rdash.fractions}{fractions}{[<.Rdash..fractions}
\keyword{math}{fractions}
\begin{Description}\relax
Find rational approximations to the components of a real numeric
object using a standard continued fraction method.
\end{Description}
\begin{Usage}
\begin{verbatim}
fractions(x, cycles = 10, max.denominator = 2000, ...)
\end{verbatim}
\end{Usage}
\begin{Arguments}
\begin{ldescription}
\item[\code{x}] Any object of mode numeric. Missing values are now allowed.

\item[\code{cycles}] The maximum number of steps to be used in the continued fraction
approximation process.

\item[\code{max.denominator}] An early termination criterion.  If any partial denominator
exceeds \code{max.denominator} the continued fraction stops at that point.

\item[\code{...}] arguments passed to or from other methods.

\end{ldescription}
\end{Arguments}
\begin{Details}\relax
Each component is first expanded in a continued fraction of the
form

\code{x = floor(x) + 1/(p1 + 1/(p2 + ...)))}

where \code{p1}, \code{p2}, \dots are positive integers, terminating either
at \code{cycles} terms or when a \code{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 \code{"fracs"} attribute and used in
printed representations.


Arithmetic operations on \code{"fractions"} objects have full floating
point accuracy, but the character representation printed out may
not.
\end{Details}
\begin{Value}
An object of class \code{"fractions"}.  A structure with \code{.Data} component
the same as the input numeric \code{x}, but with the rational
approximations held as a character vector attribute, \code{"fracs"}.
Arithmetic operations on \code{"fractions"} objects are possible.
\end{Value}
\begin{References}\relax
Venables, W. N. and Ripley, B. D. (2002)
\emph{Modern Applied Statistics with S.} Fourth Edition. Springer.
\end{References}
\begin{SeeAlso}\relax
\code{\LinkA{rational}{rational}}
\end{SeeAlso}
\begin{Examples}
\begin{ExampleCode}
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
\end{ExampleCode}
\end{Examples}

