def RadicalInverse(a, base):
  """Computes the radical inverse of |a| in base |base|.

  Args:
    a: The integer number for which the radical inverse is computed.
    base: The radical inverse is computed in this base (integer).

  Returns:
    The radical inverse as a float in the range [0.0, 1.0).
  """
  reversed_digits = 0
  base_n = 1
  # Compute the reversed digits, base b.
  while a > 0:
    next_a = a / base
    digit = a - next_a * base
    reversed_digits = reversed_digits * base + digit
    base_n *= base
    a = next_a
  # Only when done are the reversed digits divided by b^n.
  return min(reversed_digits / float(base_n), 1.0)