Why can i compare 2 floats ?
if float a==float b print equal
Typically this is due to the limits of numeric accuracy. For example,
in math class, 1.0 = .9999999(repeating), but in any finite
representation, these would be different. And since computers use
binary, even numbers like 1/5 have representations with repeating
decimals. So basically, a small round-off error or something like that
will get you.
The way you solve this is:
#include <math.h>
const double THRESHOLD = 1e-10; // or pick some other small value
if (fabs(a - b) < THRESHOLD) {
print equal;
}