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

Bug: Inaccuracy for certain complex multiplications #91

Open
MaxWipfli opened this issue Feb 2, 2024 · 1 comment
Open

Bug: Inaccuracy for certain complex multiplications #91

MaxWipfli opened this issue Feb 2, 2024 · 1 comment
Milestone

Comments

@MaxWipfli
Copy link

When performing multiplications using complex Fxp numbers, the result dtype is not inferred correctly. This can lead to overflow in the resulting value.

Example:

from fxpmath import Fxp
x = Fxp(-1-1j)
x.info()
# dtype		=	fxp-s1/0-complex
# Value		=	(-1-1j)

y = x * x

y.info()
# dtype		=	fxp-s2/0-complex
# Value		=	1j
# overflow	=	True
# inaccuracy	=	True

As shown above, the result is y = 1j, even though the correct result would be y = 2j, which cannot be represented by dtype = fxp-s2/0-complex.

I suspect the bug is that the inference of the result dtype misses the fact that a complex multiplication also requires an addition/subtraction, requiring another bit to represent the values accurately:

(a + j * b) * (c + j * d) = (ac - bd) + j * (ad + bc)

I am using fxpmath version 0.4.8, installed from PyPI.

@francof2a francof2a added this to the v0.4.10 milestone Feb 8, 2024
@francof2a
Copy link
Owner

I could reproduce the bug.
Yor're right about an extra bit is necessary because additions/subtractions.

This will be fixed in version 0.4.10.
Thanks!

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

2 participants