示例#1
0
def test_float_max_value2():
    assert Float.max_value().sign == Bit(False)
    for bit in Float.max_value().exponents[:-1]:
        assert bit == Bit(True)
    assert Float.max_value().exponents[-1] == Bit()
    for bit in Float.max_value().fractions:
        assert bit == Bit(True)
示例#2
0
def test_float_multiplication5():
    float1 = Float('0.14')
    float2 = Float('0.0001')
    res = float1 * float2

    assert res.sign == Bit()
    exponents = map(lambda x: Bit(bool(x)), [0, 1, 1, 0, 1, 1, 1, 0])
    for i, exp in enumerate(exponents):
        assert res.exponents[i] == exp

    fractions = map(
        lambda x: Bit(bool(x)),
        [1, 1, 0, 1, 0, 1, 0, 1, 1, 1, 0, 0, 0, 0, 1, 1, 0, 0, 0, 1, 0, 1, 0])
    for i, exp in enumerate(fractions):
        assert res.fractions[i] == exp
示例#3
0
def test_float_multiplication3():
    float1 = Float('-107')
    float2 = Float('-97')
    assert float1 * float2 == Float('10379.0')
示例#4
0
def test_float_plus4():
    float1 = Float('25')
    float2 = Float('-10')
    assert float1 + float2 == Float('15.0')
示例#5
0
def test_float_plus3():
    float1 = Float('5')
    float2 = Float('-10')
    assert float1 + float2 == Float('-5.0')
示例#6
0
def test_float_plus2():
    float1 = Float('-3.14')
    float2 = Float('-2.5')
    assert float1 + float2 == Float('-5.640000343322754')
示例#7
0
def test_float_init1():
    float_val = Float('3')
    assert str(float_val) == '3.0'
示例#8
0
def test_float_division3():
    float1 = Float('3.14')
    float2 = Float('0')
    assert str(float1 / float2) == 'inf'
示例#9
0
def test_float_init2():
    float_val = Float('-1')
    assert str(float_val) == '-1.0'
示例#10
0
def test_float_init5():
    float_val = Float('3.14')
    assert str(float_val) == '3.140000104904175'
示例#11
0
def test_float_init4():
    float_val = Float('0.0')
    assert str(float_val) == '0'
示例#12
0
def test_float_min_value1():
    assert str(Float.min_value()) == '-1.175494490952134e-38'
示例#13
0
def test_float_max_value1():
    assert str(Float.max_value()) == '340282346638528859811704183484516925440'
示例#14
0
def test_float_division5():
    float1 = Float('0')
    float2 = Float('0')
    assert str(float1 / float2) == 'nan'
示例#15
0
def test_float_division4():
    float1 = Float('-3.14')
    float2 = Float('0')
    assert str(float1 / float2) == '-inf'
示例#16
0
def test_float_multiplication4():
    float1 = Float('3.14')
    float2 = Float('2.0001')
    assert str(float1 * float2) == '6.280313491821289'
示例#17
0
def test_float_init6():
    float_val = Float('0.0001')
    assert str(float_val) == '9.999999747378752e-05'
示例#18
0
def test_float_plus1():
    float1 = Float('3.14')
    float2 = Float('2.5')
    assert float1 + float2 == Float('5.640000343322754')
示例#19
0
def test_float_division1():
    float1 = Float('20')
    float2 = Float('4')
    assert float1 / float2 == Float('5.0')
示例#20
0
def test_float_division2():
    float1 = Float('3.14')
    float2 = Float('2.0001')
    assert str(float1 / float2) == '1.569921612739563'