Nikola Kovacevic
Nikola Kovacevic

Reputation: 11

PyGears converting Integer to Fixed Point

I would like to convert my interface which is Uint[10] to Fixed Point 10.16, 16 bits in total, 10 for whole part and 6 bits for fraction. How to do it? Code for interface is below:

from pygears.typing import Uint

a = Intf(Uint[10])

Upvotes: 1

Views: 55

Answers (1)

Aleksa Knezevic
Aleksa Knezevic

Reputation: 116

You can't convert Uint[10] to Fixp[10, 16]. Because element of Uint[10] is between 0 and 1023 wich is far grater than max elemet of Fixp[10, 16].

You can convert Uint[10] to Fixp[11, 16] like this:

result = []
@gear
def consumer():

    data = once(val=[255], tout=Uint[10])
    res = data | Fixp[11, 16]
    collect(res, result=result)


consumer()
sim()

Result: [Fixp11, 16]

Upvotes: 1

Related Questions