This is due to the IEEE754 floating point format itself, and not to its Python implementation.
Generally speaking, floats can represent smaller negative numbers than larger positives due to denormal numbers . Here, part of the float mantissa is already implicitly supposed to start from 1, but rather describes the entire mantissa and begins with zeros. If you do not know what it is, I would advise you to read about how floats are represented, perhaps starting here .
Because of this, when you invert a denormal number, you may end up in a positive exponent too large to represent. Then the computer issues inf in its place. 1e-308 in your example is actually also denormal, but still not small for overflow when inverting (because among normal numbers, the standard actually allows for slightly more positive than negative indicators).
In the case of 1e-324 this number is simply too small to be represented even as denormal, so float literal is effectively zero. That is why you get division by zero. The smallest 64-bit float represented (just below) is 5e-324 .
source share