14. Mathematics

This chapter describes modules for performing various kinds of mathematical operations. In addition, the decimal module, which provides generalized support for decimal floating-point numbers, is described.

decimal

The Python float data type is represented using a double-precision binary floating-point encoding (usually as defined by the IEEE 754 standard). A subtle consequence of this encoding is that decimal values such as 0.1 can’t be represented exactly. Instead, the closest value is 0.10000000000000001. This inexactness carries over to calculations involving floating-point numbers and can sometimes lead to unexpected results (for example, 3*0.1 == 0.3 evaluates as False).

The decimal module provides an implementation of ...

Get Python: Essential Reference now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.