If an integer is uneven (odd), I would like to get the previous number, otherwise I would like to keep the current number. E.g. if x = 3
, I would like to assign 2
to x
, if x = 4
, then nothing happens.
At the moment, I do the following: x = (x/2)*2
, but I have heard that division is computational expensive. Does -O3
optimize this expression? I am using the c++ (Ubuntu 4.8.4-2ubuntu1~14.04) 4.8.4
compiler. x
is a uint32_t
.