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

## 34 integer

```%--------------------------------------------------%
% vim: ft=mercury ts=4 sw=4 et wm=0 tw=0
%--------------------------------------------------%
% Copyright (C) 1997-2000, 2003-2007, 2011-2012 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: integer.m.
% Main authors: aet, Dan Hazel <odin@svrc.uq.edu.au>.
% Stability: high.
%
% Implements an arbitrary precision integer type and basic
% operations on it. (An arbitrary precision integer may have
% any number of digits, unlike an int, which is limited to the
% precision of the machine's int type, which is typically 32 bits.)
%
% NOTE: All operators behave as the equivalent operators on ints do.
% This includes the division operators: / // rem div mod.
%
%--------------------------------------------------%
%--------------------------------------------------%

:- module integer.
:- interface.

:- type integer.

:- pred '<'(integer::in, integer::in) is semidet.

:- pred '>'(integer::in, integer::in) is semidet.

:- pred '=<'(integer::in, integer::in) is semidet.

:- pred '>='(integer::in, integer::in) is semidet.

:- func integer.integer(int) = integer.

:- func integer.to_string(integer) = string.

:- func integer.from_string(string::in) = (integer::out) is semidet.

:- func integer.det_from_string(string) = integer.

% Convert a string in the specified base (2-36) to an integer.
% The string must contain one or more digits in the specified base,
% optionally preceded by a plus or minus sign.  For bases > 10, digits
% 10 to 35 are represented by the letters A-Z or a-z.  If the string
% does not match this syntax then the function fails.
%
:- func integer.from_base_string(int, string) = integer is semidet.

% As above but throws an exception rather than failing.
%
:- func integer.det_from_base_string(int, string) = integer.

:- func '+'(integer) = integer.

:- func '-'(integer) = integer.

:- func integer + integer = integer.

:- func integer - integer = integer.

:- func integer * integer = integer.

:- func integer // integer = integer.

:- func integer div integer = integer.

:- func integer rem integer = integer.

:- func integer mod integer = integer.

% divide_with_rem(X, Y, Q, R) where Q = X // Y and R = X rem Y
% where both answers are calculated at the same time.
%
:- pred divide_with_rem(integer::in, integer::in,
integer::out, integer::out) is det.

:- func integer << int = integer.

:- func integer >> int = integer.

:- func integer /\ integer = integer.

:- func integer \/ integer = integer.

:- func integer `xor` integer = integer.

:- func \ integer = integer.

:- func integer.abs(integer) = integer.

:- func integer.pow(integer, integer) = integer.

:- func integer.float(integer) = float.
:- func integer.int(integer) = int.

:- func integer.zero = integer.

:- func integer.one = integer.

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

```

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