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 [b0; a1,a2,a3,...] where b0 represents the integer part of the number and the a_j are the denominator terms. If all terms, including b0 , are the same, optionally enter a single value and specify the length with the numterms value

num

A vector of numerator values. If all numerators are the same, a single value will suffice. The default is 1

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 bigq fraction. Use with care.

nreps

If denoms is a single value, repeat that value nreps times to set up the continued fraction. Otherwise, assume a periodic denominator sequence was submitted, and repeat the denom[-1] section nreps times (the first denominator is the integer term) .

msgrate

If desired enter an integer indicating how often a status message should be displayed. Leave as NULL to suppress messages. For example, setting thi to 10 will generate a message every 10 sub-fraction reductions.

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

num2cfrac

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)

[Package contFracR version 1.2.1 Index]