Numbers¶
Numbers in RuLA represent numeric values, including both integers and decimal numbers.
Creating Numbers¶
Write numbers directly without quotes:
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¶
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:
Type Checking¶
To check if a value is a number: