Dz
Djazair
v1.0.5
🔍

Math Module

Import using: use math

Constants

  • math.PI - Ratio of a circle's circumference to its diameter (~3.14159).
  • math.E - Euler's constant (~2.71828).
  • math.TAU - Equal to 2 * PI (~6.28318).
use math
print(str(math.PI))     # 3.141592653589793
print(str(math.E))      # 2.718281828459045
print(str(math.TAU))    # 6.283185307179586

Trigonometry

Angle parameters are in radians:

  • math.sin(x), math.cos(x), math.tan(x) - Sine, cosine, tangent
  • math.asin(x), math.acos(x), math.atan(x), math.atan2(y, x) - Inverse trig
  • math.sinh(x), math.cosh(x), math.tanh(x) - Hyperbolic trig
  • math.deg(rad) - Radians to degrees
  • math.rad(deg) - Degrees to radians
use math
print(str(math.sin(math.PI / 2)))  # 1.0
print(str(math.cos(math.PI)))      # -1.0
print(str(math.tan(0)))            # 0.0
print(str(math.deg(math.PI)))      # 180.0
print(str(math.rad(180)))          # 3.141592653589793

Exponentiation & Logs

  • math.sqrt(x) - Square root
  • math.cbrt(x) - Cube root
  • math.pow(x, y) - x raised to power y
  • math.exp(x) - e^x
  • math.log(x) - Natural logarithm
  • math.log10(x) - Base-10 logarithm
  • math.log2(x) - Base-2 logarithm
use math
print(str(math.sqrt(25)))       # 5.0
print(str(math.cbrt(27)))       # 3.0
print(str(math.pow(2, 10)))     # 1024.0
print(str(math.exp(1)))         # 2.718281828459045
print(str(math.log(math.E)))    # 1.0
print(str(math.log10(100)))     # 2.0
print(str(math.log2(8)))        # 3.0

Rounding & Absolute

  • math.ceil(x) - Round up to nearest integer
  • math.floor(x) - Round down to nearest integer
  • math.round(x) - Round half-up to nearest integer
  • math.trunc(x) - Truncate fractional part
  • math.abs(x) - Absolute value
use math
print(str(math.ceil(3.2)))    # 4.0
print(str(math.floor(3.8)))   # 3.0
print(str(math.round(3.5)))   # 4.0
print(str(math.trunc(3.9)))   # 3.0
print(str(math.abs(-5)))      # 5.0

Comparison & Statistics

  • math.min(a, b) - Smaller of two numbers
  • math.max(a, b) - Larger of two numbers
  • math.clamp(val, min, max) - Clamp to inclusive range
  • math.sum(arr) - Arithmetic sum of array
  • math.mean(arr) - Arithmetic mean (Null if empty)
  • math.gcd(a, b) - Greatest Common Divisor
  • math.lcm(a, b) - Least Common Multiple
  • math.factorial(n) - Factorial of non-negative integer
use math
print(str(math.min(3, 7)))        # 3.0
print(str(math.max(3, 7)))        # 7.0
print(str(math.clamp(15, 0, 10))) # 10.0
print(str(math.sum([1, 2, 3])))   # 6.0
print(str(math.mean([1, 2, 3])))  # 2.0
print(str(math.gcd(12, 8)))       # 4
print(str(math.lcm(4, 6)))        # 12
print(str(math.factorial(5)))     # 120
© 2026 Harizi Riyadh. Released under the MIT License.
Official Website for Djazair.