diff --git a/changelog.txt b/changelog.txt index b8f3b7a..2ad4b97 100644 --- a/changelog.txt +++ b/changelog.txt @@ -8,6 +8,7 @@ version 0.4.9 * Selection of `prefix` for binary and hexadecimal representations. * Fix `cumsum` function bug when dealing with sizes bigger than 32 bits (windows) / 64 bits (linux) (issue #76). * Fix `numpy.reshape` function handling. This function was returning optimal size instead of same by default (issue #77). +* Fix negative number parsing in `dtype` string (issue #80). version 0.4.8 -------------------------------------------------- diff --git a/fxpmath/__init__.py b/fxpmath/__init__.py index 75013d5..11d523f 100644 --- a/fxpmath/__init__.py +++ b/fxpmath/__init__.py @@ -1,4 +1,4 @@ -__version__ = '0.4.9-dev7' +__version__ = '0.4.9-dev8' import sys import os diff --git a/fxpmath/objects.py b/fxpmath/objects.py index 34f04cb..e560a29 100644 --- a/fxpmath/objects.py +++ b/fxpmath/objects.py @@ -316,10 +316,10 @@ def get_dtype(self, notation=None): return self._dtype def _qfmt(self): - return re.compile(r'(s|u|q|uq|qu)(\d+)(\.\d+)?') + return re.compile(r'(s|u|q|uq|qu)(\d+)(\.[+-]?\d+)?') def _fxpfmt(self): - return re.compile(r'fxp-(s|u)(\d+)/(\d+)(-complex)?') + return re.compile(r'fxp-(s|u)(\d+)/([+-]?\d+)(-complex)?') def _parseformatstr(self, fmt): fmt = fmt.casefold() diff --git a/tests/test_issues.py b/tests/test_issues.py index e4cfa03..1041ba6 100644 --- a/tests/test_issues.py +++ b/tests/test_issues.py @@ -433,3 +433,19 @@ def test_issue_77_v0_4_8(): y = np.reshape(x, (1, 4)) # fxp-s4/3-complex assert y.signed == True and y.n_word == 5 and y.n_frac == 3 + +def test_issue_80_v0_4_8(): + # Creation of Fxp-object with negative n_frac + + # 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 + assert x.dtype == 'fxp-s8/-2' + + x = Fxp(16, dtype='S10.-2') + assert x.dtype == 'fxp-s8/-2' + + x = Fxp(16, dtype='fxp-s8/-2') + assert x.dtype == 'fxp-s8/-2' + \ No newline at end of file