import math


def _Prefix(quantity, unit, precision, scale_callable, **args):
  """Formats an integer and a unit into a string.

  Args:
    quantity: A number.
    unit: A string, the dimension for quantity, with no multipliers (e.g.
        "bps").  If quantity is dimensionless, the empty string.
    precision: An integer, the minimum number of digits to display.
    scale_callable: A callable, scales the number and units.
    **args: named arguments passed to scale_callable.

  Returns:
    A string.
  """
  separator = ' ' if unit else ''

  if not quantity:
    return '0%s%s' % (separator, unit)

  if quantity in [float('inf'), float('-inf')] or math.isnan(quantity):
    return '%f%s%s' % (quantity, separator, unit)

  scaled_quantity, scaled_unit = scale_callable(quantity, unit, **args)

  if scaled_unit:
    separator = ' '

  print_pattern = '%%.%df%%s%%s' % max(0, (precision - int(
      math.log(abs(scaled_quantity), 10)) - 1))

  return print_pattern % (scaled_quantity, separator, scaled_unit)