The Devil in the Decimals

The problem is that, as much as math.sqrt(5) looks an awful lot like 5\sqrt{5}, it isn't. It's the closest thing you can get to that using 64 bits of information, writing it as a binary value.1 Specifically, Python floats are represented as a binary decimal with 532 significant base-2 digits. That's roughly equivalent to 16 significant base-10 digits. ϕ71\phi^{71} is 50 bits, and so the computer simply runs out of room and ends up misrounding the output.

Well, the simple solution here is to find a way of using more decimal places. Let's check it out.


  1. Floating point numbers are a very complicated subject. Try this as an introduction.
  2. Technically this isn't a part of Python but is rather an implenentation choice, but it seems pretty much universal to have it be a 64-bit float.
Code
Output
False

The Devil in the Decimals

The problem is that, as much as math.sqrt(5) looks an awful lot like 5\sqrt{5}, it isn't. It's the closest thing you can get to that using 64 bits of information, writing it as a binary value.1 Specifically, Python floats are represented as a binary decimal with 532 significant base-2 digits. That's roughly equivalent to 16 significant base-10 digits. ϕ71\phi^{71} is 50 bits, and so the computer simply runs out of room and ends up misrounding the output.

Well, the simple solution here is to find a way of using more decimal places. Let's check it out.


  1. Floating point numbers are a very complicated subject. Try this as an introduction.
  2. Technically this isn't a part of Python but is rather an implenentation choice, but it seems pretty much universal to have it be a 64-bit float.
Code
Output
False