Numbers
| Integers | |
| Floats | |
| Integer math | |
| Other bases and chars |
Integers
Plain digits build an integer of any size, limited only by memory. The arithmetic operators are the usual four.
1> 42.
42
2> 2 + 3 * 4.
14
1> 42.
42
2> 2 + 3 * 4.
14
Floats
A dot builds a float. The division operator always returns a float, even when both sides divide cleanly.
Use the caret for powers and the math module for the rest of the school functions.
1> 3.14.
3.14
2> 7 / 2.
3.5
3> 2.0 * 2.0.
4.0
1> 3.14.
3.14
2> 7 / 2.
3.5
3> 2.0 * 2.0.
4.0
Integer math
The div operator divides whole numbers, and rem gives the remainder. Both demand integer arguments.
The result sign follows the dividend, so negative numbers keep the remainder sign of the left side.
1> 7 div 2.
3
2> 7 rem 2.
1
3> -7 rem 2.
-1
1> 7 div 2.
3
2> 7 rem 2.
1
3> -7 rem 2.
-1
Other bases and chars
A base prefix builds a number in that base: two hashes for binary, sixteen for hexadecimal. The dollar sign builds a character code.
These literals are plain integers once compiled, so they mix freely with the rest of your math.
1> 2#1010.
10
2> 16#ff.
255
3> $A.
65
1> 2#1010.
10
2> 16#ff.
255
3> $A.
65
Next: Atoms
Article author: Arthur Isaev