title: Zero minus zero equivalent to infinity?
body: <p>I'm writing a method that creates a copy of an array of arrays of floats. I was getting some extremely weird values after debugging this, so I thought I'd ask about this since I wasn't able to figure this out by reading about C++ array FAQs.</p>
  
  <p>Here's the relevant parts of the code (it's part of an enormous program, with most of the stuff irrelevant for this post):</p>
  
  <pre><code>// height and width are integer global variables
  void method () {
      float testArray[height][width];
      for(int j = 0; j &lt; height; ++j) {
          for(int i = 0; i &lt; width; ++i) {
              testArray[j][i] -= 0.0;
              std::cout &lt;&lt; testArray[j][i] &lt;&lt; std::endl;
          }
      }
  }
  </code></pre>
  
  <p>(In my tests, height = 32 and width = 256, but that shouldn't be relevant.) When I initialize testArray, it's values should all be 0.0, correct? Then, in the loop, I subtract 0.0 from a certain element in testArray, which should logically not change the value at all. But printing the values of testArray as a debugging step result in some weird values, such as the following snippet:</p>
  
  <pre><code>[...]
  0
  [...]
  -3.23805e-24
  [...]
  8.40779e-45
  [...]
  1.79513e+37
  [...]
  0
  [...]
  3.19586e+36
  [...]
  </code></pre>
  
  <p>The most worrisome values are the infinite ones, such as the fourth number listed above. I honestly don't know why this is occurring. Shouldn't all these values still be approximately 0.0? I thought it had to do with imprecision of floating point arithmetic, but that shouldn't result in an infinite value ....</p>