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
| Function | Description | Example |
|---|---|---|
math.sqrt(x) | Square root | math.sqrt(16) # => 4.0 |
math.cbrt(x) | Cube root | math.cbrt(27) # => 3.0 |
math.pow(x, y) | x raised to power y | math.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 functions | math.ceil(2.1) # => 3 |
math.gcd(a, b) | Greatest Common Divisor | math.gcd(12, 8) # => 4 |
math.lcm(a, b) | Least Common Multiple | math.lcm(4, 6) # => 12 |
math.factorial(n) | Factorial n! | math.factorial(5) # => 120 |
math.clamp(x, min, max) | Restricts x between min and max | math.clamp(15, 0, 10) # => 10 |
math.deg(rad) / rad(deg) | Angle conversions | math.deg(math.PI) # => 180.0 |