The predicates in this section provide more logical operations between integers. They are not covered by the ISO standard, although they are‘part of the community’and found as either library or built-in in many other Prolog systems.
inf
or
infinite
123We prefer infinite
,
but some other Prolog systems already use inf
for infinity;
we accept both for the time being.
between/3
is true iff Value ≥Low, a feature
that is particularly interesting for generating integers from a certain
value.not_less_than_zero
if called with a negative integer. E.g. succ(X, 0)
fails
silently and succ(X, -1)
raises a domain error.124The
behaviour to deal with natural numbers only was defined by Richard
O'Keefe to support the common count-down-to-zero in a natural way. Up to
5.1.8, succ/2
also accepted negative integers.divmod(Dividend, Divisor, Quotient, Remainder) :- Quotient is Dividend div Divisor, Remainder is Dividend mod Divisor.
Note that this predicate is only available if SWI-Prolog is compiled with unbounded integer support. This is the case for all packaged versions.
% I < 0, % N mod 2 =\= 0, nth_integer_root_and_remainder( N, I, Root, Remainder), IPos is -I, nth_integer_root_and_remainder( N, IPos, RootPos, RemainderPos), Root =:= -RootPos, Remainder =:= -RemainderPos.