TheDocumentation Index
Fetch the complete documentation index at: https://mintlify.com/elfrask/cls/llms.txt
Use this file to discover all available pages before exploring further.
math module is part of the CLS core standard library — it is always available regardless of which node (desktop or lightweight) is executing your program. It provides the most commonly needed mathematical operations: absolute value, rounding, power, roots, trigonometry, logarithm, random number generation, a numeric range utility, and the two fundamental constants PI and E. All functions accept both int and float arguments and generally return float, with the rounding functions (floor, ceil, round) returning int.
Import
math automatically:
from:
Constants
| Name | Value | Description |
|---|---|---|
math.PI | 3.141592653589793 | The ratio of a circle’s circumference to its diameter |
math.E | 2.718281828459045 | Euler’s number, the base of the natural logarithm |
Function Reference
| Function | Signature | Return type | Description |
|---|---|---|---|
abs | abs(x: float) -> float | int or float | Absolute value — returns int if the input is int, float otherwise |
sqrt | sqrt(x: float) -> float | float | Square root of x |
pow | pow(base: float, exp: float) -> float | float | Raises base to the power exp |
min | min(a: float, b: float) -> float | float | The smaller of a and b |
max | max(a: float, b: float) -> float | float | The larger of a and b |
floor | floor(x: float) -> int | int | Largest integer ≤ x |
ceil | ceil(x: float) -> int | int | Smallest integer ≥ x |
round | round(x: float) -> int | int | Nearest integer to x (half-up rounding) |
random | random() -> float | float | A pseudo-random float in [0, 1) |
sin | sin(x: float) -> float | float | Sine of x (radians) |
cos | cos(x: float) -> float | float | Cosine of x (radians) |
tan | tan(x: float) -> float | float | Tangent of x (radians) |
log | log(x: float) -> float | float | Natural logarithm of x |
range | range(start: int, end: int) -> Array | Array<int> | Integer array [start, start+1, ..., end-1] |
Examples
Arithmetic
Rounding
Trigonometry
Logarithm
Random numbers
Range
Real-world use: distance between two points
math.abs preserves the input type: abs(-5) returns 5 (int), while abs(-3.5) returns 3.5 (float). All other functions always return float, except floor, ceil, round, and range which return int or Array<int>.