Learn R Programming

Rmpfr (version 1.1-0)

num2bigq: BigQ / BigRational Approximation of Numbers

Description

num2bigq(x) searches for “small” denominator bigq aka ‘bigRational’ approximations to numeric or "mpfr" x.

It uses the same continued fraction approximation as package MASS' fractions(), but using big integer, rational and mpfr-arithmetic from packages Rmpfr and gmp.

Usage

num2bigq(x, cycles = 50L, max.denominator = 2^25, verbose = FALSE)

Value

a big rational, i.e., bigq (from gmp) vector of the same length as x.

Arguments

x

numeric or mpfr-number like

cycles

a positive integer, the maximal number of approximation cycles, or equivalently, continued fraction terms to be used.

max.denominator

an approximate bound on the maximal denominator used in the approximation. If small, the algorithm may use less than cycles cycles.

verbose

a logical indicating if some intermediate results should be printed during the iterative approximation.

Author

Bill Venables and Brian Ripley, for the algorithm in fractions(); Martin Maechler, for the port to use Rmpfr and gmp arithmetic.

See Also

.mpfr2bigq() seems similar but typically uses much larger denominators in order to get full accuracy.

Examples

Run this code
num2bigq(0.33333)

num2bigq(pi, max.denominator = 200) #  355/113
num2bigq(pi) # much larger
num2bigq(pi, cycles=10) # much larger

Run the code above in your browser using DataLab