Next: , Previous: random, Up: Top


54 rational

     %--------------------------------------------------%
     % vim: ft=mercury ts=4 sw=4 et wm=0 tw=0
     %--------------------------------------------------%
     % Copyright (C) 1997-1998, 2003-2006 The University of Melbourne.
     % This file may only be copied under the terms of the GNU Library General
     % Public License - see the file COPYING.LIB in the Mercury distribution.
     %--------------------------------------------------%
     %
     % File: rational.m.
     % Authors: aet Apr 1998. (with plagiarism from rat.m)
     % Stability: high.
     %
     % Implements a rational number type and a set of basic operations on
     % rational numbers.
     %
     %--------------------------------------------------%
     %--------------------------------------------------%
     
     :- module rational.
     :- interface.
     
     :- import_module integer.
     
     %--------------------------------------------------%
     
     :- type rational.
     
     :- pred '<'(rational::in, rational::in) is semidet.
     
     :- pred '>'(rational::in, rational::in) is semidet.
     
     :- pred '=<'(rational::in, rational::in) is semidet.
     
     :- pred '>='(rational::in, rational::in) is semidet.
     
     :- func rational.rational(int) = rational.
     
     :- func rational.rational(int, int) = rational.
     
     :- func rational.from_integer(integer) = rational.
     
     :- func rational.from_integers(integer, integer) = rational.
     
     % :- func float(rational) = float.
     
     :- func '+'(rational) = rational.
     
     :- func '-'(rational) = rational.
     
     :- func rational + rational = rational.
     
     :- func rational - rational = rational.
     
     :- func rational * rational = rational.
     
     :- func rational / rational = rational.
     
     :- func rational.numer(rational) = integer.
     
     :- func rational.denom(rational) = integer.
     
     :- func rational.abs(rational) = rational.
     
     :- func rational.reciprocal(rational) = rational.
     
     :- func rational.one = rational.
     
     :- func rational.zero = rational.
     
     %--------------------------------------------------%
     %--------------------------------------------------%