-
Notifications
You must be signed in to change notification settings - Fork 25
Closed
Description
Hi! First of all, thanks for this module, great work!
I've noticed, that Fxp does not support the power of unsigned values. The following example
a = Fxp(15, signed=False)
b = a ** 2
Generates traceback:
Traceback (most recent call last):
File "dpd_model.py", line 16, in <module>
b = a ** 2
File "/home/arnfol/anaconda3/lib/python3.8/site-packages/fxpmath/objects.py", line 608, in __pow__
y = Fxp(self.get_val() ** n, signed=self.signed or n.signed, n_word=n_word, n_frac=n_frac)
AttributeError: 'int' object has no attribute 'signed'
Which is, obviously, because integer n does not have a signed
field :) I think that or n.signed
is not needed here, because the sign of the number in pow does not affect the resulting sign.
I also suppose that the __pow__ method does not generate correct n_word
bit size for signed values. Rigth now it multiplies sign bit by n, which is not needed. I assume it should be like:
def __pow__(self, n):
n_intg = self.n_word - self.n_frac - 1 if self.signed else self.n_word - self.n_frac
n_frac = self.n_frac * n
n_word = n_intg * n + n_frac + 1 if self.signed else n_intg * n + n_frac
y = Fxp(self.get_val() ** n, signed=self.signed, n_word=n_word, n_frac=n_frac)
return y
But I haven't tested it yet.
Metadata
Metadata
Assignees
Labels
No labels