![[Formales]]
![[module_math__600350770.png]]
[Math - Mathematical Functions](https://docs.python.org/3/library/math.html)<br> From: *Math Library*
> [!TLDR] Mathematical Operations in Python
> The math module offers access to mathematical functions that adhere to the C standard. It does not support operations with complex numbers. For such needs, the cmath module's similarly named functions should be used. This separation exists because many users prefer not to delve deeply into the mathematics of complex numbers. Encountering an error when a complex number is unexpectedly used as an input allows for prompt identification, enabling the programmer to investigate the cause and context of its occurrence.
# Math Methods
## math.fabs(x)
Returns the absolute value of `x` as a float.
```python
import math
math.fabs(-15.2)
# Output: 15.2
```
## math.ceil(x)
Returns the smallest integer not less than `x`.
```python
math.ceil(12.2)
# Output: 13
```
## math.floor(x)
Returns the largest integer not greater than `x`.
```python
math.floor(12.8)
# Output: 12
```
## math.trunc(x)
Returns the integer part of `x` by removing the decimal part.
```python
math.trunc(12.8)
# Output: 12
```
## math.fmod(x, y)
Returns the remainder of `x / y` as a float.
```python
math.fmod(17, 3)
# Output: 2.0
```
## math.frexp(x)
Returns the mantissa and exponent of `x` as the pair `(m, e)` where `x = m * 2**e`.
```python
math.frexp(12.8)
# Output: (0.8, 4)
```
## math.nan
Represents a Not-A-Number (NaN) value.
```python
nan_value = math.nan
nan_value
# Output: nan
```
## math.isnan(x)
Returns `True` if `x` is NaN, otherwise `False`.
```python
math.isnan(nan_value)
# Output: True
```
## math.sqrt(x)
Returns the square root of `x`.
```python
math.sqrt(25)
# Output: 5.0
```
## math.isqrt(n)
Returns the integer square root of `n`.
Equivalent to `int(math.sqrt(n))`.
```python
math.isqrt(20)
# Output: 4
```
## math.pow(x, y)
Returns `x` raised to the power `y`.
```python
math.pow(2, 3)
# Output: 8.0
```
## math.pi
The mathematical constant π (pi).
```python
math.pi
# Output: 3.141592653589793
```
This constant is often used in mathematical calculations involving circles or angles.
## math.e
Eulers number
```python
import math
eul_num = math.e
eul_num = float(f'{math.e:.5f}')
eul_num
# Output: 2.71828
```
# Exercises
[[Math.Storage]]
![[Math.Storage#Overview]]