March 3, 2022
5:20 p.m.
Hi Yi-Ming Chang,
I have searched online, they said this is binary float, but I am not is this an error in Python? Or there is a way to avoid it?
This is not a bug in Python, this is Python delegating the computation to your CPU, and it's not even an error from your CPU, it's a limitation in the binary representation used for the float numbers, like we have limitations to represent some values in our base 10 system (try to write 10/3 for example). To learn more about it: https://docs.python.org/3/tutorial/floatingpoint.html and https://0.30000000000000004.com/ If you really need more precision, you can use the Decimal module: https://docs.python.org/3/library/decimal.html Bests, -- Julien Palard https://mdk.fr