+ 1

9**19 == int(float(9**19)).....? And why??

Python

22nd Mar 2017, 4:51 PM
MZ Minhaz
MZ Minhaz - avatar
4 ответов
+ 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.
22nd Mar 2017, 5:30 PM
Álvaro
+ 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
22nd Mar 2017, 5:42 PM
Álvaro
+ 1
oh...thank u...so much
22nd Mar 2017, 5:49 PM
MZ Minhaz
MZ Minhaz - avatar
0
thank you. but print(9**15 == int(float(9**15))) # True. why?
22nd Mar 2017, 5:33 PM
MZ Minhaz
MZ Minhaz - avatar