Math Library¶
Introduction¶
The math library (@math) provides a range of mathematical functions, including basic operations, trigonometric functions, random number generation, and more.
Import¶
1 | |
Function Reference¶
Basic Math Functions¶
math.abs(x)¶
Calculate absolute value.
Parameters:
- x - Number
Returns: - Absolute value of the number
Example:
1 | |
math.sqrt(x)¶
Calculate square root.
Parameters:
- x - Non-negative number
Returns: - Square root value
Example:
1 | |
math.pow(x, y)¶
Calculate power operation.
Parameters:
- x - Base
- y - Exponent
Returns: - x raised to the power of y
Example:
1 | |
Trigonometric Functions¶
math.sin(x)¶
Calculate sine value (in degrees).
Parameters:
- x - Angle in degrees
Returns: - Sine value
Example:
1 | |
math.cos(x)¶
Calculate cosine value (in degrees).
Parameters:
- x - Angle in degrees
Returns: - Cosine value
Example:
1 | |
math.tan(x)¶
Calculate tangent value (in degrees).
Parameters:
- x - Angle in degrees
Returns: - Tangent value
Example:
1 | |
Math Constants¶
math.pi()¶
Return the value of pi (π).
Parameters: None
Returns: - Value of π (approximately 3.14159...)
Example:
1 | |
math.e()¶
Return the value of Euler's number (e).
Parameters: None
Returns: - Value of e (approximately 2.71828...)
Example:
1 | |
Extremum Functions¶
math.max(...args)¶
Calculate the maximum of multiple numbers.
Parameters:
- ...args - Multiple numbers
Returns: - Maximum value
Example:
1 | |
math.min(...args)¶
Calculate the minimum of multiple numbers.
Parameters:
- ...args - Multiple numbers
Returns: - Minimum value
Example:
1 | |
Random Number Functions¶
math.random()¶
Generate a random number between 0 and 1.
Parameters: None
Returns: - Random float between 0 and 1
Example:
1 | |
math.randint(a, b)¶
Generate a random integer within a specified range.
Parameters:
- a - Minimum value
- b - Maximum value
Returns: - Random integer between a and b (inclusive)
Example:
1 | |
Example Code¶
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 | |