title: Python and very small decimals
body: <p>Interesting fact on Python 2.7.6 running on macosx:</p>
  
  <p>You have a very small number like:</p>
  
  <pre><code>0.000000000000000000001
  </code></pre>
  
  <p>You can represent it as:</p>
  
  <pre><code>&gt;&gt;&gt; 0.1 / (10 ** 20)
  1.0000000000000001e-21
  </code></pre>
  
  <p>But you can see the floating pointing error at the end. What we <em>really</em> have is something like this:</p>
  
  <pre><code>0.0000000000000000000010000000000000001
  </code></pre>
  
  <p>So we got an error in the number, but thats ok. The problem is the following:</p>
  
  <p>As expected:</p>
  
  <pre><code>&gt;&gt;&gt; 0.1 / (10 ** 20) == 0
  False
  </code></pre>
  
  <p>But, wait, whats this?</p>
  
  <pre><code>&gt;&gt;&gt; 0.1 / (10 ** 20) + 1 == 1
  True
  
  &gt;&gt;&gt; repr(0.1 / (10 ** 20) + 1)
  '1.0'
  </code></pre>
  
  <p>Looks like python is using another data type to represent my number as this only happens when using the 16th decimal digit and so on. Also why python decided to automatically turn my number to <code>0</code> on the addition? Should not I be dealing with a decimal number with a very small decimal part and with a floating point error?</p>
  
  <p>I know this problem can fall in the <em>floating point errors</em> umbrella, and the solution normally is do not trust floating point for this kinda of calculation, but I would like to understand more about whats happening under the hood.</p>