While working on an issue, I stumbled at something I cannot really undestand on my own.
I have a variable:
a = pow(2, 1024)
Its type is long int. If I try casting it explicitly to float, like float(a), I receive OverflowError. The number is too big to fit in 64bit float, so it's understandable.
Then I try implicit cast, through mutliplying it by a float number:
b = a * 11.0
Once again, the OverflowError occurs, which is fine, because according to python docs, implicit conversion from long int to float happens. So the result is like before.
Finally, I try comparison:
a > 11.0
returns True. The OverflowError doesn't occur. And that confuses me a lot. How does the Python comparison mechanism work, if it doesn't require numerics to be in the same format? Accordind to this,
Python fully supports mixed arithmetic: when a binary arithmetic operator has operands of different numeric types, the operand with the “narrower” type is widened to that of the other, where plain integer is narrower than long integer is narrower than floating point is narrower than complex. Comparisons between numbers of mixed type use the same rule. The constructors int(), long(), float(), and complex() can be used to produce numbers of a specific type.
My question is, why a is not being cast to float in forementioned comparison?
The version of Python I'm using is 2.7.15. Thanks in an advance