incorrect output because of bad logic for <=:
x=-1:x<=-0.5=1 x=-0.9:x<=-0.5=1 x=-0.8:x<=-0.5=1 x=-0.7:x<=-0.5=1 x=-0.6:x<=-0.5=1 x=-0.5:x<=-0.5=0 (this should be 1) x=-0.4:x<=-0.5=0 x=-0.3:x<=-0.5=0 x=-0.2:x<=-0.5=0 x=-0.1:x<=-0.5=0 x=5.55112e-017:x<=-0.5=0 x=0.1:x<=-0.5=0 x=0.2:x<=-0.5=0 x=0.3:x<=-0.5=0 x=0.4:x<=-0.5=0 x=0.5:x<=-0.5=0 x=0.6:x<=-0.5=0 x=0.7:x<=-0.5=0 x=0.8:x<=-0.5=0 x=0.9:x<=-0.5=0
Welcome to the world of floating point on a computer.
Oh, and floating point loop conditions are never a good idea.
run this code:
apparently only <= for long double gives wrong results.
you should look carefully before commenting.
You really need to start by understanding how floating point works. You need to realize your code is flawed, right? Don't tell me to look before commenting. I completely understand what has happened in your code. The values you are comparing are INEXACT, leading to rounding and error accumulation.
If you want to see what's really happening, add a setprecision manipulator to the stream:
Do you get it now?
P.S. Close this as yet again NOT A BUG