import math


def _scale_absolute_gap(gap, scale):
    """Convert an absolute gap to a relative gap with the
    given scaling factor."""
    assert scale > 0
    if not math.isinf(gap):
        return gap / scale
    else:
        return gap