Introduction -- library(math)

library(math) is an interface to the math(3m) library.

All of the predicates in this module take some number of numeric arguments and yield a numeric result as their last argument. For example, the predicate call sin(X, Result) unifies Result with sin(X). The predicates provided are

sign(X, Result)
Result is +/-1, agreeing with sign of X.
sign(X, Y, AbsX_SignY)

abs(X, Result)
Result has same type as X
fabs(X, Result)
Result is a float
hypot(X, Y, Result)
Result is sqrt(X*X+Y*Y)
max(X, Y, Result)
If X and Y are different types,
min(X, Y, Result)
Result may be of either type; see NOTE #1, below.
log(X, Result)
natural logarithm
log10(X, Result)
common logarithm; see NOTE #2, below.
pow(X, Y, Result)
Result is X**Y; see NOTE #2, below.
exp(Y, Result)
Result is e**Y
sqrt(X, Result)
Result is X**0.5
scale(X, Integer, Result)
X and Result) are floats, Result = X*2^N.
floor(+X, ?Result)

floor(+X, Result, Fraction)

ffloor(X, Result)
Result is float(floor(X))
ffloor(X, Result, Fraction)

truncate(X, I)

truncate(X, I, F)

ftruncate(X, I)

ftruncate(X, I, F)

ceiling(+X, ?Result)

ceiling(+X, ?Result, Fraction)
like ceiling/2, with a fraction present.
fceiling(X, Result)
Result is float(ceiling(X))
fceiling(X, Result, Fraction)
like fceiling/2, with a fraction present.
round(X, Result)

round(X, Result, Fraction)

fround(X, Result)

fround(X, Result, Fraction)

fremainder(X, Y, Remainder)

decode_float(?Number, ?Sign, ?Significand, ?Exponent)

j0(X, Result)
These are Bessel functions,
y0(X, Result)
see j0(3m)
j1(X, Result)

y1(X, Result)

jn(N, X, Result)
N is an integer.
yn(N, X, Result)
See NOTE #3, below.
sin(X, Result)

asin(X, Result)

sinh(X, Result)

asinh(X, Result)
See NOTE #4, below.
cos(X, Result)

acos(X, Result)

cosh(X, Result)

acosh(X, Result)
See NOTE #4, below.
tan(X, Result)

atan(X, Result)

atan2(X, Y, Result)

tanh(X, Result)

atanh(X, Result)
See NOTE #4, below.
gamma(X, Result)
This is really ln(gamma(X)); see NOTE #5, below.


  1. If an arithmetic operation like X+Y is given mixed arguments, it will convert the integer argument to a floating-point number. In this release, max(X, Y, Max) and min(X, Y, Min) do not do this. For example,
              | ?- min(1, 2.3, X).
              X = 1

    This is likely to change.

  2. The names of these functions are copied from C. In a later release, the functions will be

    ^(X, N, Result)
    Result is X^N (N integer)
    exp(Y, Result)
    Result is e**Y
    exp(X, Y, Result)
    Result is X**Y, as exp(Y*log(X))
    log(X, Y, Result)
    Result is the base X logarithm of Y
    log(Y, Result)
    Result is the base e logarithm of Y
  3. The Bessel functions will be moved into another file. They are not generally available on non-UNIX versions of Quintus Prolog. They are retained as is in this release for compatibility with previous releases.
  4. The inverse hyperbolic trigonometric functions are not provided in most systems. We have provided C code to compute them. It is suggested that you satisfy yourself as to their accuracy before relying on them.
  5. The function that UNIX calls gamma() is in fact the natural logarithm of the gamma function. It is not generally available on non-UNIX versions of Quintus Prolog. It is retained in this release for compatibility with previous releases.