# 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                   isqrt: integer -> integer
ulp: float -> float                       sqrtrem: integer -> integer^2
ulp: decimal -> decimal                   iroot: integer^2 -> integer
gcd: integer^2 -> integer                 rootrem: integer^2 -> integer^2lcm: integer^2 -> integer                 divmod : number^2-> number^2```

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.

Examples:
```ulp(0)          --> 1                     isqrt(7)        --> 2
ulp(0.0)        --> 4.9E-324              sqrtrem(7)      --> (2,3)
ulp(0d0.00)     --> 0d0.01                iroot(77,5)     --> 2
gcd(36,24)      --> 12                    rootrem(77,5)   --> (2, 45)lcm(36,24)      --> 72                    divmod(12,-7)   --> (-1,5)```

The evaluable functions isqrt/1 and iroot/2 as well as the predicates sqrtrem/3 and rootrem/4 use the fast Hacker method of finding an integer root. The predicate divmod/4 returns both the quotient and remainder of a division. This is faster than invoking the ISO core standard evaluable functions (//)/2 and (rem)/2 separately.

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.
modinv(B, M, R):
The predicate succeeds in R with B^(-1) mod M.
modpow(B, E, M, R):
The predicate succeeds in R with B^E mod M.
isqrt(X, Y):
The predicate succeeds in Y with the integer square root of X.
sqrtrem(X, Y, Z):
The predicate succeeds in Y with integer square root of X and in Z with the corresponding remainder.
iroot(X, Y, Z):
The predicate succeeds in Z with the Y-th root of X.
rootrem(X, Y, Z, T):
The predicate succeeds in Z with the Y-th root of X with and in T with the corresponding remainder.
divmod(X, Y, Z, T):
The predicate succeeds in Z with the division of X by Y, and in T with the modulo of X by Y.