Beispiel #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
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
Beispiel #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
Beispiel #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
Beispiel #5
0
def test_isinf(tc):
    tc.assertIs(utils.isinf(0), False)
    tc.assertIs(utils.isinf(0.0), False)
    tc.assertIs(utils.isinf(3), False)
    tc.assertIs(utils.isinf(3.0), False)
    tc.assertIs(utils.isinf(1e300), False)
    tc.assertIs(utils.isinf(1e400), True)
    tc.assertIs(utils.isinf(-1e300), False)
    tc.assertIs(utils.isinf(-1e400), True)
    tc.assertIs(utils.isinf(1e-300), False)
    tc.assertIs(utils.isinf(1e-400), False)
    tc.assertIs(utils.isinf(float("inf")), True)
    tc.assertIs(utils.isinf(float("-inf")), True)
    tc.assertIs(utils.isinf(float("NaN")), False)
Beispiel #6
0
def test_isinf(tc):
    tc.assertIs(utils.isinf(0), False)
    tc.assertIs(utils.isinf(0.0), False)
    tc.assertIs(utils.isinf(3), False)
    tc.assertIs(utils.isinf(3.0), False)
    tc.assertIs(utils.isinf(1e300), False)
    tc.assertIs(utils.isinf(1e400), True)
    tc.assertIs(utils.isinf(-1e300), False)
    tc.assertIs(utils.isinf(-1e400), True)
    tc.assertIs(utils.isinf(1e-300), False)
    tc.assertIs(utils.isinf(1e-400), False)
    tc.assertIs(utils.isinf(float("inf")), True)
    tc.assertIs(utils.isinf(float("-inf")), True)
    tc.assertIs(utils.isinf(float("NaN")), False)