PDA

View Full Version : strange thing



ugluk
07-12-2010, 04:02 AM
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;
}

tanzanite
07-12-2010, 04:28 AM
abs

maverick00
07-12-2010, 07:11 AM
lower code...coz cnsisi f less no. f i.e. 0 milt. opereations....which consumes much f the process. time

ugluk
07-12-2010, 09:33 PM
Hehe, std::abs() from <cstdlib> is better than all of them I think.