Reputation: 873
I know I can define infinity as float("inf"). but I am more interested in its actual implementation. float("inf") surely does not return a number. But normal arithmetic comparison can be done on it. How?
Upvotes: 4
Views: 200
Reputation: 280456
Floating-point infinity is defined by the IEEE 754 floating-point standard. As far as the processor cares, it's a number. It's represented by a bit pattern with all exponent bits set to 1
, all bits in the significand set to 0
, and the sign bit corresponding to the sign of the infinity. The floating-point circuitry in your CPU recognizes this bit pattern and understands what to do with infinity or negative infinity as operands. For most operators, this is probably done with special cases for infinity in the circuitry.
Upvotes: 6