![]() |
![]() |
![]() |
![]() |
![]() |
---|
umath
– Math functions¶
This MicroPython module is similar to the math module in Python.
See also the built-in math functions that can be used without importing anything.
Rounding and sign¶
- ceil(x: float) int ¶
Rounds up.
- Parameters
x – The value
x
.- Returns
Value rounded towards positive infinity.
- floor(x: float) int ¶
Rounds down.
- Parameters
x – The value
x
.- Returns
Value rounded towards negative infinity.
- trunc(x: float) int ¶
Truncates decimals to get the integer part of a value.
This is the same as rounding towards
0
.- Parameters
x – The value
x
.- Returns
Integer part of the value.
- fmod(x: float, y: float) float ¶
Gets the remainder of
x / y
.Not to be confused with
modf()
.- Parameters
x – The numerator.
y – The denominator.
- Returns
Remainder after division
Powers and logarithms¶
- e = 2.718282¶
The mathematical constant e.
- exp(x: float) float ¶
Gets
e
raised to the power ofx
.- Parameters
x – The exponent.
- Returns
e
raised to the power ofx
.
- pow(x: float, y: float) float ¶
Gets
x
raised to the power ofy
.- Parameters
x – The base number.
y – The exponent.
- Returns
x
raised to the power ofy
.
Trigonomety¶
- pi = 3.141593¶
The mathematical constant π.
- degrees(x: float) float ¶
Converts an angle
x
from radians to degrees.- Parameters
x – Angle in radians.
- Returns
Angle in degrees.
- radians(x: float) float ¶
Converts an angle
x
from degrees to radians.- Parameters
x – Angle in degrees.
- Returns
Angle in radians.
- sin(x: float) float ¶
Gets the sine of the given angle
x
.- Parameters
x – Angle in radians.
- Returns
Sine of
x
.
- asin(x: float) float ¶
Applies the inverse sine operation on
x
.- Parameters
x – Opposite / hypotenuse.
- Returns
Arcsine of
x
, in radians.
- cos(x: float) float ¶
Gets the cosine of the given angle
x
.- Parameters
x – Angle in radians.
- Returns
Cosine of
x
.
- acos(x: float) float ¶
Applies the inverse cosine operation on
x
.- Parameters
x – Adjacent / hypotenuse.
- Returns
Arccosine of
x
, in radians.
- tan(x: float) float ¶
Gets the tangent of the given angle
x
.- Parameters
x – Angle in radians.
- Returns
Tangent of
x
.
Other math functions¶
- modf(x: float) Tuple[float, float] ¶
Gets the fractional and integral parts of
x
, both with the same sign asx
.Not to be confused with
fmod()
.- Parameters
x – The value to be decomposed.
- Returns
Tuple of fractional and integral parts.