コード例 #1
0
ファイル: test_numbers.py プロジェクト: robotment/sympy
def test_Real():
    def eq(a, b):
        t = Real("1.0E-15")
        return (-t < a-b < t)

    a = Real(2) ** Real(3)
    assert eq(a.evalf(), Real(8))
    assert eq((pi ** -1).evalf(), Real("0.31830988618379067"))
    a = Real(2) ** Real(4)
    assert eq(a.evalf(), Real(16))
    assert (S(.3) == S(.5)) is False
    x_str = Real((0, '13333333333333L', -52, 53))
    x2_str = Real((0, '26666666666666L', -53, 53))
    x_hex = Real((0, 0x13333333333333L, -52, 53))
    x_dec = Real((0, 5404319552844595L, -52, 53))
    x2_hex = Real((0, 0x13333333333333L*2, -53, 53))
    assert x_str == x_hex == x_dec == x2_hex == Real(1.2)
    # x2_str and 1.2 are superficially the same
    assert str(x2_str) == str(Real(1.2))
    # but are different at the mpf level
    assert Real(1.2)._mpf_ == (0, 5404319552844595L, -52, 53)
    assert x2_str._mpf_ == (0, 10808639105689190L, -53, 53)

    # do not automatically evalf
    def teq(a):
        assert (a.evalf () == a) is False
        assert (a.evalf () != a) is True
        assert (a == a.evalf()) is False
        assert (a != a.evalf()) is True

    teq(pi)
    teq(2*pi)
    teq(cos(0.1, evaluate=False))
コード例 #2
0
def test_Real():
    def eq(a, b):
        t = Real("1.0E-15")
        return (-t < a - b < t)

    a = Real(2)**Real(3)
    assert eq(a.evalf(), Real(8))
    assert eq((pi**-1).evalf(), Real("0.31830988618379067"))
    a = Real(2)**Real(4)
    assert eq(a.evalf(), Real(16))
    assert (S(.3) == S(.5)) is False
    x_str = Real((0, '13333333333333L', -52, 53))
    x2_str = Real((0, '26666666666666L', -53, 53))
    x_hex = Real((0, 0x13333333333333L, -52, 53))
    x_dec = Real((0, 5404319552844595L, -52, 53))
    x2_hex = Real((0, 0x13333333333333L * 2, -53, 53))
    assert x_str == x_hex == x_dec == x2_hex == Real(1.2)
    # x2_str and 1.2 are superficially the same
    assert str(x2_str) == str(Real(1.2))
    # but are different at the mpf level
    assert Real(1.2)._mpf_ == (0, 5404319552844595L, -52, 53)
    assert x2_str._mpf_ == (0, 10808639105689190L, -53, 53)

    # do not automatically evalf
    def teq(a):
        assert (a.evalf() == a) is False
        assert (a.evalf() != a) is True
        assert (a == a.evalf()) is False
        assert (a != a.evalf()) is True

    teq(pi)
    teq(2 * pi)
    teq(cos(0.1, evaluate=False))
コード例 #3
0
ファイル: test_numbers.py プロジェクト: jcockayne/sympy-rkern
def test_Real():
    def eq(a, b):
        t = Real("1.0E-15")
        return (-t < a - b < t)

    a = Real(2)**Real(3)
    assert eq(a.evalf(), Real(8))
    assert eq((pi**-1).evalf(), Real("0.31830988618379067"))
    a = Real(2)**Real(4)
    assert eq(a.evalf(), Real(16))
コード例 #4
0
ファイル: test_numbers.py プロジェクト: jcockayne/sympy-rkern
def test_Real():
    def eq(a, b):
        t = Real("1.0E-15")
        return (-t < a-b < t)

    a = Real(2) ** Real(3)
    assert eq(a.evalf(), Real(8))
    assert eq((pi ** -1).evalf(), Real("0.31830988618379067"))
    a = Real(2) ** Real(4)
    assert eq(a.evalf(), Real(16))
コード例 #5
0
def test_Real():
    def eq(a, b):
        t = Real("1.0E-15")
        return -t < a - b < t

    a = Real(2) ** Real(3)
    assert eq(a.evalf(), Real(8))
    assert eq((pi ** -1).evalf(), Real("0.31830988618379067"))
    a = Real(2) ** Real(4)
    assert eq(a.evalf(), Real(16))
    assert (S(0.3) == S(0.5)) is False
    x_str = Real((0, "13333333333333L", -52, 53))
    x2_str = Real((0, "26666666666666L", -53, 53))
    x_hex = Real((0, 0x13333333333333L, -52, 53))
    x_dec = Real((0, 5404319552844595L, -52, 53))
    x2_hex = Real((0, 0x13333333333333L * 2, -53, 53))
    assert x_str == x_hex == x_dec == x2_hex == Real(1.2)
    # x2_str and 1.2 are superficially the same
    assert str(x2_str) == str(Real(1.2))
    # but are different at the mpf level
    assert Real(1.2)._mpf_ == (0, 5404319552844595L, -52, 53)
    assert x2_str._mpf_ == (0, 10808639105689190L, -53, 53)