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. The evaluable functions msb/1, lsb/1 and popcount/1 are not required by the ISO core standard.

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.
sqrtrem(X, Y, Z):
If X is an integer then the predicate succeeds in Y with the integer square root of X, and in Z with the remainder X-Y*Y.
isqrt(X, Y):
If X is an integer then the predicate succeeds in Y with the integer square root of X.

Use Privacy (c) 2005-2026 XLOG Technologies AG