In Eiffel, what is the size of an INTEGER
type?
I was not able to find it, except here, where it is claimed that the size is 32 bits.
In this case, how does Eiffel handle overflow? Is it undefined behavior like in C? Or is there a mechanism to prevent overflow?
If there is any resource where I can find it, then please direct me to it.
According to ECMA standard INTEGER
is defined as an alias for one of the sized variants of integer classes with the recommended size of 64 bits. However, because there is a lot of existing code, current implementations still use 32-bit integers for INTEGER
. The size can be set by a compiler option (e.g., EiffelStudio uses an Eiffel Configuration File (ECF) to map INTEGER
to INTEGER_32
, this is done in the core library Base
). In principle, a library or an application can specify a different size for INTEGER
type using type mapping. The mechanism is not part of Eiffel language specification, therefore usually sized variants are used directly when a specific size is required.
Eiffel standard does not define precise behavior of basic types, i.e. they are treated like any other types from the language perspective. All implementations, I know of, do not check for integer overflow or underflow and silently wrap the result modulo their size.
There are several library-based solutions that provide arbitrary precision integer arithmetic:
FACTORIAL
represents big integer valuesBIG_INTEGER
with a set of other numeric classesINTEGER_X
- an arbitrary precision integerDECIMAL
and MA_DECIMAL
respectively - decimal numbers following the General Decimal Arithmetic Specification