next up previous index
Next: Arithmetic Functions Up: Arithmetic Previous: Built-Ins to Evaluate Arithmetic   Index

Subsections


Numeric Types and Type Conversions

ECLiPSe distinguishes three types of numbers: integers, rationals and floats.


Integers

The magnitude of integers is only limited by your available memory. However, integers that fit into the word size of your computer are represented more efficiently (this distinction is invisible to the user). Integers are written in decimal notation or in base notation, e.g.:
	0  3  -5  1024  16'f3ae  0'a  15511210043330985984000000


Rationals

Rational numbers implement the corresponding mathematical domain, i.e. ratios of two integers (numerator and denominator). ECLiPSe represents rationals in a canonical form where the greatest common divisor of numerator and denominator is 1 and the denominator is positive. Rational constants are written as numerator and denominator separated by an underscore10.1, e.g.
	1_3  -30517578125_32768  0_1
Rational arithmetic is arbitrarily precise. When the global flag prefer_rationals is set, the system uses rational arithmetic wherever possible. In particular, dividing two integers then yields a precise rational rather than a float result.


Floating Point Numbers

Floating point numbers conceptually correspond to the mathematical domain of real numbers, but are not precisely represented. Floats are written with decimal point and/or an exponent, e.g.
	0.0  3.141592653589793  6.02e23  -35e-12  -1.0Inf
ECLiPSe can handle both single and double precision floats. Which precision is used depends on the setting of the global flag float_precision10.2. The default is double precision.

Type Conversions

Note that numbers of different types never unify, e.g. 3, 3_1 and 3.0 are all different. Use the arithmetic comparison predicates when you want to compare numeric values. When numbers of different types occur as arguments of an arithmetic operation or comparison, the types are first made equal by converting to the more general of the two types, i.e. the rightmost one in the sequence
integer -> rational -> single float -> double float
The operation or comparison is then carried out with this type and the result is of this type as well, unless otherwise specified. Beware of the potential loss of precision in the rational -> float conversion! Note that the system never does automatic conversions in the opposite direction. Such conversion must be programmed explicitly using the fix, rational and float functions.


next up previous index
Next: Arithmetic Functions Up: Arithmetic Previous: Built-Ins to Evaluate Arithmetic   Index

1999-08-06