math
Mathematical functions for trigonometry, rounding, power, logarithms, and basic operations.
|
|
| Version |
v0.1 |
| Platform |
PC, ESP32 |
| Type |
Native (C) |
star.mod
require dev-libs/math v0.1
Usage
Functions
Trigonometry
| Function |
Signature |
Description |
math.sin(x) |
(number) -> number |
Sine of x (radians) |
math.cos(x) |
(number) -> number |
Cosine of x (radians) |
math.tan(x) |
(number) -> number |
Tangent of x (radians) |
math.atan2(y, x) |
(number, number) -> number |
Angle from x-axis to point (x, y) |
var s: number = math.sin(0.0) # 0.0
var c: number = math.cos(0.0) # 1.0
var t: number = math.tan(0.0) # 0.0
var a: number = math.atan2(1.0, 1.0) # ~0.7854 (π/4)
Rounding
| Function |
Signature |
Description |
math.floor(x) |
(number) -> number |
Round down to nearest integer |
math.ceil(x) |
(number) -> number |
Round up to nearest integer |
math.round(x) |
(number) -> number |
Round to nearest integer (half up) |
var f: number = math.floor(3.7) # 3.0
var c: number = math.ceil(3.2) # 4.0
var r: number = math.round(3.5) # 4.0
Power & Logarithms
| Function |
Signature |
Description |
math.pow(x, y) |
(number, number) -> number |
x raised to the power y |
math.sqrt(x) |
(number) -> number |
Square root of x |
math.log(x) |
(number) -> number |
Natural logarithm (base e) |
math.log10(x) |
(number) -> number |
Base-10 logarithm |
var p: number = math.pow(2.0, 10.0) # 1024.0
var s: number = math.sqrt(16.0) # 4.0
var l: number = math.log(1.0) # 0.0
var d: number = math.log10(100.0) # 2.0
Absolute Value
| Function |
Signature |
Description |
math.abs(x) |
(number) -> number |
Absolute value of x |
var a: number = math.abs(-5.0) # 5.0
var b: number = math.abs(3.0) # 3.0
Min / Max
| Function |
Signature |
Description |
math.min(a, b) |
(number, number) -> number |
Smaller of a and b |
math.max(a, b) |
(number, number) -> number |
Larger of a and b |
var lo: number = math.min(3.0, 7.0) # 3.0
var hi: number = math.max(3.0, 7.0) # 7.0
Notes
- All functions operate on
number (64-bit double precision)
- Trigonometric functions use radians, not degrees
math.log(x) is the natural logarithm (ln), not base-10
- For integer math, use
i32 arithmetic directly — no library needed
- On ESP32, all math functions are available (backed by hardware FPU or soft-float)