What do you think works faster on a modern machine:
int i(-1);
i *= 2 * (i > 0) - 1;
or
int i(-1);
if (i < 0)
{
i = -i;
}
What do you think works faster on a modern machine:
int i(-1);
i *= 2 * (i > 0) - 1;
or
int i(-1);
if (i < 0)
{
i = -i;
}
abs
lower code…coz cnsisi f less no. f i.e. 0 milt. opereations…which consumes much f the process. time
Hehe, std::abs() from <cstdlib> is better than all of them I think.