Mathematics and precise calculations
Python has a decent number of mathematical functions and features built in, but there are cases where you need more advanced features or something faster. In this section, we will discuss a few libraries that help by introducing many extra mathematical functions and/or increase mathematical precision and/or performance quite a bit.
First, let’s discuss the options in the Python core libraries to store numbers and perform calculations with varying precision:
int
: To store whole numbers (e.g.1, 2, 3
), we have theint
object in Python. Theint
is directly translated into a Cint64
on most systems as long as it can fit within 64-bit. Outside of that, it is internally cast to a Pythonlong
type (not to be confused with a Clong
), which can be arbitrarily large. This allows for infinite accuracy but only works as long as you use whole numbers.fractions.Fraction
: TheFraction
object makes it possible to store fractional numbers...