Constants
(constant) math_e :float
The Number value for e, Euler's number,
which is approximately 2.718281828459045.
Type:
- float
(constant) math_inf :float
The name inf refers to float value positive infinity.
(For negative infinity, use -math.inf.)
See also Python 3.13 Documentation.
Type:
- float
(constant) math_nan :float
A floating-point “not a number” (nan) value.
See also Python 3.13 Documentation.
Type:
- float
(constant) math_pi :float
The float value of
π,
the ratio of the circumference of a circle to its diameter,
which is approximately 3.1415926535897932.
Type:
- float
(constant) math_tau :float
Tau is a circle constant equals to
2π,
the ratio of a circle’s circumference to its radius,
which is approximately 6.283185307179586.
Type:
- float
Functions
math_acos(x) → {float}
Return the arc cosine of
x, in radians. The result is between 0 and pi.
Parameters:
| Name | Type | Description |
|---|---|---|
|
int | float | The value whose arc cosine is to be computed. Must be in the interval
[-1, 1]. |
Returns:
the arc cosine of
x in radians
- Type
- float
math_acosh(x) → {float}
Return the inverse hyperbolic cosine of
x.
Parameters:
| Name | Type | Description |
|---|---|---|
|
int | float | The number for which to compute the inverse hyperbolic cosine.
(Typically, x must be ≥ 1.) |
Returns:
the inverse hyperbolic cosine of
x
- Type
- float
math_asin(x) → {float}
Return the arc sine of
x, in radians. The result is between -pi/2 and pi/2.
Parameters:
| Name | Type | Description |
|---|---|---|
|
int | float | The value whose arc sine is to be computed. Must be in the interval
[-1, 1]. |
Returns:
the arc sine of
x in radians
- Type
- float
math_asinh(x) → {float}
Return the inverse hyperbolic sine of
x.
Parameters:
| Name | Type | Description |
|---|---|---|
|
int | float | The number for which to compute the inverse hyperbolic sine. |
Returns:
the inverse hyperbolic sine of
x
- Type
- float
math_atan(x) → {float}
Return the arc tangent of
x, in radians. The result is between -pi/2 and pi/2.
Parameters:
| Name | Type | Description |
|---|---|---|
|
int | float | The value whose arc tangent is to be computed. |
Returns:
the arc tangent of
x in radians
- Type
- float
math_atan2(y, x) → {float}
Return
atan(y / x), in radians.
Parameters:
| Name | Type | Description |
|---|---|---|
|
int | float | The y-coordinate of the point. |
|
int | float | The x-coordinate of the point. |
Returns:
the arc tangent of
y/x in radians
- Type
- float
math_atanh(x) → {float}
Return the inverse hyperbolic tangent of
x.
Parameters:
| Name | Type | Description |
|---|---|---|
|
int | float | The number for which to compute the inverse hyperbolic tangent.
(Must be in the interval (-1, 1).) |
Returns:
the inverse hyperbolic tangent of
x
- Type
- float
math_cbrt(x) → {float}
Return the cube root of
x.
Parameters:
| Name | Type | Description |
|---|---|---|
|
int | float | The numeric value for which to compute the cube root. |
Returns:
the cube root of
x
- Type
- float
math_ceil(x) → {int}
Return the ceiling of
x, the smallest integer greater than or equal to
x.
Parameters:
| Name | Type | Description |
|---|---|---|
|
int | float | The numeric value for which to compute the ceiling. |
Returns:
the ceiling of
x
- Type
- int
math_comb(n, k) → {int}
Return the number of ways to choose
k items from n items
without repetition and without order.
Returns zero when k > n.
Parameters:
| Name | Type | Description |
|---|---|---|
|
int | Total number of items (must be a non-negative integer). |
|
int | Number of items to choose (must be a non-negative integer). |
Returns:
the binomial coefficient of
n and k
- Type
- int
math_copysign(x, y) → {float}
Return a
float with the magnitude (absolute value) of x
but the sign of y.
Parameters:
| Name | Type | Description |
|---|---|---|
|
int | float | The value whose magnitude (absolute value) will be used. |
|
int | float | The value whose sign will be applied to x's magnitude. |
Returns:
a
float with the absolute value of x but with the sign of
y
- Type
- float
math_cos(x) → {float}
Return the cosine of
x radians.
Parameters:
| Name | Type | Description |
|---|---|---|
|
int | float | The angle in radians for which the cosine is computed. |
Returns:
the cosine of
x
- Type
- float
math_cosh(x) → {float}
Return the hyperbolic cosine of
x.
Parameters:
| Name | Type | Description |
|---|---|---|
|
int | float | The angle in radians for which to compute cosh(x). |
Returns:
the hyperbolic cosine of
x
- Type
- float
math_degrees(x) → {float}
Convert angle
x from radians to degrees.
Parameters:
| Name | Type | Description |
|---|---|---|
|
int | float | The angle in radians to be converted to degrees. |
Returns:
the angle, in degrees, corresponding to the given radians
- Type
- float
math_erf(x) → {float}
Return the error function at
x.
Parameters:
| Name | Type | Description |
|---|---|---|
|
int | float | The value at which to evaluate the error function. |
Returns:
the error function value at
x
- Type
- float
math_erfc(x) → {float}
Return the complementary error function at
x. The complementary error function is
defined as 1.0 - erf(x). It is used for large values of x where a subtraction
from one would cause a loss of significance.
Parameters:
| Name | Type | Description |
|---|---|---|
|
int | float | The value at which to evaluate the complementary error function. |
Returns:
the complementary error function at
x
- Type
- float
math_exp(x) → {float}
Return
e raised to the power x, where e = 2.718281…
is the base of natural logarithms.
Parameters:
| Name | Type | Description |
|---|---|---|
|
int | float | The exponent for which to compute e^x. |
Returns:
the value of
e raised to the power x with high accuracy
- Type
- float
math_exp2(x) → {float}
Return
2 raised to the power x.
Parameters:
| Name | Type | Description |
|---|---|---|
|
int | float | The exponent for which to compute 2^x. |
Returns:
the value of
2 raised to the power x with high accuracy
- Type
- float
math_expm1(x) → {float}
Return
e raised to the power x, minus 1. Here e is
the base of natural logarithms. For small x, the subtraction in
exp(x) - 1 can result in a significant loss of precision; the expm1() function
provides a way to compute this quantity to full precision.
Parameters:
| Name | Type | Description |
|---|---|---|
|
int | float | The exponent for which to compute e^x. |
Returns:
the value of
e raised to the power x minus 1 with high accuracy
- Type
- float
math_fabs(x) → {float}
Return the absolute value of a number as a float.
Unlike the built-in
abs(), math_fabs() always returns a float,
even when the input is an integer.
It only accepts int or float types (complex numbers are not supported).
Parameters:
| Name | Type | Description |
|---|---|---|
|
int | float | The number whose absolute value is computed. |
Returns:
absolute value of
x
- Type
- float
math_factorial(n) → {int}
Return
n factorial as an integer.
Parameters:
| Name | Type | Description |
|---|---|---|
|
int | A non-negative integer whose factorial is to be computed. |
Returns:
the factorial of
n
- Type
- int
math_floor(x) → {int}
Return the floor of
x, the largest integer less than or equal to
x.
Parameters:
| Name | Type | Description |
|---|---|---|
|
int | float | The numeric value for which to compute the flooring. |
Returns:
the flooring of
x
- Type
- int
math_fma(x, y, z) → {float}
Fused multiply–add operation. Return
(x * y) + z, computed as though with infinite
precision and range followed by a single round to the float format.
This operation often provides better accuracy than the direct expression
(x * y) + z.
This function follows the specification of the
(fusedMultiplyAdd) operation described in the IEEE 754 standard.
The standard leaves one case implementation-defined, namely the result of
fma(0, inf, nan) and fma(inf, 0, nan).
In these cases, math.fma returns a math.nan, and does not raise any exception.
Parameters:
| Name | Type | Description |
|---|---|---|
|
int | float | The first multiplicand. It is multiplied by y. |
|
int | float | The second multiplicand. It is multiplied by x. |
|
int | float | The addend. The product of x and y
is added to z using a fused multiply–add operation. |
Returns:
the float value of
(x * y) + z
- Type
- float
math_fmod(x, y) → {float}
Return the floating-point remainder of
x / y, as defined by the
platform C library function fmod(x, y). The sign of the result is the same as the
sign of x.
Parameters:
| Name | Type | Description |
|---|---|---|
|
int | float | The dividend. It will be converted to a float
if necessary. |
|
int | float | The divisor. It will be converted to a float
if necessary. |
Returns:
the platform C library function
fmod(x, y) style remainder of
x divided by y
- Type
- float
math_gamma(x) → {float}
Return the Gamma function at
x.
Parameters:
| Name | Type | Description |
|---|---|---|
|
int | float | The input value at which the Gamma function is computed. |
Returns:
the Gamma function at
x
- Type
- float
math_gcd(*integers) → {int}
Return the greatest common divisor of the specified
*integers arguments.
If any of the arguments is nonzero, then the returned value is the largest positive
integer that is a divisor of all arguments.
If all arguments are 0, then the returned value is 0.
gcd() without arguments returns 0.
If any of the provided integers is negative, the function treats it as its
absolute value when computing the GCD.
Parameters:
| Name | Type | Description |
|---|---|---|
|
int | A variable number of integer arguments for which to compute the greatest common divisor. |
Returns:
the greatest common divisor of the given
integers as a positive
integer
- Type
- int
math_isfinite(x) → {bool}
Return
True if x is neither an infinity nor a nan,
and False otherwise.
Parameters:
| Name | Type | Description |
|---|---|---|
|
int | float | A numeric value. It is converted to float if necessary. |
Returns:
the
True if x is finite; otherwise, False
- Type
- bool
math_isinf(x) → {bool}
Return
True if x is a positive or negative infinity,
and False otherwise.
Parameters:
| Name | Type | Description |
|---|---|---|
|
int | float | A numeric value. It is converted to float if necessary. |
Returns:
the
True if x is an infinity (positive or negative);
otherwise, False
- Type
- bool
math_isnan(x) → {bool}
Return
True if x is a nan (not a number),
and False otherwise.
Parameters:
| Name | Type | Description |
|---|---|---|
|
int | float | A numeric value. It is converted to float if necessary. |
Returns:
the
True if x is nan; otherwise, False
- Type
- bool
math_isqrt(n) → {int}
Return the integer square root of the non-negative
n.
Parameters:
| Name | Type | Description |
|---|---|---|
|
int | A non-negative integer for which to compute the integer square root. |
Returns:
the integer square root of
n
- Type
- int
math_lcm(*integers) → {int}
Return the least common multiple of the specified integer arguments.
If all arguments are nonzero, then the returned value is the smallest positive
integer that is a multiple of all arguments.
If any of the arguments is
0, then the returned value is 0.
lcm() without arguments returns 1.
If any of the input integers is negative, math_lcm() treats it
as its absolute value when computing the LCM, so the result is always
non-negative.
Parameters:
| Name | Type | Description |
|---|---|---|
|
int | A variable number of integer arguments for which the least common multiple is computed. |
Returns:
the least common multiple of the given integers as a positive
integer
- Type
- int
math_ldexp(x, i) → {float}
Return
x * (2**i). This is essentially the inverse of function
frexp().
Parameters:
| Name | Type | Description |
|---|---|---|
|
int | float | A numeric value (the significand). It is converted to
float if necessary. |
|
int | An integer exponent. |
Returns:
the result of
x multiplied by 2 raised to the power
i
- Type
- float
math_lgamma(x) → {float}
Return the natural logarithm of the absolute value of the Gamma function at
x.
Parameters:
| Name | Type | Description |
|---|---|---|
|
int | float | The input value for which to compute the natural logarithm of the absolute Gamma function. |
Returns:
the natural logarithm of the absolute value of the Gamma function at
x
- Type
- float
math_log(x, base(optional)) → {float}
With one argument, return the natural logarithm of
x (to base e).
With two arguments, return the logarithm of x to the given base,
calculated as log(x)/log(base).
Parameters:
| Name | Type | Description |
|---|---|---|
|
int | float | The numeric value for which to compute the logarithm. |
|
int | float | The base of the logarithm. If provided, the result is computed as
log(x)/log(base). If omitted, the natural logarithm (base e) is returned. |
Returns:
a float representing the logarithm of
x (either natural logarithm when
base is not provided, or logarithm with the given base otherwise)
- Type
- float
math_log10(x) → {float}
Return the base-10 logarithm of
x. This is usually more accurate than
log(x, 10).
Parameters:
| Name | Type | Description |
|---|---|---|
|
int | float | A positive number. The function returns the logarithm of
x to base 10. |
Returns:
the base-10 logarithm of
x
- Type
- float
math_log1p(x) → {float}
Return the natural logarithm of
1+x (base e). The result is calculated in a way
which is accurate for x near 0.
Parameters:
| Name | Type | Description |
|---|---|---|
|
int | float | The number to be added to 1. The function returns the natural
logarithm of (1+x), computed in a way that is accurate for values of x near 0. |
Returns:
the natural logarithm of
1+x (base e)
- Type
- float
math_log2(x) → {float}
Return the base-2 logarithm of
x. This is usually more accurate than
log(x, 2).
Parameters:
| Name | Type | Description |
|---|---|---|
|
int | float | A positive number. The function returns the logarithm of
x to base 2. |
Returns:
the base-2 logarithm of
x
- Type
- float
math_nextafter(x, y, steps) → {float}
Return the floating-point value
steps steps after x towards
y. If x is equal to y, return y, unless
steps is 0.
Parameters:
| Name | Type | Description |
|---|---|---|
|
int | float | The starting floating-point number from which the stepping begins. |
|
int | float | The target value that determines the direction. The function will
return a value toward y from x. |
|
int | The number of representable floating-point values to step from
x toward y (default is 1). |
Returns:
the floating-point number that is exactly
steps representable numbers
away from x in the direction of y
- Type
- float
math_perm(n, k) → {int}
Return the number of ways to choose
k items from n items without
repetition and with order.
Returns zero when k > n.
Parameters:
| Name | Type | Description |
|---|---|---|
|
int | Total number of items (must be a non-negative integer). |
|
int | Number of items to choose (must be a non-negative integer). |
Returns:
the permutations of
n and k
- Type
- int
math_pow(x, y) → {float}
Return
x raised to the power y. Unlike the built-in
** operator, math_pow() converts both its arguments to type float.
Parameters:
| Name | Type | Description |
|---|---|---|
|
int | float | The base value. Both x and y are converted
to float before the operation. |
|
int | float | The exponent value. The function computes x raised to the power
y, following IEEE 754 rules for special cases. |
Returns:
the value of
x raised to the power y
- Type
- float
math_radians(x) → {float}
Convert angle
x from degrees to radians.
Parameters:
| Name | Type | Description |
|---|---|---|
|
int | float | The angle in degrees to be converted to radians. |
Returns:
the angle, in radians, corresponding to the given degrees
- Type
- float
math_remainder(x, y) → {float}
Return the IEEE 754-style remainder of
x with respect to y. For finite
x and finite nonzero y, this is the difference x - n*y, where
n is the closest integer to the exact value of the quotient x / y.
If x / y is exactly halfway between two consecutive integers, the nearest
even integer is used for n. The remainder r = remainder(x, y)
thus always satisfies abs(r) <= 0.5 * abs(y).
Parameters:
| Name | Type | Description |
|---|---|---|
|
int | float | The dividend. It will be converted to a float
if necessary. |
|
int | float | The divisor. It will be converted to a float
if necessary. |
Returns:
the IEEE 754-style remainder of
x divided by y
- Type
- float
math_sin(x) → {float}
Return the sine of
x radians.
Parameters:
| Name | Type | Description |
|---|---|---|
|
int | float | The angle in radians for which the sine is computed. |
Returns:
the sine of
x
- Type
- float
math_sinh(x) → {float}
Return the hyperbolic sine of
x.
Parameters:
| Name | Type | Description |
|---|---|---|
|
int | float | The angle in radians for which to compute sinh(x). |
Returns:
the hyperbolic sine of
x
- Type
- float
math_sqrt(x) → {float}
Return the square root of
x.
Parameters:
| Name | Type | Description |
|---|---|---|
|
int | float | A non-negative number. x is converted to a float
if necessary. |
Returns:
the square root of
x
- Type
- float
math_tan(x) → {float}
Return the tangent of
x radians.
Parameters:
| Name | Type | Description |
|---|---|---|
|
int | float | The angle in radians for which the tangent is computed. |
Returns:
the tangent of
x
- Type
- float
math_tanh(x) → {float}
Return the hyperbolic tangent of
x.
Parameters:
| Name | Type | Description |
|---|---|---|
|
int | float | The angle in radians for which to compute tanh(x). |
Returns:
the hyperbolic tangent of
x
- Type
- float
math_trunc(x) → {int}
Return
x with the fractional part removed, leaving the integer part.
trunc() is equivalent to floor() for positive x, and equivalent
to ceil() for negative x.
Parameters:
| Name | Type | Description |
|---|---|---|
|
int | float | The numeric value from which the fractional part is removed,
returning the integral part (i.e. x rounded toward 0). |
Returns:
the integer part of
x
- Type
- int
math_ulp(x) → {float}
Return the value of the least significant bit of the
float x.
If x is a NaN (not a number), return x.
If x is negative, return ulp(-x).
If x is a positive infinity, return x.
If x is equal to 0, return the smallest positive denormalized
representable float (smaller than the minimum positive normalized float,
sys.float_info.min, approximately 1.7976931348623157e+308).
If x is equal to the largest positive representable float, return the value
of the least significant bit of x, such that the first float smaller than
x is x - ulp(x).
Otherwise (when x is a positive finite number), return the value of the least significant
bit of x, such that the first float bigger than x is
x + ulp(x).
Parameters:
| Name | Type | Description |
|---|---|---|
|
int | float | The numeric value (typically a float) for which to compute
the ULP (Unit in the Last Place). The function returns the value of the least significant
bit of x, handling special cases (NaN, infinities, 0, etc.)
as specified by IEEE 754. |
Returns:
the spacing between
x and the next representable float in the
direction defined by x's sign
- Type
- float