<p>What would be the most efficient way to compare two <code>double</code> or two <code>float</code> values?</p>

<p>Simply doing this is not correct:</p>

<pre><code>bool CompareDoubles1 (double A, double B)
{
   return A == B;
}
</code></pre>

<p>But something like:</p>

<pre><code>bool CompareDoubles2 (double A, double B) 
{
   diff = A - B;
   return (diff &lt; EPSILON) &amp;&amp; (-diff &lt; EPSILON);
}
</code></pre>

<p>Seems to waste processing.</p>

<p>Does anyone know a smarter float comparer?</p>

The comparison with an epsilon value is what most people do (even in game programming).
You should change your implementation a little though:
```
```
bool AreSame(double a, double b)
{
    return fabs(a - b) < EPSILON;
}
```
```
Edit: Christer has added a stack of great info on this topic on a
recent blog post
. Enjoy.