Next: , Previous: ranges, Up: Top   [Contents]


74 rational

%--------------------------------------------------%
% vim: ft=mercury ts=4 sw=4 et
%--------------------------------------------------%
% Copyright (C) 1997-1998, 2003-2006 The University of Melbourne.
% Copyright (C) 2014-2016, 2018-2019 The Mercury team.
% This file is distributed under the terms specified in COPYING.LIB.
%--------------------------------------------------%
%
% 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.

:- func numer(rational) = integer.

:- func denom(rational) = integer.

:- func zero = rational.

:- func one = 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(int) = rational.

:- func rational(int, int) = rational.

:- func from_integer(integer) = rational.

:- func 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 reciprocal(rational) = rational.

:- func abs(rational) = rational.

%--------------------------------------------------%
%--------------------------------------------------%