Numbers are very straightforward data structures:
Most mathematical operators are designed to work with them
(2 ** 5.5 / 1 / 3 + 19) % 5 # 4.08494466531301
Note that numbers have what we call a “zero value”:
a value that evaluates to
false when casted to boolean:
!!0 # false
You can use bitwise operators on numbers, but bear in mind that they will be implicitely converted to integers:
1 ^ 1 # 0 1 ^ 0 # 1 1 ^ 0.9 # 1, as 0.9 is converted to 0
You can write numbers in the exponential notation:
1e1 # 10 1e+1 # 10 1e-1 # 0.1
In addition, numbers can include underscores (
_) as visual
separators, in order to improve readability: when
1_000_000 it will internally convert it
to a million. Underscore separators can be placed anywhere
on a number (
10.00_00_00) except at its start:
1000000 # 1M 1_000_000 # 1M, just a lot more readable 1_00_00_00 # 1M, formatted with another separator pattern _100000000 # ERROR: identifier not found: _
Note there is no limit to the amount of consecutive
underscores that can be used (eg.
99.5.number() # 99.5
Rounds down the number to the closest integer:
10.3.int() # 10
Rounds the number with the given precision.
The precision argument is optional, and set to
10.3.round() # 10 10.6.round() # 11 10.333.round(1) # 10.3
Rounds the number up to the closest integer:
10.3.ceil() # 11
Rounds the number down to the closest integer:
10.9.floor() # 10
Returns a string containing the number:
99.str() # "99"
That’s about it for this section!
You can now head over to read about arrays.