convert.decimal.fraction.to.binary: Convert a decimal fraction into a binary fraction using...

View source: R/carithmetic.R

convert.decimal.fraction.to.binaryR Documentation

Convert a decimal fraction into a binary fraction using integer arithmetic with Horner's method.

Description

A function to convert a decimal fraction into a binary fraction, for demonstration of rounding necessary to represent most fractional numbers on a computer.

Usage

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

Arguments

d

the integer part of the decimal fraction.

e

the exponent for 10^(-e)

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.

This function returns the

**NOTE:** Both d and e 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.binary(1, 1)

# Binary expansion of 1/2 = 5/10^1

convert.decimal.fraction.to.binary(5, 1)

# Binary expansion of 1/100 = 1/10^2

convert.decimal.fraction.to.binary(1, 2)

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