Python negative threshold, lowest negative number without infinity?

What is python's threshold of representable negative numbers? What's the lowest number by which Python will refer to any other value for a - negative fuzziness?

+3


source to share


1 answer


There is no negative integer as Python integers are arbitrary precision. The smallest float is greater than negative infinity (which depending on your implementation can be represented as -float('inf')

found in sys.float_info

.

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

      



The actual values ​​depend on the actual implementation, but your C library type is usually used double

. Since floating point values ​​usually use the sign bit, the smallest negative value is simply the inverse of the largest positive value. Also, due to the fact that floating point values ​​are stored (separate mantissa and exponent), you cannot simply subtract a small value from the "minimum" value and go back to negative infinity. Subtracting 1, for example, just returns the same value due to limited precision.

(In other words, the possible values float

are a small subset of real real numbers, and operations on two values ​​are float

not necessarily equivalent to the same operation in "equivalent" operations.)

+4


source







All Articles