convert.rational.fraction.to.nary: Convert a rational fraction into its base-n (n-nary)...

View source: R/carithmetic.R

convert.rational.fraction.to.naryR Documentation

Convert a rational fraction into its base-n (n-nary) representation using integer arithmetic with Horner's method.

Description

A function to convert a rational fraction into its base-n (n-ary) representation.

Usage

convert.rational.fraction.to.nary(p, q, base, ndigits = 1000)

Arguments

p

the numerator of the rational fraction

q

the denominator of the rational fraction

base

the base for the n-ary representation of the decimal fraction

ndigits

the maximum number of digits to search for the repeating pattern

Details

See

http://cs.furman.edu/digitaldomain/more/ch6/dec_frac_to_bin.htm

for more details.

**NOTE:** p, q, and base should be **integer type**, i.e. suffixed with an 'L'.

If not, they will be coerced to integer type if possible.

Examples

# Binary expansion of 1/10

convert.rational.fraction.to.nary(1, 10, base = 2)

# Base-5 expansion of 1/3

convert.decimal.fraction.to.nary(1, 3, base = 5)

ddarmon/MUsaic documentation built on June 19, 2024, 6:43 p.m.