Skip to content

pow is 'expensive' #3

Description

@hugopeeters

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;
  }
}

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions