def lerp(position: float, target: float, magnitude: float) -> float:
    """Linearly interpolates this position value towards a target value, which changes
    by a maximum of the magnitude value, returning the resulting position.

    Is a helper function for Vector.lerp.

    Preconditions:
        - magnitude >= 0

    Args:
        - position: The value to be linearly interpolated.
        - target: The other value to be linearly interpolated towards.
        - magnitude: The magnitude of any changes to the position value.
    """
    if position > target:
        return max(position - abs(magnitude), target)
    elif position < target:
        return min(position + abs(magnitude), target)
    else:
        return target