import math


def closest_power_of_two(n):
  """Returns the closest power of two (linearly) to n.

  See: http://mccormick.cx/news/entries/nearest-power-of-two

  Args:
    n: Value to find the closest power of two of.

  Returns:
    Closest power of two to "n".
  """
  return pow(2, int(math.log(n, 2) + 0.5))