title: Shannon's Entropy Algorithm Returning negative values
body: <p>note: project is in C, not C++</p>
  <pre><code>float entr = 0;
  for(int i = 0; i &lt; map-&gt;entry_count; ++i)
  {
      float x = (float)map-&gt;entry[i].occ / map-&gt;entry_count;
      if(x &gt; 0)
      {
          entr -= x * log(x) / log(2);
      }
  }
  return entr;
  </code></pre>
  <p>when my map has 3 occurences of value 15, the entropy returned is -4.214.. something</p>
  <p>when my map has 3 occurences of value 15 and one occurence of value 25, the entropy returned is 0.000</p>
  <p>something is clearly wrong here. i don't really understand the maths behind it, so i got the algorithm off the internet, but i'd really like to get it to work.</p>
  <p>BTW, the map is written by me. i cannot provide the code (it's for production), but:</p>
  <ul>
  <li>occ = the number of occurences for a single value</li>
  <li>entry_count = the number of values in the map. it does not increase when occurences increase, it increases when a new value is added</li>
  </ul>
  <p>so basically it works just like a C++ map, to my knowledge</p>