Repository navigation
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.
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.
== 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
| 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
Begin here
Values and expressions
- Language basics
- Variables and scope
- Numbers and logic
- Strings and paths
- Arrays
- Hash maps
- Ranges and iteration
- Control flow
- Match and type guards
Functions and types
- Functions and calls
- Closures and function types
- Methods and properties
- Structs
- Enums
- Named types and unions
- Conversions
- Types and properties
Shell and modules
- Pipelines
- Pipeline splits
- Pipeline formats
- Commands and exit status
- Redirection
- Environment and exported variables
- Modules and visibility
- Nested modules and directory packages
- Conditional imports and declarations
- Errors and cleanup
- Supervised processes and terminals
Library guides
- Standard library
- The implicit prelude
- Bytes, files, readers, and writers
- Explicit item streams
- JSON documents and typed mapping
- Sockets, DNS, and TLS
- HTTP clients
- HTTP servers
- Framing, server-sent events, and JSON-RPC
- Terminal colors, styles, and geometry
- Build an application console
Interactive use