 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.

• arith0_op defines constants and arity 0 arithmetic functions

constant operators specifies the available arithmetic "constants"

• arith1_op defines single argument arithmetic functions

unary operators specifies the available unary arithmetic operators

• arith2_op defines binary arithmetic functions

binary operators specifies the available binary arithmetic operators

Arithmetic expressions in YAP may use the following operators:

• pi [ISO]

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

• e

Euler's number, the base of the natural logarithms

• epsilon

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

• `inf` Infinity according to the IEEE Floating-Point standard Note that evaluating this term will generate a domain error in the `iso` language mode

Note also that YAP supports `+inf` and `-inf`

• nan (not a number)

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

• random

A "random" floating point number between 0 and 1

• cputime

CPU time since YAP was invoked, in seconds

• heapused

Heap (data-base) space used, in bytes

• local

Local stack in use, in bytes

• \$b

current choicepoint

• \$env

Environment

• \$tr

Trail in use

• \$free_stack

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

• global

Global stack in use, in bytes

• exp( X) [ISO]

Natural exponential

• log( X) [ISO]

Natural logarithm

• log10( X)

Decimal logarithm

• sqrt( X) [ISO]

Square root

• sin( X) [ISO]

Sine

• cos( X) [ISO]

Cosine

• tan( X) [ISO]

Tangent

• asin( X) [ISO]

Arc sine

• acos( X) [ISO]

Arc cosine

• atan( X) [ISO]

Arc tangent

• sinh( X)

Hyperbolic sine

• cosh( X)

Hyperbolic cosine

• tanh( X)

Hyperbolic tangent

• asinh( X)

Hyperbolic arc sine

• acosh( X)

Hyperbolic arc cosine

• atanh( X)

Hyperbolic arc tangent

• lgamma( X)

Logarithm of gamma function

• erf( X)

Gaussian error function

• erfc( X)

Complementary gaussian error function

• random( X) [ISO]

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

• integer( 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

• float( X) [ISO]

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

• float_fractional_part( X) [ISO]

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

• float_integer_part( X) [ISO]

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

• abs( X) [ISO]

The absolute value of X

• ceiling( X) [ISO]

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

• floor( X) [ISO]

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

• round( X) [ISO]

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

• sign( X) [ISO]

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

• truncate( X) [ISO]

The integral value between X and 0 closest to X

• rational( 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
• rationalize( X)

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
• \ X [ISO]

Integer bitwise negation

• msb( X)

The most significant bit of the non-negative integer X

• lsb( X)

The least significant bit of the non-negative integer X

• popcount( X)

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

• [ 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-.

which would be evaluated as:

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

Addition, implemented between any two types of numbers

• *_X_- Y [ISO]*

Addition, implemented between any two types of numbers

• *_X_* Y [ISO]*

Product

• *_X_/ Y [ISO]*
```Quotient.
```
• *_X_// Y [ISO]*

Integer quotient

• *_X_ mod Y [ISO]* Integer module operator, always positive
• *_X_ rem Y [ISO]* Integer remainder, similar to `mod` but always has the same sign as `X`
• * X div Y [ISO]* Integer division, as if defined by `( _X_ - _X_ mod _Y_)// _Y_`
• max( X, Y) [ISO] The greater value of X and Y
• min( X, Y) [ISO] The lesser value of X and Y
• *_X_ ^ Y [ISO]*

X raised to the power of Y, (from the C-Prolog syntax)

• exp( X, Y) X raised to the power of Y, (from the Quintus Prolog syntax)
• *_X_ ** Y [ISO]*

X raised to the power of Y (from ISO)

• *_X_ /\ Y [ISO]*

Integer bitwise conjunction

• *_X_ \/ Y [ISO]*

Integer bitwise disjunction

• *_X_ # Y*

Integer bitwise exclusive disjunction

• *_X_ >< Y*

Integer bitwise exclusive disjunction

• xor( X , Y) [ISO] Integer bitwise exclusive disjunction
• *_X_ << Y*

Integer bitwise left logical shift of X by Y places

• *_X_ > Y [ISO]*

Integer bitwise right logical shift of X by Y places

• gcd( X, Y) The greatest common divisor of the two integers X and Y
• atan( X, Y) Four-quadrant arc tangent Also available as `atan2/2 `
• atan2( X, Y) [ISO] Four-quadrant arc tangent
• * X rdiv Y [ISO]* Rational division

## ◆ 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...