I created this diagram to display more clearly and objectively the hierarchical distribution of the numerical sets.
As we can observe each numerical set is represented by a certain letter, i.e.:
- N - Set of Natural Numbers;
- Z - Set of numbers Integers;
- Q - Set of Rational Numbers;
- GO - Set of Irrational Numbers;
- R - Set of Real Numbers;
- C - Set of Complex Numbers.
The class math
is specialized to work with numbers belonging to the set of numbers Reais
.
As we can see, the set of numbers Reais
, is a subset of the set of numbers Complexos
, that is, the irrigation used to operate with real numbers is not sufficient to cover operations with complex numbers. So when we want to operate with real numbers we use the class math
.
Already the class cmath
is specialized to work with numbers belonging to the set of complex numbers.
Looking again at the diagram, we can notice that all sets are contained in the set of complex numbers. For this reason, the methods implemented in the class cmath
are much more comprehensive.
What does this mean?
This means that when we import the class math
, we can work with all the numbers except the numbers complexos
. And when we import the class cmath
, we can work with all the numbers without any exception.
It is logical, that to operate with real numbers we do not need to import the class cmath
, because we already have everything we need in class math
.
Now, from the moment we need to work with complex numbers, it’s obvious that we should import the class cmath
.