Fractional
Fractional is a library that implements fractions and fractional arithmetic in Crystal
beyond purely rational numbers (as is possible in the standard library with BigRational).
Currently, Fractional has implemented basic arithmetic with all base number types (i.e.,
those that inherit from Number (see /src/number/number.cr)).
two_over_three = frac(2, 3)
3 + two_over_three # => 11/3
two_over_three / 2 # => 2/6
Fractions are not automatically reduced to simplest terms, unlike BigRationals, so if
your use case depends on keeping your values in simplest terms, account for this.
Constants
Constructors
Returns a new Fraction(T, U) with the given numerator and denominator.
NOTE: While it is a potential idea at the moment to potentially support non-Number
and non-Fraction numerators and denominators (for example, for support of an
algebraic mathematics library), that is currently not the main idea, and so the primary
constructors (these and the frac macro) are intended to abstract the types away,
and raise an exception when a bad type is supplied.
Returns a new Fraction(T, U) with a numerator and denominator derived from the given
big_rational.
Returns a new Fraction(T, U) with a numerator and denominator derived from a BigRational
created by calling BigRational#new(float).
Class methods
Returns the additive identity of the type.