If I have something like this:
double a = 1.0f;
double b = 1.0f;
double c = 1.0f;
double d = 1.0f;
a /= 3.0f; // 0.3333...
b /= 3.0f;
c /= 3.0f;
if ((a+b+c) == 1)
puts("sum equals 1");
if (3*a == 1)
puts("product equals 1");
if (d == 1)
puts("d equals 1");
Unsurprisingly, only the 3rd one executes. Is there a simple way to execute a code if a sum of some independent variables equals exactly 1?
Edit: I really know why (1/3.0) + (1/3.0) + (1/3.0) is not 1. But I didn't know another way to ask it.