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

View source: R/carithmetic.R

convert.decimal.fraction.to.naryR Documentation

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

Description

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

Usage

convert.decimal.fraction.to.nary(d, e, base, ndigits = 54)

Arguments

d

the integer part of the decimal fraction.

e

the exponent for 10^(-e)

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:** d, e, 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 = 1/10^1

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

# Trinary expansion of 1/10 = 1/10^1

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

# Base-5 expansion of 1/5 = 2/10^1

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

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