pythonnumbersthresholdinfinity

python's negative threshold, the lowest non-infinity negative number?


What is python's threshold of representable negative numbers? What's the lowest number below which Python will call any other value a - negative inifinity?


Solution

  • There is no most negative integer, as Python integers have arbitrary precision. The smallest float greater than negative infinity (which, depending on your implementation, can be represented as -float('inf')) can be found in sys.float_info.

    >>> import sys
    >>> sys.float_info.max
    1.7976931348623157e+308
    

    The actual values depend on the actual implementation, but typically uses your C library's double type. Since floating-point values typically use a sign bit, the smallest negative value is simply the inverse of the largest positive value. Also, because of how floating point values are stored (separate mantissa and exponent), you can't simply subtract a small value from the "minimum" value and get back negative infinity. Subtracting 1, for example, simply returns the same value due to limited precision.

    (In other words, the possible float values are a small subset of the actual real numbers, and operations on two float values is not necessarily equivalent to the same operation on the "equivalent" reals.)