Number and number literals
Numbers describe amounts and positions. A literal is a value you write directly, such as 42. Pliro stores numbers with limited precision, so some fractions are approximate. The rounding explanation shows why 0.1 + 0.2 can surprise you.
Number literals use ASCII decimal digits with an optional fractional part:
0
42
3.14
The decimal point requires digits on both sides. A sign is a separate unary
operator:
-12
+3.5
The following forms are not supported:
.5 # use 0.5
1. # use 1.0
1e6 # no exponent syntax
1_000 # no digit separators
0xff # no hexadecimal literals
0b1010 # no binary literals
At runtime, every Number is a finite IEEE 754 binary64 value. NaN and infinity
are not successful values.
Numbers use binary floating-point. Familiar floating-point rounding can occur.
Results must stay finite. Number display uses a short round-trippable decimal
form and does not add .0 to whole values.
Indexes, collection sizes, random bounds, and GPIO pins impose additional
whole-number and range requirements.
Example
# language: en
say 3.5 + 2
say(-8 / 2)
