Nov 10, 2012

Coding smarter

1. Avoiding if else by max of min:
    e.g., if (x-CONST_1 < 0) y = CONST_2 else y = x-CONST_1
    => max(1,x-CONST_1)
   condition  CONST_2 > x-CONST_1

   e.g., if (x+CONST_1 > CONST_3) y = CONST_4 else y = x+CONST_1
    => min(CONST_4,x+CONST_1)
   condition  CONST_4 < x+CONST_1

2. 




No comments:

Down with the Dictatorship!

    "Let them hate me, so that they fear me" - Caligula 41AD