math Module

The math module provides mathematical constants, trigonometric operations, logarithms, power functions, statistical aggregations, and number theory utilities.

Importing

djazair
use math

Mathematical Constants

  • math.PI: Ratio of circle circumference to diameter (~3.141592653589793).
  • math.E: Base of natural logarithms (~2.718281828459045).
  • math.TAU: 2 * PI (~6.283185307179586).

Functions Catalog

FunctionDescriptionExample
math.sqrt(x)Square rootmath.sqrt(16) # => 4.0
math.cbrt(x)Cube rootmath.cbrt(27) # => 3.0
math.pow(x, y)x raised to power ymath.pow(2, 10) # => 1024.0
math.sin(x) / cos(x) / tan(x)Trigonometric functions (radians)math.sin(math.PI / 2) # => 1.0
math.log(x) / log10(x) / log2(x)Logarithms (natural, base-10, base-2)math.log10(1000) # => 3.0
math.ceil(x) / floor(x) / round(x)Rounding functionsmath.ceil(2.1) # => 3
math.gcd(a, b)Greatest Common Divisormath.gcd(12, 8) # => 4
math.lcm(a, b)Least Common Multiplemath.lcm(4, 6) # => 12
math.factorial(n)Factorial n!math.factorial(5) # => 120
math.clamp(x, min, max)Restricts x between min and maxmath.clamp(15, 0, 10) # => 10
math.deg(rad) / rad(deg)Angle conversionsmath.deg(math.PI) # => 180.0