cfrac2num {contFracR} | R Documentation |
Function to convert a defined set of numerators and denominators into the equivalent number.
Description
Given a vector of denominators and optionally a vector of numerators, calculate the bigq
fraction and the mpfr
extended precision decimal value.
Usage
cfrac2num(denom, num = 1, init = 0, nreps= 1, msgrate = NULL )
Arguments
denom |
A vector in standard continued fraction form |
num |
A vector of numerator values. If all numerators are the same, a single value will suffice. The default is |
init |
In those cases where the denominator values repeat (e.g., for continued fraction form of square roots), it is possible to take the output of a previous run and use it to initialize a new run. This input must be a |
nreps |
If |
msgrate |
If desired enter an integer indicating how often a status message should be displayed. Leave as |
Details
All calculations are done with bigq
fractions to preserve full precision. Naturally, a finite input will not yield the exact value for any irrational number.
Value
The exact numeric value is provided in cgmp
, a bigq
fraction. The mpfr
value is calculated using .bigq2mpfr
, which generates a decimal number of sufficient precision to match the implied precision of the fraction.
fracpart
equals cgmp
minus the integer part, if any.
denom
and num
provide the vectors of denominator and numerator values used in the calculation.
Author(s)
Carl Witthoft, carl@witthoft.com
See Also
Examples
cfrac2num(rep(1,10)) # approximate phi
frac2 <- sqrt2periodicCfrac(2)
cfrac2num(frac2$numericdenom)
#simple cases
cfrac2num(denom=1)
cfrac2num(denom = c(0,2),num=1)