convert_rational_fraction_to_nary | R Documentation |
This function computes the representation of a rational fraction in a specified base (n-ary form), using the GNU Multiple Precision (GMP) library for arbitrary precision arithmetic. The process involves repeated division by the base, using Horner's method for efficient computation. The function detects and marks repeating sequences in the n-ary expansion.
convert_rational_fraction_to_nary(p, q, base, ndigits = 1000)
p |
A 'bigz' object representing the numerator of the fraction. |
q |
A 'bigz' object representing the denominator of the fraction. |
base |
The base in which to express the fraction. |
ndigits |
The maximum number of digits to compute before stopping or detecting a repeat. |
'gmp::as.bigz()' is used to allow for arbitrarily large integers for the numerator and denominator of the rational fraction.
For more theoretical background, see: http://cs.furman.edu/digitaldomain/more/ch6/dec_frac_to_bin.htm
A list containing: - 'p': The numerator. - 'q': The denominator. - 'nary_representation': The n-ary number as a string. - 'expansion': Numeric vector of computed digits. - 'initial_part': Non-repeating part of the expansion. - 'repeating_part': Repeating sequence of digits in the expansion. - 'terms': List of intermediary terms used in computation.
library(gmp)
# Convert the fraction 1/9007199254740992 to binary
convert_rational_fraction_to_nary_gmp(as.bigz("1"), as.bigz("9007199254740992"), base = 2)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.