title: Lua floating point errors in table index
body: <p>Usually, I compare two floats by seeing if they are within a range of a very small number. It doesn't work for table keys because you do not know if they exist without knowing their key (if that makes sense).</p>
  
  <p>Example with lua 5.1 on a 64 bit computer:</p>
  
  <pre class="lang-lua prettyprint-override"><code>a, b, c = 1.7, -0.8, -0.4
  d = a + b + c -- prevents constant folding
  print(string.format('%1.20f', d)) --  0.49999999999999989000  (around 0.5)
  assert(d ~= 0.5)
  t = {[0] = 'foo', [0.5] = 'bar'}
  print(t[d]) -- nil  (I want it to print 'bar')
  </code></pre>
  
  <p>Basically, how can I find a key in a table while accounting for floating point error? I'd want it to work without a comparison to each key in the table, so it can still be fast with big tables. There's probably already a built-in function to do this, but I could not find one.</p>
  
  <p>Any help would be appreciated!</p>