![]() |
YAP 7.1.0
|
YAP supports several numeric types:
Tagged integers
YAP supports integers of up to almost the CPU word size: 28 bits on 32-bit machines, and 60-bits on 64-bit machines.The engine tags smaller integers are tagged so that they fit in a single word These are the so called tagged integers
Large integers
Integers that cannot fit a tag, but who can fit a word are represented by adding a special functor, and a special end cell The difference between these integers and tagged integers should be transparent to the programmer
When YAP is built using the GNU multiple precision arithmetic library (GMP), integer arithmetic is unbounded, which means that the size of integers is only limited by available memory The type of integer support can be detected using the Prolog flags bounded, min_integer and max_integer As the use of GMP is default, most of the following descriptions assume unbounded integer arithmetic
Rational numbers are quotients of two integers Rational arithmetic is provided if GMP is used Rational numbers that are returned from is/2 are canonical, which means the denominator M is positive and that the numerator N and M have no common divisors Rational numbers are introduced in the computation using the rational/1 , rationalize/1 or the rdiv/2 (rational division) function
Floating point numbers
Floating point numbers are represented using the C-type double On most today platforms these are 64-bit IEEE-754 floating point numbers YAP now includes the built-in predicates isinf/1 and to isnan/1 tests
Arithmetic functions that require integer arguments accept, in addition to integers, rational numbers with denominator ‘1’ and floating point numbers that can be accurately converted to integers If the required argument is a float the argument is converted to float Note that conversion of integers to floating point numbers may raise an overflow exception In all other cases, arguments are converted to the same type using the order integer to rational number to floating point number
Evaluation generates the following Call exceptions:
error(instantiation_error, Call ) | if not ground |
type_error(evaluable( V ), Call) | if not evaluable term |
type_error(integer( V ), Call) | if must be integer |
type_error(float( V ), Call) | if must be float |
domain_error(out_of_range( V ), Call) | if argument invalid |
domain_error(not_less_than_zero( V ), Call) | if argument must be positive or zero |
evaluation_error(undefined( V ), Call) | result is not defined (nan) |
evaluation_error(overflow( V ), Call) | result is arithmetic overflow |
Modules | |
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: | |
Arithmetic Comparison Predicates | |
Predicates that perform arithmetic | |
class succ/2 |
succ(? Int1:int, ? Int2:int)
properties: deterministic
succ(X, 0)
fails silently and succ(X, -1)
raises a domain-error The behaviour to deal with natural numbers only was defined by Richard O'Keefe to support the common count-down-to-zero in a natural way class plus/3 |
plus(? Int1:int, ? Int2:int, ? Int3:int)
properties: deterministic
True if Int3 = Int1 + Int2 At least two of the three arguments must be instantiated to integers