Arithmetic
In the terminalela --spec arithmetic
- Ordinary infix maths in expressions, no
$(( )):count = $count + 1. - Operators:
+ - * / %, comparisons== != < <= > >=, logicand,or,not. andandorstop early:andworks out its right side only when its left is true, andoronly when its left is false. A test that guards what follows it is one line:if has($m, "k") and $m["k"] > 0never reads the missing key, andif $err != null and $err.stderr != ""never reads a field of null.- Bash's and C's
||,&&and!in an expression are errors that name the word to write:if $a || $bstops withwrite or for ||. In a condition,! cmdstops with the word to write,if not cmd. - One visible
numbertype. Internally it is a 64-bit integer while whole, and becomes a float only when needed (as in Lua 5.3), so large integers such as nanosecond timestamps keep full precision. - Integer overflow is an error (fail fast), never a silent wrap-around.
/always gives the exact result:7 / 2is 3.5.//is whole-number division:7 // 2is 3.%is the remainder.- Conversions are explicit:
int(x)truncates towards zero,float(x)reads a number that may have a fraction or an exponent,float("2.5"). Both refuse text with spaces or underscores. Whatfloatgives is a number as any other, whole when it is whole:float("1")indexes a list. - A value becomes text inside a string,
"$x"or"${int($x)}". A call tostr(…)orstring(…)stops before line 1 and says so, andnumber(…)namesint(x)andfloat(x).