math.fractions #

fn approximate #

fn approximate(val f64) Fraction

approximate returns a Fraction that approcimates the given value to within the default epsilon value (1.0e-4). This means the result will be accurate to 3 places after the decimal.

fn approximate_with_eps #

fn approximate_with_eps(val f64, eps f64) Fraction

approximate_with_eps returns a Fraction

fn fraction #

fn fraction(n i64, d i64) Fraction

A factory function for creating a Fraction, adds a boundary condition to ensure that the denominator is non-zero. It automatically converts the negative denominator to positive and adjusts the numerator. NOTE: Fractions created are not reduced by default.

fn (Fraction) str #

fn (f Fraction) str() string

To String method

fn (Fraction) + #

fn (f1 Fraction) + (f2 Fraction) Fraction

Fraction add using operator overloading

fn (Fraction) - #

fn (f1 Fraction) - (f2 Fraction) Fraction

Fraction subtract using operator overloading

fn (Fraction) * #

fn (f1 Fraction) * (f2 Fraction) Fraction

Fraction multiply using operator overloading

fn (Fraction) / #

fn (f1 Fraction) / (f2 Fraction) Fraction

Fraction divide using operator overloading

fn (Fraction) negate #

fn (f Fraction) negate() Fraction

Fraction negate method

fn (Fraction) reciprocal #

fn (f Fraction) reciprocal() Fraction

Fraction reciprocal method

fn (Fraction) reduce #

fn (f Fraction) reduce() Fraction

Fraction method which reduces the fraction

fn (Fraction) f64 #

fn (f Fraction) f64() f64

f64 converts the Fraction to 64-bit floating point

fn (Fraction) equals #

fn (f1 Fraction) equals(f2 Fraction) bool

+-----------------------------+ | Public comparison functions | +-----------------------------+ equals returns true if both the Fractions are equal

fn (Fraction) ge #

fn (f1 Fraction) ge(f2 Fraction) bool

ge returns true if f1 >= f2

fn (Fraction) gt #

fn (f1 Fraction) gt(f2 Fraction) bool

gt returns true if f1 > f2

fn (Fraction) le #

fn (f1 Fraction) le(f2 Fraction) bool

le returns true if f1 <= f2

fn (Fraction) lt #

fn (f1 Fraction) lt(f2 Fraction) bool

lt returns true if f1 < f2