Functions for doing basic arithmetic with fractions.

add_fractions(x1, x2)

subtract_fractions(x1, x2)

multiply_fractions(x1, x2)

divide_fractions(x1, x2)

x1 %f+% x2

x1 %f-% x2

x1 %f*% x2

x1 %f/% x2

Arguments

x1

The first fraction to be used.

x2

The second fraction to be used.

Examples

# Use as a function add_fractions("1/2", "1/4")
#> [1] "3/4"
# Use with the defined infix operator "1/8" %f+% "2/3"
#> [1] "19/24"
"1/2" %f/% "1/2"
#> [1] "1"
# Infix operators can be chained # Operations go from left to right "-2" %f-% "1/2" %f+% "2 1/3"
#> [1] "-1/6"
# Use parentheses to control order of operations "-2" %f-% "1/2" %f+% "2 1/3" %f*% "2"
#> [1] "-1/3"
"-2" %f-% "1/2" %f+% ("2 1/3" %f*% "2")
#> [1] "2 1/6"