Standard Library
math Package
Complete reference for all built-in math package APIs in PriyoScript.
Theory
The math package is the standard numeric utility package in PriyoScript. It provides safe arithmetic, aggregation, trigonometry, unit conversion, and geometry helpers so users do not need to rewrite common calculations in every program. All APIs are runtime-validated, so invalid inputs produce clear errors.
Current status
math is stable and production-ready in current PriyoScript docs.
Import
monalisa {
lisaaBring math
priyoTell(math.add(2, 3))
}API Table
Arithmetic APIs
| Method | Signature | Description |
|---|---|---|
add | math.add(a, b) | Adds two numbers |
sub | math.sub(a, b) | Subtracts second from first |
mul | math.mul(a, b) | Multiplies two numbers |
div | math.div(a, b) | Divides first by second |
mod | math.mod(a, b) | Remainder operation |
abs | math.abs(value) | Absolute value |
pow | math.pow(base, exponent) | Exponentiation |
sqrt | math.sqrt(value) | Square root |
cube | math.cube(value) | Cube (value^3) |
round | math.round(value) | Rounds to nearest integer |
floor | math.floor(value) | Rounds down |
ceil | math.ceil(value) | Rounds up |
Aggregate APIs
| Method | Signature | Description |
|---|---|---|
sum | math.sum(...values) | Sum of all values |
average | math.average(...values) | Mean value |
min | math.min(...values) | Smallest value |
max | math.max(...values) | Largest value |
clamp | math.clamp(value, minValue, maxValue) | Bounds a value in range |
percent | math.percent(value, total) | Value as percent |
gcd | math.gcd(a, b) | Greatest common divisor |
lcm | math.lcm(a, b) | Least common multiple |
factorial | math.factorial(value) | Factorial (integer) |
Trigonometry APIs (radians)
| Method | Signature | Description |
|---|---|---|
sin | math.sin(radians) | Sine |
cos | math.cos(radians) | Cosine |
tan | math.tan(radians) | Tangent |
asin | math.asin(value) | Inverse sine |
acos | math.acos(value) | Inverse cosine |
atan | math.atan(value) | Inverse tangent |
degToRad | math.degToRad(degrees) | Degree to radian conversion |
radToDeg | math.radToDeg(radians) | Radian to degree conversion |
distance2d | math.distance2d(x1, y1, x2, y2) | 2D distance |
distance3d | math.distance3d(x1, y1, z1, x2, y2, z2) | 3D distance |
Geometry APIs
| Method | Signature | Description |
|---|---|---|
areaCircle | math.areaCircle(radius) | Circle area |
areaRectangle | math.areaRectangle(length, width) | Rectangle area |
areaTriangle | math.areaTriangle(base, height) | Triangle area |
areaSquare | math.areaSquare(side) | Square area |
circumference | math.circumference(radius) | Circle circumference |
API Examples (Every Method)
Arithmetic + Aggregate
monalisa {
lisaaBring math
priyoTell(math.add(10, 5))
priyoTell(math.sub(10, 5))
priyoTell(math.mul(10, 5))
priyoTell(math.div(10, 5))
priyoTell(math.mod(10, 3))
priyoTell(math.abs(-9))
priyoTell(math.pow(2, 4))
priyoTell(math.sqrt(25))
priyoTell(math.cube(3))
priyoTell(math.round(12.7))
priyoTell(math.floor(12.7))
priyoTell(math.ceil(12.1))
priyoTell(math.random(1, 5))
priyoTell(math.lerp(10, 20, 0.25))
priyoTell(math.sum(1, 2, 3, 4))
priyoTell(math.average(10, 20, 30))
priyoTell(math.min(9, 2, 7))
priyoTell(math.max(9, 2, 7))
priyoTell(math.clamp(27, 0, 20))
priyoTell(math.percent(25, 200))
priyoTell(math.gcd(24, 18))
priyoTell(math.lcm(12, 18))
priyoTell(math.factorial(5))
}Output:
15
5
50
2
1
9
16
5
27
13
12
13
(random between 1 and 5)
12.5
10
20
2
9
20
12.5
6
36
120Trigonometry + Conversion
monalisa {
lisaaBring math
priyoKeep r = math.degToRad(30)
priyoTell(math.sin(r))
priyoTell(math.cos(r))
priyoTell(math.tan(r))
priyoTell(math.asin(0.5))
priyoTell(math.acos(0.5))
priyoTell(math.atan(1))
priyoTell(math.degToRad(180))
priyoTell(math.radToDeg(3.141592653589793))
priyoTell(math.distance2d(0, 0, 3, 4))
priyoTell(math.distance3d(0, 0, 0, 1, 2, 2))
}Output:
0.49999999999999994
0.8660254037844387
0.5773502691896257
0.5235987755982989
1.0471975511965979
0.7853981633974483
3.141592653589793
180
5
3Geometry
monalisa {
lisaaBring math
priyoTell(math.areaCircle(2))
priyoTell(math.areaRectangle(10, 5))
priyoTell(math.areaTriangle(10, 5))
priyoTell(math.areaSquare(9))
priyoTell(math.circumference(2))
}Output:
12.566370614359172
50
25
81
12.566370614359172Error Cases
monalisa {
lisaaBring math
priyoTell(math.div(10, 0))
}Expected error:
math.div cannot divide by zeromonalisa {
lisaaBring math
priyoTell(math.sqrt(-1))
}Expected error:
math.sqrt expects non-negative valueValidation Notes
divandmodreject zero divisor. -sqrt,areaCircle,areaSquare,areaTriangle,areaRectangle,circumferencerequire non-negative dimensions. - All APIs expect numeric arguments.
Practice Questions
Concept Check
- When should you use
clampinstead of manualifchecks? 2. Why mustsin/cos/taninput be in radians in this API? 3. Which geometry API would you use for each: coin, notebook, and warning sign triangle?
Related Docs
Last updated on