Exemplo n.º 1
0
def interpret_real(s, context=None):
    """Convert a raw Real value to the float it represents.

    This is more lenient than the SGF spec: it accepts strings accepted as a
    float by the platform libc. It rejects infinities and NaNs.

    """
    result = float(s)
    if isinf(result):
        raise ValueError("infinite")
    if isnan(result):
        raise ValueError("not a number")
    return result
Exemplo n.º 2
0
def interpret_real(s, context=None):
    """Convert a raw Real value to the float it represents.

    This is more lenient than the SGF spec: it accepts strings accepted as a
    float by the platform libc. It rejects infinities and NaNs.

    """
    result = float(s)
    if isinf(result):
        raise ValueError("infinite")
    if isnan(result):
        raise ValueError("not a number")
    return result
Exemplo n.º 3
0
def interpret_float(arg):
    """Interpret a string representing a float, as specified by GTP.

    Returns a Python float.

    Raises GtpError with an appropriate message if 'arg' isn't a valid GTP
    float specification.

    Accepts strings accepted as a float by the platform libc; rejects
    infinities and NaNs.

    """
    try:
        result = float(arg)
        if isinf(result) or isnan(result):
            raise ValueError
    except ValueError:
        raise GtpError("invalid float: '%s'" % arg)
    return result
Exemplo n.º 4
0
def interpret_float(arg):
    """Interpret a string representing a float, as specified by GTP.

    Returns a Python float.

    Raises GtpError with an appropriate message if 'arg' isn't a valid GTP
    float specification.

    Accepts strings accepted as a float by the platform libc; rejects
    infinities and NaNs.

    """
    try:
        result = float(arg)
        if isinf(result) or isnan(result):
            raise ValueError
    except ValueError:
        raise GtpError("invalid float: '%s'" % arg)
    return result
Exemplo n.º 5
0
def test_nan(tc):
    tc.assertIs(utils.isnan(0), False)
    tc.assertIs(utils.isnan(0.0), False)
    tc.assertIs(utils.isnan(1e300), False)
    tc.assertIs(utils.isnan(1e400), False)
    tc.assertIs(utils.isnan(-1e300), False)
    tc.assertIs(utils.isnan(-1e400), False)
    tc.assertIs(utils.isnan(1e-300), False)
    tc.assertIs(utils.isnan(1e-400), False)
    tc.assertIs(utils.isnan(float("inf")), False)
    tc.assertIs(utils.isnan(float("-inf")), False)
    tc.assertIs(utils.isnan(float("NaN")), True)
Exemplo n.º 6
0
def test_nan(tc):
    tc.assertIs(utils.isnan(0), False)
    tc.assertIs(utils.isnan(0.0), False)
    tc.assertIs(utils.isnan(1e300), False)
    tc.assertIs(utils.isnan(1e400), False)
    tc.assertIs(utils.isnan(-1e300), False)
    tc.assertIs(utils.isnan(-1e400), False)
    tc.assertIs(utils.isnan(1e-300), False)
    tc.assertIs(utils.isnan(1e-400), False)
    tc.assertIs(utils.isnan(float("inf")), False)
    tc.assertIs(utils.isnan(float("-inf")), False)
    tc.assertIs(utils.isnan(float("NaN")), True)