Datatype int
An integer is a number of the set Z = {…, -2, -1, 0, 1, 2, …}.
Syntax
Integers can be specified only in decimal (10-based) notation, optionally preceded by a sign (- or +). You may use scientific notation.
Example: Integer literals
d = 1234; // decimal number d = -123; // a negative number d = 1.3E+6; // 1 300 000
The size of an integer is 32 bit. Internally the compiler takes care about integers only when loading and storing them from/to memory.
Converting to/from integers
Integers are converted automatically to other datatypes if necessary and allowed. Because they are just truncated real values they seem to behave very similar to the real datatype.
Converting to:
- bool: 0 gets converted to false, any other value gets converted to true.
- real: integer value gets converted to exactly the same value
- complex: integer value gets converted to a complex number with real part=integer value, imaginary part=0
- quaternion: integer value gets converted to a quaternion number with real part=integer value, all other parts are set to 0
Converting from:
- bool: false gets converted to 0, true gets converted to 1.
- real: converting a real value to integer just rounds towards zero (i.e. fractional part truncated).
- complex: the resulting integer value is the truncated part of the real component
- quaternion: the resulting integer value is the truncated part of the real component