+ 1
9**19 == int(float(9**19)).....? And why??
4 Respuestas
+ 4
print(9**19)
# 1350851717672992089
print(float(9**19))
# 1.350851717672992e+18
print(int(float(9**19)))
# 1350851717672992000
print(9**19==int(float(9**19)))
# False
The floating point number loses some precision on its less significant digits –this is normal. When casting back to int, the last digits are rounded off.
+ 4
9**15 is "small" enough to fit into a floating point number in Python, in an exact representation and with no need to express it with an approximate mantissa and exponent.
[EDIT] Python can handle "exactly" floating point numbers that can be stored in <=53 bits (in binary format):
https://docs.python.org/2/tutorial/floatingpoint.html
+ 1
oh...thank u...so much
0
thank you. but
print(9**15 == int(float(9**15))) # True.
why?