Box.Fraction (box v0.15.1)
View SourceFraction type to work with irrational numbers. The fractions are not simplified. At the moment, it also doesn't support negative fractions.
Summary
Functions
Compares two fraction. The fractions are compared using their float conversion in order to make sure unsimplified expression gets invalid results.
Creates a fraction from primitive types, for strings, see parse/1
Creates a fraction from numerator and denominator
Parses a string to a fraction type. It supports parsing the following formats:
Converts to float
Converts a fraction to string.
Converts to float
Types
Functions
Compares two fraction. The fractions are compared using their float conversion in order to make sure unsimplified expression gets invalid results.
Creates a fraction from primitive types, for strings, see parse/1
Creates a fraction from numerator and denominator
Parses a string to a fraction type. It supports parsing the following formats:
- Integer (
"43"
): rendered as%Fraction{numerator: 43, denominator: 1}
- Float (
"12.1"
): rendered as%Fraction{numerator: 121, denominator: 10}
- Fraction (
"12/14"
): rendered as%Fraction{numerator: 12, denominator: 14}
@spec to_float(t()) :: Float.t()
Converts to float
Converts a fraction to string.
Converts to float