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

div for complex data does not behave expected #53

Closed
ruoting0103 opened this issue Feb 11, 2022 · 2 comments
Closed

div for complex data does not behave expected #53

ruoting0103 opened this issue Feb 11, 2022 · 2 comments

Comments

@ruoting0103
Copy link

from fxpmath import Fxp
x = Fxp(2j, dtype = 'fxp-u4/0-complex')
x/2

the result is fxp-u4/0-complex(0j) rather than 1j

i could solve the problem by adding x.config.op_method = 'repr'

is there any other way to make it work like 2j/2 ? thanks

@francof2a
Copy link
Owner

Clearly, it's a bug!

I did a debug and the problem is that a floordiv with a complex number doesn't work in python nor numpy

j2 // 2 # raise TypeError: can't take floor of complex number.

np.array(2j) // np.array(2) # result = 0j

The raw method is used bay default in Fxp operation to assure precision, when you use repr the operation is performed using a truediv (/).

In other way, if you use multiplication and give a fractional bit the operation is performed well, but I don't think this is a workaround:

x = Fxp(2j, dtype = 'fxp-u4/1-complex')
x * 0.5

fxp-u4/1-complex(1j)

A special method should be implemented for complex division (raw op_method). It would be included in next release!

@francof2a
Copy link
Owner

Issue solved in v0.4.6

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