Skip to content

Bug: Inaccuracy for certain complex multiplications #91

@MaxWipfli

Description

@MaxWipfli

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions