Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Incorrect Multiplication Result when using NumPy Array Instantiation #97

Open
Greek64 opened this issue Jun 20, 2024 · 0 comments
Open

Comments

@Greek64
Copy link

Greek64 commented Jun 20, 2024

I'm getting wrong results when I'm using Fxps instantiated from a NumPy Array and given a custom dtype.
The same Fxp instantiated via different ways, even if seemingly exactly the same, produces correct results.


Minimal Example:

import numpy as np
from fxpmath import Fxp

a1 = Fxp(np.array([1.057311]),dtype='Q5.20')
print(f"A1 = {a1[0]}, dtype = {a1[0].dtype}, mem = {a1[0].val}")
a2 = Fxp(1.057311,dtype='Q5.20')
print(f"A2 = {a2}, dtype = {a2.dtype}, mem = {a2.val}")
b = Fxp('7971079',dtype='Q24.20')
print(f"B = {b}, dtype = {b.dtype}")
c = b * a1[0]
print(f"C = {c}, dtype = {c.dtype}")
d = b * a2
print(f"D = {d}, dtype = {d.dtype}")
e = b * Fxp(a1[0],dtype='Q5.20')
print(f"E = {e}, dtype = {e.dtype}")

Output:

A1 = 1.0573101043701172, dtype = fxp-s25/20, mem = 1108670
A2 = 1.0573101043701172, dtype = fxp-s25/20, mem = 1108670
B = 7971079.0, dtype = fxp-s44/20
C = -8349313.630567551, dtype = fxp-s69/40
D = 8427902.36943245, dtype = fxp-s69/40
E = 8427902.36943245, dtype = fxp-s69/40

As can be seen from the output, Fxp A1 produces incorrect multiplication results.
I don't know if it affects different operations besides multiplication and other conditions that have to be met.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant