PriyoScriptPriyoScript
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

MethodSignatureDescription
addmath.add(a, b)Adds two numbers
submath.sub(a, b)Subtracts second from first
mulmath.mul(a, b)Multiplies two numbers
divmath.div(a, b)Divides first by second
modmath.mod(a, b)Remainder operation
absmath.abs(value)Absolute value
powmath.pow(base, exponent)Exponentiation
sqrtmath.sqrt(value)Square root
cubemath.cube(value)Cube (value^3)
roundmath.round(value)Rounds to nearest integer
floormath.floor(value)Rounds down
ceilmath.ceil(value)Rounds up

Aggregate APIs

MethodSignatureDescription
summath.sum(...values)Sum of all values
averagemath.average(...values)Mean value
minmath.min(...values)Smallest value
maxmath.max(...values)Largest value
clampmath.clamp(value, minValue, maxValue)Bounds a value in range
percentmath.percent(value, total)Value as percent
gcdmath.gcd(a, b)Greatest common divisor
lcmmath.lcm(a, b)Least common multiple
factorialmath.factorial(value)Factorial (integer)

Trigonometry APIs (radians)

MethodSignatureDescription
sinmath.sin(radians)Sine
cosmath.cos(radians)Cosine
tanmath.tan(radians)Tangent
asinmath.asin(value)Inverse sine
acosmath.acos(value)Inverse cosine
atanmath.atan(value)Inverse tangent
degToRadmath.degToRad(degrees)Degree to radian conversion
radToDegmath.radToDeg(radians)Radian to degree conversion
distance2dmath.distance2d(x1, y1, x2, y2)2D distance
distance3dmath.distance3d(x1, y1, z1, x2, y2, z2)3D distance

Geometry APIs

MethodSignatureDescription
areaCirclemath.areaCircle(radius)Circle area
areaRectanglemath.areaRectangle(length, width)Rectangle area
areaTrianglemath.areaTriangle(base, height)Triangle area
areaSquaremath.areaSquare(side)Square area
circumferencemath.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
120

Trigonometry + 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
3

Geometry

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.566370614359172

Error Cases

monalisa {
  lisaaBring math
  priyoTell(math.div(10, 0))
}

Expected error:

math.div cannot divide by zero
monalisa {
  lisaaBring math
  priyoTell(math.sqrt(-1))
}

Expected error:

math.sqrt expects non-negative value

Validation Notes

  • div and mod reject zero divisor. - sqrt, areaCircle, areaSquare, areaTriangle, areaRectangle, circumference require non-negative dimensions. - All APIs expect numeric arguments.

Practice Questions

Concept Check

  1. When should you use clamp instead of manual if checks? 2. Why must sin/cos/tan input be in radians in this API? 3. Which geometry API would you use for each: coin, notebook, and warning sign triangle?

Last updated on

On this page