import math


def _Scale(quantity, unit, multiplier, prefixes=None, min_scale=None):
  """Returns the formatted quantity and unit into a tuple.

  Args:
    quantity: A number.
    unit: A string
    multiplier: An integer, the ratio between prefixes.
    prefixes: A sequence of strings.
        If empty or None, no scaling is done.
    min_scale: minimum power of multiplier corresponding to the first prefix.
        If None assumes prefixes are for positive powers only.

  Returns:
    A tuple containing the raw scaled quantity (float) and the prefixed unit.
  """
  if (not prefixes or not quantity or math.isnan(quantity) or
      quantity in [float('inf'), float('-inf')]):
    return float(quantity), unit

  if min_scale is None:
    min_scale = 0
    prefixes = ('',) + tuple(prefixes)
  value, prefix = quantity, ''
  for power, prefix in enumerate(prefixes, min_scale):
    # This is more numerically accurate than '/ multiplier ** power'.
    value = float(quantity) * multiplier ** -power
    if abs(value) < multiplier:
      break
  return value, prefix + unit