francof2a / fxpmath

A python library for fractional fixed-point (base 2) arithmetic and binary manipulation with Numpy compatibility.
MIT License
183 stars 21 forks source link

Creation of Fxp-object with negative n_frac #80

Closed alb-pol closed 9 months ago

alb-pol commented 1 year ago

The following code results in unexpected behaviour when trying to specify the same type using alternative formats :

x = Fxp(16, signed=True, n_word=8, n_frac=-2) -> x.dtype = 'fxp-s8/-2' , ok

x = Fxp(16, dtype='S10.-2') -> x.dtype = 'fxp-s10/0' , why? expected x.dtype= 'fxp-s8/-2'

x = Fxp(16, dtype='fxp-s8/-2') -> error message

Traceback (most recent call last): File "", line 1, in File "c:\Projects\MA-pyrdf.venv\lib\site-packages\fxpmath\objects.py", line 222, in init signed, n_word, n_frac, complex_flag = self._parseformatstr(dtype) File "c:\Projects\MA-pyrdf.venv\lib\site-packages\fxpmath\objects.py", line 348, in _parseformatstr raise ValueError('unrecognized format string') ValueError: unrecognized format string

francof2a commented 10 months ago

Hello, I could replicate the bug. The problem is that the dtype string parsing does not support negative numbers. This will be fixed in next version (v0.4.9). Thank you for the issue report!

francof2a commented 9 months ago

solved in v0.4.9