Bogus float inequality due to compiler optimization? : <p>I found that some straightforward code results in an unexpected (and incorrect) inequality comparison on GCC 4.6.1 vs Visual Studio (2008 &amp; 2012) or Clang 7.3.0 on OSX.</p>

<p>Here's a reduced snippet:</p>

<pre><code>typedef float ftype;
struct Foo
{
    ftype v;

    Foo(): v(16.0f / 60.0f) {}
    ftype val() const {return v * 60.0f;}
};

void bar()
{
    Foo f;
    ftype v = f.val();
    if (v != f.val())
        printf("inequal");
}
</code></pre>

<p>If ftype is typedef'd as double then the problem doesn't occur. Could this be something to do with compiler inlining? Perhaps actually returning a double instead of a float?</p>
