This is the documentation for the latest development branch of MicroPython and may refer to features that are not available in released versions.

If you are looking for the documentation for a specific release, use the drop-down menu on the left and select the desired version.

math – Mathematical functions.

Mathematical functions.

This module implements a subset of the corresponding CPython module, as described below. For more information, refer to the original CPython documentation: math.

The math module provides some basic mathematical functions for working with floating-point numbers.

Note: On the pyboard, floating-point numbers have 32-bit precision.

Availability: not available on WiPy. Floating point support required for this module.

Attributes

e

base of the natural logarithm

pi

the ratio of a circle's circumference to its diameter

Functions

acos(→ float)

Return the inverse cosine of x.

acosh(→ float)

Return the inverse hyperbolic cosine of x.

asin(→ float)

Return the inverse sine of x.

asinh(→ float)

Return the inverse hyperbolic sine of x.

atan(→ float)

Return the inverse tangent of x.

atan2(→ float)

Return the principal value of the inverse tangent of y/x.

atanh(→ float)

Return the inverse hyperbolic tangent of x.

ceil(→ int)

Return an integer, being x rounded towards positive infinity.

copysign(→ _typeshed.Incomplete)

Return x with the sign of y.

cos(→ float)

Return the cosine of x.

cosh(→ float)

Return the hyperbolic cosine of x.

degrees(→ _typeshed.Incomplete)

Return radians x converted to degrees.

erf(→ _typeshed.Incomplete)

Return the error function of x.

erfc(→ _typeshed.Incomplete)

Return the complementary error function of x.

exp(→ float)

Return the exponential of x.

expm1(→ _typeshed.Incomplete)

Return exp(x) - 1.

fabs(→ _typeshed.Incomplete)

Return the absolute value of x.

floor(→ int)

Return an integer, being x rounded towards negative infinity.

fmod(→ _typeshed.Incomplete)

Return the remainder of x/y.

frexp(→ _typeshed.Incomplete)

Decomposes a floating-point number into its mantissa and exponent.

gamma(→ _typeshed.Incomplete)

Return the gamma function of x.

isfinite(→ bool)

Return True if x is finite.

isinf(→ bool)

Return True if x is infinite.

isnan(→ bool)

Return True if x is not-a-number

ldexp(→ _typeshed.Incomplete)

Return x * (2**exp).

lgamma(→ float)

Return the natural logarithm of the gamma function of x.

log(→ float)

Return the natural logarithm of x.

log10(→ float)

Return the base-10 logarithm of x.

log2(→ float)

Return the base-2 logarithm of x.

modf(→ Tuple)

Return a tuple of two floats, being the fractional and integral parts of

pow(→ _typeshed.Incomplete)

Returns x to the power of y.

radians(→ _typeshed.Incomplete)

Return degrees x converted to radians.

sin(→ float)

Return the sine of x.

sinh(→ float)

Return the hyperbolic sine of x.

sqrt(→ _typeshed.Incomplete)

Return the square root of x.

tan(→ float)

Return the tangent of x.

tanh(→ float)

Return the hyperbolic tangent of x.

trunc(→ int)

Return an integer, being x rounded towards 0.

Module Contents

math.acos(x) float

Return the inverse cosine of x.

math.acosh(x) float

Return the inverse hyperbolic cosine of x.

math.asin(x) float

Return the inverse sine of x.

math.asinh(x) float

Return the inverse hyperbolic sine of x.

math.atan(x) float

Return the inverse tangent of x.

math.atan2(y, x) float

Return the principal value of the inverse tangent of y/x.

math.atanh(x) float

Return the inverse hyperbolic tangent of x.

math.ceil(x) int

Return an integer, being x rounded towards positive infinity.

math.copysign(x, y) Incomplete

Return x with the sign of y.

math.cos(x) float

Return the cosine of x.

math.cosh(x) float

Return the hyperbolic cosine of x.

math.degrees(x) Incomplete

Return radians x converted to degrees.

math.erf(x) Incomplete

Return the error function of x.

math.erfc(x) Incomplete

Return the complementary error function of x.

math.exp(x) float

Return the exponential of x.

math.expm1(x) Incomplete

Return exp(x) - 1.

math.fabs(x) Incomplete

Return the absolute value of x.

math.floor(x) int

Return an integer, being x rounded towards negative infinity.

math.fmod(x, y) Incomplete

Return the remainder of x/y.

math.frexp(x) Incomplete

Decomposes a floating-point number into its mantissa and exponent. The returned value is the tuple (m, e) such that x == m * 2**e exactly. If x == 0 then the function returns (0.0, 0), otherwise the relation 0.5 <= abs(m) < 1 holds.

math.gamma(x) Incomplete

Return the gamma function of x.

math.isfinite(x) bool

Return True if x is finite.

math.isinf(x) bool

Return True if x is infinite.

math.isnan(x) bool

Return True if x is not-a-number

math.ldexp(x, exp) Incomplete

Return x * (2**exp).

math.lgamma(x) float

Return the natural logarithm of the gamma function of x.

math.log(x) float

Return the natural logarithm of x.

math.log10(x) float

Return the base-10 logarithm of x.

math.log2(x) float

Return the base-2 logarithm of x.

math.modf(x) Tuple

Return a tuple of two floats, being the fractional and integral parts of x. Both return values have the same sign as x.

math.pow(x, y) Incomplete

Returns x to the power of y.

math.radians(x) Incomplete

Return degrees x converted to radians.

math.sin(x) float

Return the sine of x.

math.sinh(x) float

Return the hyperbolic sine of x.

math.sqrt(x) Incomplete

Return the square root of x.

math.tan(x) float

Return the tangent of x.

math.tanh(x) float

Return the hyperbolic tangent of x.

math.trunc(x) int

Return an integer, being x rounded towards 0.

math.e: float

base of the natural logarithm

math.pi: float

the ratio of a circle’s circumference to its diameter