import math
import struct


def _next_up(x):
    """Returns the next-largest float towards positive infinity.

    Args:
        A floating point number.

    Returns:
        The next-largest float towards positive infinity. If NaN
        or positive infinity is passed, the argument is returned.

    """
    if math.isnan(x) or (math.isinf(x) and x > 0):
        return x

    # 0.0 and -0.0 both map to the smallest +ve float.
    if x == 0.0:
        x = 0.0

    n = struct.unpack('<q', struct.pack('<d', x))[0]
    if n >= 0:
        n += 1
    else:
        n -= 1
    return struct.unpack('<d', struct.pack('<q', n))[0]