File "math"

This Prolog text provides further built-ins for numbers, as seen in many other Prolog  systems. The module originally started with the predicate random/1 which gives a uniform random 64-bit floating point value. Native implementations of divmod/4 can use an algorithm that yields div/2 and mod/2 at the same time. Not available for all targets.

The evaluable functions msb/1, lsb/1 and popcount/1 are not required by the ISO core standard. Implementing these functions by means of the bitwise and number theoretic functions is not feasible. Native implementations, with access to the integer representation, perform better by an order of magnitude. Not available for all targets.

The following math evaluable functions are provided:

msb(X):
If X is an integer, then the function returns the most significant bit.
lsb(X):
If X is an integer, then the function returns the least significant bit.
popcount(X):
If X is an integer, then the function returns the number of ones.

The following math predicates are provided:

random(F):
The predicate succeeds in F with a uniform random 64-bit floating point value in the interval [0..1).
random(M, N):
The predicate succeeds in N with a uniform random arbitrary large integer value in the interval [0..M).
testbit(X, Y):
The predicate succeeds when X /\ (1 << Y) =\= 0.
divmod(X, Y, Z, T):
If X and Y are both integers then the predicate succeeds in Z with the division of X by Y, and in T with the modulo of X by Y.

Kommentare