KerbalController icon indicating copy to clipboard operation
KerbalController copied to clipboard

pow is 'expensive'

Open hugopeeters opened this issue 7 years ago • 1 comments

Suggestion to use custom function:

int myPow2(int n) // returns 2^n, calculated in integer math
{
  int result = 1;
  if (n = 0) return result;
  else if ( n < 0) return -1;
  else if (n > 30) return -1; //overflow
  else
  {
    for (int i = 0; i < n; i++) result = result *2;
    return result;
  }
}

hugopeeters avatar Jan 07 '18 19:01 hugopeeters