Beispiel #1
0
def test_issue_19_v0_3_7():
    DW = 12
    DATA_FXPTYPE = Fxp(None, signed=True, n_word=DW, n_frac=DW - 1)

    a = Fxp(np.zeros(2, dtype=complex), like=DATA_FXPTYPE)
    c = Fxp(complex(0, 0), like=DATA_FXPTYPE)
    b = Fxp(0.5 - 0.125j, like=DATA_FXPTYPE)

    # print(c.get_val() + b.get_val())
    c.equal(c + b)

    # c.info()
    assert c() == 0.5 - 0.125j

    # print(a[0].get_val() + b.get_val())
    # a[0].equal(a[0]+b) # not supported
    a[0] = a[0] + b

    # a[0].info()
    assert a[0]() == 0.5 - 0.125j
Beispiel #2
0
#%%
x1 = Fxp(4.25, signed=True, n_word=8, n_frac=4)
x2 = Fxp(1.0, signed=True, n_word=16, n_frac=2)

y = x1 + x2
print('{} + {} = {}'.format(x1, x2, y))
print(y.info())

#%%
y = Fxp(signed=True, n_word=8, n_frac=4)

x1 = Fxp(4.25, signed=True, n_word=8, n_frac=4)
x2 = Fxp(1.0, signed=True, n_word=16, n_frac=2)

y.equal(x1 + x2)
print('{} + {} = {}'.format(x1, x2, y))
print(y.info())

x3 = Fxp(15.0, signed=True, n_word=16, n_frac=2)

y.equal(x1 + x3)
print('{} + {} = {}'.format(x1, x3, y))
print(y.info())

y.equal(x1 - x3)
print('{} - {} = {}'.format(x1, x3, y))
print(y.info())

#%%
x1 = Fxp(4.25, signed=True, n_word=8, n_frac=4)