Mu.QRational numbers (ℚ).
The type for rational numbers.
Values of this type are normalized. The numerator and denominator have no common factor and the denominator is non-negative.
The special rationals 1/0, -1/0 and 0/0 repectively denote infinity, neg_infinity and nan.
val v : int -> int -> tv num den is the normalized rational num / den.
val int : int -> tint n is v n 1.
val (#/) : int -> int -> tn #/ d is v num den.
val num : t -> intnum r is the numerator of r.
val den : t -> intden r is the denominator of r.
val zero : tzero is 0/1.
val one : tone is 1/1.
val minus_one : tminus_one is -1/1.
val infinity : tinfinity is 1/0.
val neg_infinity : tneg_infinity is -1/0.
val nan : tnan is 0/0.
val is_finite : t -> boolis_finite r is true iff r's kind is either Zero or Non_zero.
val is_infinite : t -> boolis_infinite r is true iff r is either infinity or neg_infinity.
val sign : t -> intsign r is the sign of r. This is either -1, 0 or 1. The sign of Nan is 0.
compare r0 r1 is a total order on r0 and r1. nan is the smallest value and equal to itself, the rest is ordered as expected.
Note. All these operations return nan if they get a nan argument.
val of_int : int -> tof_int n is n // 1.
val to_int_towards_zero : t -> intto_int_towards_zero r is num r / den r. Divides r and moves towards zero to the nearest int. Raises Division_by_zero if den r is 0; that is on nan, neg_infinity, infinity.
val to_int_away_from_zero : t -> intto_int_away_from_zero r divides r moves away from zero to the nearest int. Raises Division_by_zero if den r is 0; that is on nan, neg_infinity, infinity.
val checked_to_int_towards_zero : t -> int optionchecked_to_int_towards_zero is like to_int_towards_zero but is None if den r is 0.
val checked_to_int_away_from_zero : t -> int optionchecked_to_int_towards_zero is like to_int_away_from_zero but is None if den r is 0.
val to_float : t -> floatto_float r is (float (num r) /. (float (den r)). Special values are mapped to corresponding floating point special values.
val pp : Stdlib.Format.formatter -> t -> unitpp is a formatter for rationals.
val pp_kind : Stdlib.Format.formatter -> kind -> unitpp_kind is a formatter for rational kinds.