Skip to content

Commit

Permalink
version 0.3.4
Browse files Browse the repository at this point in the history
* fix wrap error for unsigned Fxp.
  • Loading branch information
francof2a committed Jun 9, 2020
1 parent c8a856f commit 9ca5eb2
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 3 deletions.
4 changes: 4 additions & 0 deletions changelog.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
version 0.3.4
--------------------------------------------------
* fix wrap error for unsigned Fxp.

version 0.3.3
--------------------------------------------------
* fix shifting bitwise of unsigned values.
Expand Down
2 changes: 1 addition & 1 deletion fxpmath/__init__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
__version__ = '0.3.3'
__version__ = '0.3.4'

import sys
__maxsize__ = sys.maxsize
Expand Down
5 changes: 4 additions & 1 deletion fxpmath/objects.py
Original file line number Diff line number Diff line change
Expand Up @@ -382,7 +382,10 @@ def _overflow_action(self, new_val, val_min, val_max):
elif self.overflow == 'wrap':
if new_val.ndim == 0:
if not ((new_val <= val_max) & (new_val >= val_min)):
val = utils.twos_complement_repr(new_val, self.n_word)
if self.signed:
val = utils.twos_complement_repr(new_val, self.n_word)
else:
val = new_val % (1 << self.n_word)
else:
val = new_val
else:
Expand Down
7 changes: 6 additions & 1 deletion tests/test_bugs.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,4 +58,9 @@ def test_bugs_0_3_2():
assert x() == 0.5
assert x(4.0) == 0.0
assert x(5.0) == 1.0
assert x([3.5, 4.0, 4.5, 5.0])().all() == np.array([3.5, 0.0, 0.5, 1.0]).all()
assert x([3.5, 4.0, 4.5, 5.0])().all() == np.array([3.5, 0.0, 0.5, 1.0]).all()

def test_bugs_0_3_3():
# wrap error
x = Fxp(12.5, False, 11, 8, overflow='wrap')
assert x() == 4.5

0 comments on commit 9ca5eb2

Please sign in to comment.