View Source Toothmath.Fraction (Toothmath v0.1.0)
This is a hand spun math module to handle Fractions
Summary
Functions
A fraction
Add 2 fractions together in simplified form
Approximates the given x
float value into a fraction
Create a new fraction with numerator and denominator such as 1 / 2
Simply a fraction using the greatest common divisor using the Euclidean algorithm
Get the rational number
Functions
A fraction
:a
: the top (numerator) value:b
the bottom (denominator) value
Add 2 fractions together in simplified form
Examples
iex> alias Toothmath.Fraction
iex> Fraction.add(%Fraction{a: 1, b: 2}, %Fraction{a: 1, b: 4})
%Fraction{a: 3, b: 4}
Approximates the given x
float value into a fraction
Examples
iex> alias Toothmath.Fraction iex> Fraction.from_value(0.6875) %Fraction{a: 11, b: 16}
Create a new fraction with numerator and denominator such as 1 / 2
a
- the numeratorb
- the denominator
Simply a fraction using the greatest common divisor using the Euclidean algorithm
iex> alias Toothmath.Fraction
iex> Fraction.simplify(%Fraction{a: 2, b: 4})
%Fraction{a: 1, b: 2}
Get the rational number
a fractional number is always a rational number, but a rational number may or may not be a fractional number
Examples
iex> alias Toothmath.Fraction
iex> Fraction.value(%Fraction{a: 1, b: 2})
0.50