Variables
Similar to python, variables do not require specific types and can be declared as follows:
from "std" import *
res_value = 10k
at res(res_value)
Numeric type
Besides integers and floating numbers, specify numeric values using the following multiplers:
| Multipler | Value | Example |
|---|---|---|
p | pico | 10p |
n | nano | 10n |
u | micro | 10u |
m | mili | 10m |
k | kilo | 10k |
M | mega | 10M |
Math operations
The usual math operations are supported: addition, subtraction, multiplication and division.
Chained comparisons
Comparisons chain Python-style: each adjacent pair in the chain is evaluated, and the whole chain
is true only if every link holds. The chain short-circuits at the first false link. The following
operators may be chained: <, <=, >, >=, ==.
print(1 < 2 < 3) # true
print(1 < 5 < 3) # false
print(3 > 2 > 1) # true
print(1 < 2 <= 2) # true, operators may be mixed
print(10k < 20k < 30k) # true, works with unit multipliers
print(1 < 2 < 3 < 4 < 5) # true, chains of any length
Chained comparisons work as if conditions and with variables, the same as any other boolean
expression.
Tolerances
A numeric value can carry a tolerance, attached with + and a bracketed list:
r1 = 10k + [5%] # symmetric: 10k +- 5%
r2 = 10k + [5%, 2%] # asymmetric: +5% / -2%
r3 = 10k + [100] # absolute tolerance, not a percentage
A single entry in the list sets a symmetric tolerance. Two entries set an asymmetric tolerance,
with the first as the plus bound and the second as the minus bound. An entry without a % sign is
an absolute tolerance in the same units as the value, not a percentage.
Percentage literals must be positive integers with no leading zero — 0.5% and 0% are not valid
and are rejected as parse errors. A leading zero such as 05% is not treated as a single
percentage literal either: the lexer reads it as two separate tokens (0 and 5%), so
10k + [05%] parses as a two-entry tolerance list rather than a single 5% tolerance.
Printing a toleranced value shows the tolerance using the interpreter's own ASCII notation: a
single tolerance renders as 10k +- 5%, an asymmetric one as 10k +5%/-2%, and an absolute one as
10k +- 100.
Tolerances propagate through arithmetic using worst-case bounds. All figures below are absolute
values in the operand's units — +-700 means +700/-700:
| Operation | Rule | Example | Result |
|---|---|---|---|
a + b | absolute bounds add directly | 10k+[5%] + 20k+[1%] | 30k, +-700 |
a - b | plus pairs with the other operand's minus (cross term) | 10k+[5%,2%] - 20k+[4%,1%] | -10k, +700/-1000 |
a * b | relative tolerances add | 10k+[5%] * 2+[1%] | 20k, +-1200 |
a / b | cross terms on the relative tolerances | 10k+[5%,2%] / 2+[3%,1%] | 5k, +300/-250 |
Asymmetric tolerances stay independently tracked through arithmetic — the plus and minus bounds
are computed separately rather than being collapsed into a single worst case. roundDp preserves
a value's tolerance onto the rounded result. Negation swaps the plus and minus bounds rather than
preserving them, since negating a value flips which side is worse case. An operand with no
tolerance contributes nothing to the result, so (10k + [5%]) + 5k keeps a tolerance of +-500.