Module elem

We provide a couple of additional elementary operations. The ulp evaluable function is defined for integer, float and decimal. The function returns a result of the same type as its argument. The gcd and the evaluable function operation are currently only defined for integers. The functions return a result of type integer:

ulp: integer -> integer
ulp: float -> float
ulp: decimal -> decimal
gcd: integer x integer -> integer
lcm: integer x integer -> integer
isqrt: integer -> integer

The ulp evaluable function makes use of the ulp() function of the Java Math library. The gcd evaluable function implements a binary gcd algorithm for 32-bit integers and otherwise delegates to the Java BigInteger gcd function implementation. The lcm evaluable function is bootstrapped from the gcd evaluable function. The isqrt evaluable function uses a logarithmic bisection method.

ulp(0)          --> 1
ulp(0.0)        --> 4.9E-324
ulp(0d0.00)     --> 0d0.01
gcd(36,24)      --> 12
lcm(36,24) --> 72
isqrt(7) --> 8

The following elementary evaluable functions are provided:

ulp(X, Y):
Predicate succeeds in Y with the unit of least precision of the number X.
gcd(X, Y, Z):
Predicate succeeds in Z with the greatest common divisor of the integer X and the integer Y.
lcm(X, Y, Z):
Predicate succeeds in Z with the least common multiple of the integer X and the integer Y.
isqrt(X, Y):
The predicate succeeds in Y with the integer square root of X.