Title: | Convert Decimals to Fractions |
---|---|
Description: | Provides functions for converting decimals to a matrix of numerators and denominators or a character vector of fractions. Supports mixed or improper fractions, finding common denominators for vectors of fractions, limiting denominators to powers of ten, and limiting denominators to a maximum value. Also includes helper functions for finding the least common multiple and greatest common divisor for a vector of integers. Implemented using C++ for maximum speed. |
Authors: | Alexander Rossell Hayes [aut, cre, cph] |
Maintainer: | Alexander Rossell Hayes <[email protected]> |
License: | MIT + file LICENSE |
Version: | 0.2.1 |
Built: | 2024-12-06 04:40:49 UTC |
Source: | https://github.com/rossellhayes/fracture |
Least common multiple and greatest common divisor
frac_lcm(..., max = 1e+07) frac_gcd(...)
frac_lcm(..., max = 1e+07) frac_gcd(...)
... |
Integer vectors or vectors that can be coerced to integer. |
max |
If the least common multiple is greater than |
An integer.
frac_lcm(1, 2, 3, 4, 5, 6) x <- 1:6 frac_lcm(x) frac_lcm(x, 7) frac_gcd(12, 42, 60) y <- c(12, 42, 60) frac_gcd(y) frac_gcd(y, 39)
frac_lcm(1, 2, 3, 4, 5, 6) x <- 1:6 frac_lcm(x) frac_lcm(x, 7) frac_gcd(12, 42, 60) y <- c(12, 42, 60) frac_gcd(y) frac_gcd(y, 39)
Convert decimals to a matrix of numerators and denominators
frac_mat( x, ..., denom = NULL, base_10 = FALSE, common_denom = FALSE, mixed = FALSE, max_denom = 1e+07 ) as.frac_mat(x) is.frac_mat(x)
frac_mat( x, ..., denom = NULL, base_10 = FALSE, common_denom = FALSE, mixed = FALSE, max_denom = 1e+07 ) as.frac_mat(x) is.frac_mat(x)
x |
A vector of decimals or, for |
... |
These dots are for future extensions and must be empty. |
denom |
If |
base_10 |
If |
common_denom |
If If the least common denominator is greater than |
mixed |
If If |
max_denom |
All denominators will be less than or equal to
If A |
A matrix with the same number of columns as the length of x
and
rows for integer
s (if mixed
is TRUE
), numerator
s,
and denominator
s.
fracture()
to return a character vector of fractions.
x <- (6:1) / (1:6) frac_mat(x) frac_mat(x, common_denom = TRUE) frac_mat(x, base_10 = TRUE) frac_mat(x, base_10 = TRUE, max_denom = 100) frac_mat(x, base_10 = TRUE, common_denom = TRUE) frac_mat(x, base_10 = TRUE, common_denom = TRUE, max_denom = 100) frac_mat(x, mixed = TRUE) frac_mat(x, mixed = TRUE, common_denom = TRUE) frac_mat(x, mixed = TRUE, base_10 = TRUE) frac_mat(x, mixed = TRUE, base_10 = TRUE, max_denom = 100) frac_mat(x, mixed = TRUE, base_10 = TRUE, common_denom = TRUE) frac_mat(x, mixed = TRUE, base_10 = TRUE, common_denom = TRUE, max_denom = 100)
x <- (6:1) / (1:6) frac_mat(x) frac_mat(x, common_denom = TRUE) frac_mat(x, base_10 = TRUE) frac_mat(x, base_10 = TRUE, max_denom = 100) frac_mat(x, base_10 = TRUE, common_denom = TRUE) frac_mat(x, base_10 = TRUE, common_denom = TRUE, max_denom = 100) frac_mat(x, mixed = TRUE) frac_mat(x, mixed = TRUE, common_denom = TRUE) frac_mat(x, mixed = TRUE, base_10 = TRUE) frac_mat(x, mixed = TRUE, base_10 = TRUE, max_denom = 100) frac_mat(x, mixed = TRUE, base_10 = TRUE, common_denom = TRUE) frac_mat(x, mixed = TRUE, base_10 = TRUE, common_denom = TRUE, max_denom = 100)
Uses Unicode superscripts and subscripts to format a fracture.
frac_style(fracture, ...)
frac_style(fracture, ...)
fracture |
A fracture or a vector to be passed to |
... |
Additional arguments passed to |
fracture
with numerators formatted with Unicode superscripts and
denominators formatted with Unicode subscripts.
frac_style(fracture(0.5)) frac_style(fracture(c(0.5, 1.5), mixed = TRUE))
frac_style(fracture(0.5)) frac_style(fracture(c(0.5, 1.5), mixed = TRUE))
Convert decimals to a character vector of fractions
fracture( x, ..., denom = NULL, base_10 = FALSE, common_denom = FALSE, mixed = FALSE, max_denom = 1e+07 ) as.fracture(x) is.fracture(x)
fracture( x, ..., denom = NULL, base_10 = FALSE, common_denom = FALSE, mixed = FALSE, max_denom = 1e+07 ) as.fracture(x) is.fracture(x)
x |
A vector of decimals or, for |
... |
These dots are for future extensions and must be empty. |
denom |
If |
base_10 |
If |
common_denom |
If If the least common denominator is greater than |
mixed |
If If |
max_denom |
All denominators will be less than or equal to
If A |
A character vector.
frac_mat()
to return a matrix of numerators and denominators.
x <- (6:1) / (1:6) fracture(x) fracture(x, common_denom = TRUE) fracture(x, base_10 = TRUE) fracture(x, base_10 = TRUE, max_denom = 100) fracture(x, base_10 = TRUE, common_denom = TRUE) fracture(x, base_10 = TRUE, common_denom = TRUE, max_denom = 100) fracture(x, mixed = TRUE) fracture(x, mixed = TRUE, common_denom = TRUE) fracture(x, mixed = TRUE, base_10 = TRUE) fracture(x, mixed = TRUE, base_10 = TRUE, max_denom = 100) fracture(x, mixed = TRUE, base_10 = TRUE, common_denom = TRUE) fracture(x, mixed = TRUE, base_10 = TRUE, common_denom = TRUE, max_denom = 100)
x <- (6:1) / (1:6) fracture(x) fracture(x, common_denom = TRUE) fracture(x, base_10 = TRUE) fracture(x, base_10 = TRUE, max_denom = 100) fracture(x, base_10 = TRUE, common_denom = TRUE) fracture(x, base_10 = TRUE, common_denom = TRUE, max_denom = 100) fracture(x, mixed = TRUE) fracture(x, mixed = TRUE, common_denom = TRUE) fracture(x, mixed = TRUE, base_10 = TRUE) fracture(x, mixed = TRUE, base_10 = TRUE, max_denom = 100) fracture(x, mixed = TRUE, base_10 = TRUE, common_denom = TRUE) fracture(x, mixed = TRUE, base_10 = TRUE, common_denom = TRUE, max_denom = 100)