Pedantic note: Code::Blocks isn't a compiler, so the "weird logic" isn't within it, but within whatever compiler you're using (probably gcc/g++).
With the version of g++ in my installation (4.8.4), I can replicate the problem by compiling without any optimisation. Using any of the -O options results in the expected output.
Here's the full output of g++ --version
on my system:
g++ (i686-posix-sjlj-rev0, Built by MinGW-W64 project) 4.8.4
The following version of g++ gives the expected output, regardless of the optimisation setting:
g++ (Debian 4.9.2-10) 4.9.2
So: you could see if you can upgrade the compiler which may result in different behaviour, or always compile with at least -O. In Code::Blocks this is listed under Compiler settings, Compiler flags, Optimization options, as "Optimize generated code (for speed)". Any of the optimization levels appear to give the desired output, even optimising for size instead of speed.
Also, as user4581301 commented, you normally want to avoid performing exact equality tests on floating point numbers, but instead test if the value lies within a specific range. Or, explicitly cast the result to an integer type before the comparison as Humam Helfawi suggests. Even though the optimisation setting seems to "fix" this particular case, there may be others that it doesn't, or for which the unoptimized code produces the desired result but the optimized code does not.