The module contains mathematical methods and constants. Call the require
function to load the module before first using its methods:
The number π = 3.14159265358979323846264338327950288.
The number e (Euler's number) = 2.71828182845904523536028747135266250.
The smallest number that satisfies the condition: 1.0 + EPSILON != 1.0. EPSILON = 2.2204460492503131e-16.
Return the absolute value of a number.
Parameters
Returns
The absolute value of x
. If x
is negative (including -0), returns -x
. Otherwise, returns x
. The result is therefore always a positive number or 0.
Example
Return the inverse cosine (in radians) of a number.
Parameters
Returns
The inverse cosine (angle in radians between 0 and π, inclusive) of x
. If x
is less than -1 or greater than 1, returns NaN
.
Example
Return the inverse hyperbolic cosine of a number.
Parameters
Returns
The inverse hyperbolic cosine of x
.
Example
Return the inverse sine (in radians) of a number.
Parameters
Returns
The inverse sine (angle in radians between -𝜋/2 and 𝜋/2, inclusive) of x
.
Example
Return the inverse hyperbolic sine of a number.
Parameters
Returns
The inverse hyperbolic sine of x
.
Example
Return the inverse tangent (in radians) of a number.
Parameters
Returns
The inverse tangent (angle in radians between -𝜋/2 and 𝜋/2, inclusive) of x
.
Example
Return the angle in the plane (in radians) between the positive x-axis and the ray from (0, 0) to the point (x, y), for math.atan2(y, x).
Parameters
Returns
The angle in radians (between -π and π, inclusive) between the positive x-axis and the ray from (0, 0) to the point (x, y).
Example
The method returns the inverse hyperbolic tangent of a number.
Parameters
Returns
The inverse hyperbolic tangent of x
.
Example
Return the cube root of a number.
Parameters
Returns
The cube root of x
.
Example
Round up and return the smallest integer greater than or equal to a given number.
Parameters
Returns
The smallest integer greater than or equal to x
. It's the same value as -math.floor(-x)
.
Example
Return the number of leading zero bits in the 32-bit binary representation of a number.
Parameters
Returns
The number of leading zero bits in the 32-bit binary representation of x
.
Example
Return the cosine of a number in radians.
Parameters
Returns
The cosine of x
, between -1 and 1, inclusive.
Example
Return e raised to the power of a number.
Parameters
Returns
A nonnegative number representing e^x
, where e
is the base of the natural logarithm.
Example
Round down and return the largest integer less than or equal to a given number.
Parameters
Returns
The largest integer smaller than or equal to x
. It's the same value as -math.ceil(-x)
.
Example
Return the natural logarithm of x.
Parameters
Returns
The natural logarithm of x
, as in ln(x)
where e
is the base of the natural logarithm.
Example
Return true if the difference between numbers a
and b
is less than the specified tolerance
.
Parameters
Returns
True if the difference between numbers a
and b
is less than the specified parameter e
. Otherwise, false.
Example
Return the largest of two numbers given as input parameters.
Parameters
Returns
The largest of the given numbers.
Example
Return the smallest of two numbers given as input parameters.
Parameters
Returns
The smallest of the given numbers.
Example
Return the value of a base raised to a power.
Parameters
Returns
A number representing base taken to the power of exponent.
Example
Return a floating-point, pseudo-random number that's greater than or equal to 0 and less than 1, with approximately uniform distribution over that range — which you can then scale to your desired range.
Returns
A floating-point, pseudo-random number between 0 (inclusive) and 1 (exclusive).
Example
Return 1 or -1, indicating the sign of the number passed as argument.
Parameters
Returns
-1 if the number is less than 0, and 1 otherwise.
Example
Return the sine of a number in radians.
Parameters
Returns
The sine of x
, between -1 and 1, inclusive.
Example
Return the square root of a number.
Parameters
Returns
The square root of x
, a nonnegative number. If x
< 0, script will fail with an error.
Example
Return the integer part of a number by removing any fractional digits.
Parameters
Returns
The integer part of x
.
Example