Keyboard shortcuts

Press ← or → to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

Numbers and Comparisons

All operations on this page are Functions: arguments are evaluated from left to right before overload selection. Arithmetic supports separate integer and float signatures. Arguments in one call must all use the same numeric type; there is no implicit conversion.

Arithmetic

FunctionArgumentsResult
add(left, right, rest...)At least two integers or two floatsSum, same type
subtract(left, right)Two integers or two floatsDifference, same type
multiply(left, right, rest...)At least two integers or two floatsProduct, same type
divide(left, right)Two integers or two floatsQuotient, same type
modulo(left, right)Two integers or two floatsRemainder, same type
negate(value)One integer or floatNegated value, same type

add

Sums the arguments in order. Requires at least two arguments.

print(add(1, 2, 3)) / 6
print(add(1.5, 2.5)) / 4

subtract

Subtracts the right argument from the left.

print(subtract(10, 3)) / 7

multiply

Multiplies the arguments in order. Requires at least two arguments.

print(multiply(2, 3, 4)) / 24

divide

Divides the left argument by the right. Integer division truncates toward zero; integer division by zero is a runtime error. Float division follows IEEE 754 arithmetic and may produce infinity or NaN rather than an error.

print(divide(7, 2)) / 3
print(divide(7.0, 2.0)) / 3.5
print(divide(negate(7), 2)) / -3

modulo

Returns the remainder. For integers, its sign follows the left operand; a zero divisor is a runtime error. Float remainder may produce NaN.

print(modulo(7, 3)) / 1
print(modulo(negate(7), 3)) / -1

negate

Changes the sign of its argument. Negative literal syntax is not provided; use this operation when writing a negative number.

print(negate(3)) / -3

Integer operations currently use Rust’s ordinary signed 64-bit arithmetic. Overflow is not converted into a DETLEF error: debug builds can panic, while ordinary release builds wrap for addition, subtraction, multiplication, and negation. Dividing or taking the remainder of the smallest integer by -1 can panic in either build. Avoid overflowing inputs until checked arithmetic is implemented.

Comparisons

FunctionArgumentsResult
equal(first, second, rest...)At least two integers, or at least two stringsBoolean
less(first, second, rest...)At least two integers or floatsBoolean
greater(first, second, rest...)At least two integers or floatsBoolean
less_equal(first, second, rest...)At least two integers or floatsBoolean
greater_equal(first, second, rest...)At least two integers or floatsBoolean
close(left, right, tolerance)Three floatsBoolean

equal

Returns true when every adjacent pair is equal. Strings are compared exactly, including case. There are no equal overloads for floats, booleans, arrays, records, or none; use is_none for absence.

print(equal(3, 3, 3)) / true
print(equal("DETLEF", "detlef")) / false

less

Returns true if each argument is strictly less than the next.

print(less(1, 2, 3)) / true
print(less(1, 3, 2)) / false

greater

Returns true if each argument is strictly greater than the next.

print(greater(3, 2, 1)) / true

less_equal

Returns true if each argument is less than or equal to the next.

print(less_equal(1, 1, 2)) / true

greater_equal

Returns true if each argument is greater than or equal to the next.

print(greater_equal(3, 3, 2)) / true

Variadic comparisons still evaluate all arguments before comparing values; they do not short-circuit argument evaluation.

close

Returns whether the absolute difference between two floats is at most the tolerance. A negative tolerance is an error; zero tests for zero difference.

print(close(1.0, 1.001, 0.01)) / true

NaN makes these comparisons false. close uses an absolute tolerance, not a relative one. Boolean logic can be expressed with if; the library currently has no and, or, or not operations.