title: int((0.1+0.7)*10) = 7 in several languages. How to prevent this?
body: <p>Recently I came across a bug/feature in several languages. I have a very basic knowledge about how it's caused (and I'd like some detailed explanation), but when I think of all the bugs I must have made over the years, the question is how can I determine "<strong><em>Hey, this might cause a riddiculous bug, I'd better use arbitrary precision functions</em></strong>", what other languages do have this bug (and those who don't, <strong>why</strong>). Also, why 0.1+0.7 does this and i.e. 0.1+0.3 doesn't, are there any other well-known examples?</p>
  
  <p>PHP </p>
  
  <pre><code>//the first one actually doesn't make any sense to me,
  //why 7 after typecast if it's represented internally as 8?
  debug_zval_dump((0.1+0.7)*10); //double(8) refcount(1)
  debug_zval_dump((int)((0.1+0.7)*10)); //long(7) refcount(1)
  debug_zval_dump((float)((0.1+0.7)*10)); //double(8) refcount(1)
  </code></pre>
  
  <p>Python:</p>
  
  <pre><code>&gt;&gt;&gt; ((0.1+0.7)*10)
  7.9999999999999991
  &gt;&gt;&gt; int((0.1+0.7)*10)
  7
  </code></pre>
  
  <p>Javascript:</p>
  
  <pre><code>alert((0.1+0.7)*10); //7.999999999999999
  alert(parseInt((0.7+0.1)*10)); //7
  </code></pre>
  
  <p>Ruby:</p>
  
  <pre><code>&gt;&gt; ((0.1+0.7)*10).to_i                                                  
  =&gt; 7                                                                    
  &gt;&gt;((0.1+0.7)*10)                                                       
  =&gt; 7.999999999999999                                                    
  </code></pre>