Skip to content

Numbers

Numbers in RuLA represent numeric values, including both integers and decimal numbers.

Creating Numbers

Write numbers directly without quotes:

42          # Integer
-7          # Negative number
3.14159     # Decimal number
0.5         # Decimal less than 1

Number Operations

Arithmetic

5 + 3           # Addition: 8
10 - 4          # Subtraction: 6
3 * 4           # Multiplication: 12
15 / 3          # Division: 5
17 // 5         # Integer division: 3
17 % 5          # Modulo (remainder): 2
2 ** 3          # Exponentiation: 8

Comparison

5 > 3           # Greater than: True
5 >= 5          # Greater than or equal: True
3 < 5           # Less than: True
4 <= 5          # Less than or equal: True

Rounding and Precision

ROUND(3.14159)          # Round to nearest integer: 3
ROUND(3.14159, 2)       # Round to 2 decimals: 3.14
FLOOR(3.7)              # Round down: 3
CEIL(3.2)               # Round up: 4

Absolute Value and Sign

ABS(-5)                 # Returns 5
SIGN(-5)                # Returns -1
SIGN(5)                 # Returns 1
SIGN(0)                 # Returns 0

Useful Number Functions

Function Description Example
SUM Sum of all numbers in a list SUM([1, 2, 3]) → 6
AVG Average of numbers in a list AVG([1, 2, 3]) → 2
MIN Smallest number in a list MIN([3, 1, 2]) → 1
MAX Largest number in a list MAX([3, 1, 2]) → 3
ROUND Round to nearest integer ROUND(2.5) → 3
ROUND(number, decimals) Round to N decimal places ROUND(3.14159, 2) → 3.14
FLOOR Round down to integer FLOOR(3.9) → 3
CEIL Round up to integer CEIL(3.1) → 4
ABS Absolute value ABS(-5) → 5
SIGN Sign of number (-1, 0, 1) SIGN(-5) → -1
SQRT Square root SQRT(16) → 4
CLAMP Constrain to range CLAMP(10, 0, 5) → 5
COMB Combinations (n choose k) COMB(5, 2) → 10
SUM_PRODUCT Sum of products SUM_PRODUCT([1,2], [3,4]) → 11

Working with Lists of Numbers

Aggregate functions work on lists:

numbers = [10, 20, 30, 40]
SUM(numbers)        # 100
AVG(numbers)        # 25
MIN(numbers)        # 10
MAX(numbers)        # 40

Type Checking

To check if a value is a number:

# Numbers are always known (not None/unknown)
known(42)           # True
unknown(42)         # False