Skip to content

Numbers and Logic

Chloë Strainge edited this page Oct 15, 2026 · 2 revisions

Numbers and logic

Integer is signed 64-bit. Float is a finite floating-point number. Number accepts either concrete numeric type; it does not erase which one a value has.

Arithmetic

echo (11 / 4) (11.0 / 4) (11 / 4.0)
echo (11.5 % 4) (-11 / 4)
let $ratio: Float = 11
echo ($ratio / 4)
2 2.75 2.75
3.5 -2
2.75

*, /, and % bind more tightly than + and -. Operations at the same precedence associate left to right. Integer division truncates toward zero. A Float operand promotes the other numeric operand; % gives a remainder for Floats too. Use parentheses when grouping matters.

Integer overflow, zero divisors, and non-finite results are errors. Explicit Float-to-Integer conversion requires an integral, representable value. Floating-point arithmetic has finite precision; keep exact identifiers as Integers.

String + concatenates two Strings. Other arithmetic requires numeric values: text that looks numeric is still text until explicitly converted.

Equality and ordering

== and != compare values. Numeric pairs compare numerically; unrelated kinds such as "2" and 2 are unequal. Arrays compare element-by-element, hashes by entries, and named values include their nominal identity. String equality compares text, including executable String references' text.

<, <=, >, and >= order numbers. Ordering Strings or structs is an error. Same-type named numeric values support ordering through their underlying numbers. Mixed Integer/Float comparisons preserve the Integer's exact value; they do not round it to Float first. Equality, relational operators, and numeric array sorting use the same relation. Arithmetic promotion remains a separate rule.

let $serial = 9007199254740993
let $rounded: Float = 9007199254740992.0
echo ($serial == $rounded) ($serial > $rounded)
let $ordered = [$serial, $rounded].sort
echo $ordered[0].type $ordered[1].type
false true
Float Integer

Truthiness

Value False when…
() Always
Boolean Its value is false
Integer / Float It is zero
String It is empty
Array / hash / argument expansion It is empty
Bounded range It contains no items
ExecResult The command failed or was signaled

Structs, enum values, types, and function values are true. Nonempty Strings such as "false", "0", and "0.0" are true.

echo Boolean("") Boolean("0.0") Boolean(0.0)
let $count = 4
if $count > 0 && $count < 8 { echo "small batch" }
false true false
small batch

! negates truthiness. && and || short-circuit and return Boolean results, rather than returning one of their operands. Their right side is evaluated only when required. Bare command words used as truth-tested operands are called; quoted Strings and explicit references remain values.


Related: Control flow · Conversions · Exit status

Clone this wiki locally