Overflow and Truncation in Floating Point Types
This lesson explains how overflow and truncation affects floating point types.
We'll cover the following
Overflow is not ignored #
Despite being able to take very large values, floating point types are prone to overflow as well. Nevertheless, floating point types are safer than integer types in this regard because overflow is not ignored. The values that overflow on the positive side become .infinity, and the values that overflow on the negative side become ‐.infinity. To see this, let’s increase the value of .max
by 10%, which is equivalent to multiplying by 1.1. Since the value is already at its maximum, increasing by 10% would overflow:
Get hands-on with 1400+ tech skills courses.