Module Rat


module Rat: sig .. end
Provides type rat : rational numbers and operations involving them.


type rat =
| Rat of Num.num
Gives every rational number a unique representation.
val cons_rat : string * string -> rat
Constructs the rational a / b from the given pair of strings whose first and second elements denote the integers a and b respectively.
val add_rat : rat * rat -> rat
Adds two rationals.
val sub_rat : rat * rat -> rat
Returns the rational a - b given the pair (a, b) of rationals.
val mult_rat : rat * rat -> rat
Multiply two rationals.
val div_rat : rat * rat -> rat
Returns the rational a / b given the pair (a, b) of rationals.
val opp_rat : rat -> rat
Returns the opposite (or additive inverse) of a rational.
val reciproc_rat : rat -> rat
Returns the reciprocal (or multiplicative inverse) of a rational.
val abs_rat : rat -> rat
Returns the absolute value of a rational.
val eq_rat : rat * rat -> bool
Tests two rationals for equality.
val gt_rat : rat * rat -> bool
Tests whether a > b given the pair (a, b) of rationals.
val ge_rat : rat * rat -> bool
Tests whether a >= b given the pair (a, b) of rationals.
val lt_rat : rat * rat -> bool
Tests whether a < b given the pair (a, b) of rationals.
val le_rat : rat * rat -> bool
Tests whether a <= b given the pair (a, b) of rationals.
val string_of_rat : rat -> string
Returns a string representation of a rational, using fractional notation.
val string_approx_rat : rat * int -> string
Returns a string representation of a decimal approximation of a rational according to a given precision (the number of digits after the decimal point).
val pr_rat : 'a -> rat -> unit
val print_rat : rat -> unit
Prints a string representation of a rational.