fractions
Rational Approximation

Description

A collection of functions for fractional approximation of numbers.

Usage

fractions(x, cycles = 10, max.denominator = 2000, ...)
as.fractions(x)
is.fractions(x)

## S3 method for class 'fractions': "["(x, ...) ## S3 method for class 'fractions': "[<-"(x, ..., value) ## S3 method for class 'fractions': as.character(x, ...) ## S3 method for class 'fractions': print(x, ...) ## S3 method for class 'fractions': t(x)

# Group functions ## S3 method for class 'fractions': Math(x, ...) ## S3 method for class 'fractions': Ops(e1, e2) ## S3 method for class 'fractions': Summary(x, ..., na.rm)

Arguments

x any numeric mode of object for fractions and as.fractions; NA is allowed in this case. Can be an object of class "fractions" for other methods.
cycles This argument is ignored.
max.denominator The maximum denominator to consider for fractional approximation.
... other optional arguments passed to or from methods.
value the replacement value for the relevant piece of the object.
e1, e2 two objects of class "fractions".
na.rm a logical flag. If TRUE, missing values are ignored for the group functions of Summary.

Details

fractions(x) uses the Euclidean algorithm to compute continued fraction approximations for the numbers in x. It terminates the algorithm when the denominator exceeds max.denominator. This gives the best rational approximation to x with a denominator less than or equal to max.denomiator. The fraction is in lowest terms.
fractions(x) creates a text form of this approximation of the form "numerator/denominator", or "numerator" if the denomiator is 1, and attaches that to its input as the attribute "fracs" makes the result of class "fractions".
The main use of this function is to print values that you expect to be the ratio of small integers. The arithmetic operators do not work on the rational representations; rather, they do the arithmetic on the original numbers and recompute the rational representations from the results of the arithmetic.
Value

fractions and as.fractionsreturn an object of class "fractions", which is a structure with a data value of input x and an attribute "fracs" containing a character vector representing the numerators and denominators.
is.fractionsreturns TRUE if x is an object of class "fractions". Otherwise, it returns FALSE.
For other S3 methods, See their generic functions for the returned value.
See Also
Math, Ops, Summary, Extract
Examples
fractions(c(0.2, 1.3, -0.4, 3.25))
A <- fractions(matrix(c(0.2, -0.4, 3.25, 2.5), nrow=2))
A
A[2,2] <- 0.85001 # close to 17/20
A
fractions(asin(0.965926)/pi)
Package terrUtils version 6.1.1-7
Package Index