Reputation: 1618
Can someone explain me why x and y give completely different results?
>>> x=int(5) * 1e50
>>> x
5e+50
>>> y=int(5e50)
>>> y
499999999999999996610474337180813988230854220972032
The python manual says that integer can be of arbitrary length regardless the available memory, x and y as I known are integers but the result is completely different but are equivalent expressions, is 5e50 interpreted as float before int conversion? If so, why?
Upvotes: 0
Views: 172
Reputation: 1996
int(5) is an int, 1e50 is a float. If you multiply them, the int(5) will be converted to the larger type (which is a float) and then multiplied with 1e50. The result is of type float, not int.
int(5e50) converts the float to an int and is therefore printed as an integer of, as you say, arbitrary length.
Upvotes: 1