YAP 7.1.0
Arithmetic Functions

YAP implements several arithmetic functions, they are defined as fields in three enumerations, such that there is one enumeration per each different arity:
More...

Detailed Description

YAP implements several arithmetic functions, they are defined as fields in three enumerations, such that there is one enumeration per each different arity:

These are the binary numeric operators currently supported by YAP.

Arithmetic expressions in YAP may use the following operators:

An approximation to the value of pi, that is, the ratio of a circle's circumference to its diameter

Euler's number, the base of the natural logarithms

The difference between the float 1.0 and the next largest floating point number

Note also that YAP supports +inf and -inf

Not-a-number according to the IEEE Floating-Point standard Note that evaluating this term will generate a domain error in the iso language mode

A "random" floating point number between 0 and 1

CPU time since YAP was invoked, in seconds

Heap (data-base) space used, in bytes

Local stack in use, in bytes

current choicepoint

Environment

Trail in use

Amount of free stack space, that is, free space between global and local stacks

Global stack in use, in bytes

Natural exponential

Natural logarithm

Decimal logarithm

Square root

Sine

Cosine

Tangent

Arc sine

Arc cosine

Arc tangent

Hyperbolic sine

Hyperbolic cosine

Hyperbolic tangent

Hyperbolic arc sine

Hyperbolic arc cosine

Hyperbolic arc tangent

Logarithm of gamma function

Gaussian error function

Complementary gaussian error function

An integer random number between 0 and X

In iso language mode the argument must be a floating point-number, the result is an integer and it the float is equidistant it is rounded up, that is, to the least integer greater than X

If X evaluates to a float, the integer between the value of X and 0 closest to the value of X, else if X evaluates to an integer, the value of X

If X evaluates to an integer, the corresponding float, else the float itself

The fractional part of the floating point number X, or 0.0 if X is an integer In the iso language mode, X must be an integer

The float giving the integer part of the floating point number X, or X if X is an integer In the iso language mode, X must be an integer

The absolute value of X

The integer that is the smallest integral value not smaller than X

In iso language mode the argument must be a floating point-number and the result is an integer

The integer that is the greatest integral value not greater than X

In iso language mode the argument must be a floating point-number and the result is an integer

The nearest integral value to X If X is equidistant to two integers, it will be rounded to the closest even integral value

In iso language mode the argument must be a floating point-number, the result is an integer and it the float is equidistant it is rounded up, that is, to the least integer greater than X

Return 1 if the X evaluates to a positive integer, 0 it if evaluates to 0, and -1 if it evaluates to a negative integer If X evaluates to a floating-point number return 1.0 for a positive X, 0.0 for 0.0, and -1.0 otherwise

The integral value between X and 0 closest to X

Convert the expression X to a rational number or integer The function returns the input on integers and rational numbers For floating point numbers, the returned rational number exactly represents the float As floats cannot exactly represent all decimal numbers the results may be surprising In the examples below, doubles can represent 0.25 and the result is as expected, in contrast to the result of rational(0.1) The function rationalize/1 gives a more intuitive result

?- A is rational(0.25).
A is 1 rdiv 4
?- A is rational(0.1).
A = 3602879701896397 rdiv 36028797018963968

Convert the expression X to a rational number or integer The function is vvxu similar to rational/1, but the result is only accurate within the rounding error of floating point numbers, generally producing a much smaller denominator

?- A is rationalize(0.25).
A = 1 rdiv 4
?- A is rationalize(0.1).
A = 1 rdiv 10

Integer bitwise negation

The most significant bit of the non-negative integer X

The least significant bit of the non-negative integer X

The number of bits set to 1 in the binary representation of the non-negative integer X

Evaluates to X for expression X Useful because character strings in Prolog are lists of character codes

X is Y*10+C-"0"

is the same as

X is Y*10+C-[48].

which would be evaluated as:

X is Y*10+C-48.

Addition, implemented between any two types of numbers

Quotient.

Enumeration Type Documentation

◆ arith2_op

enum arith2_op

binary operators

specifies the available binary arithmetic operators

Definition at line 319 of file YapEval.h.

Enumerations

enum  arith2_op {
  op_plus , op_minus , op_times , op_fdiv ,
  op_mod , op_rem , op_div , op_idiv ,
  op_sll , op_slr , op_and , op_or ,
  op_xor , op_atan2 , op_power , op_power2 ,
  op_gcd , op_min , op_max , op_rdiv
}
 binary operators More...