Skip to content

Commit

Permalink
Merge pull request #57 from molssi-seamm/dev
Browse files Browse the repository at this point in the history
Bugfix: Floating point issues in finding duplicates in lists.
  • Loading branch information
seamm authored Jun 5, 2024
2 parents 88a06b2 + 753669c commit 4c20d30
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 2 deletions.
4 changes: 4 additions & 0 deletions HISTORY.rst
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
=======
History
=======
2024.6.5 -- Bugfix: Handling of duplicates in lists
* Roundoff in floating point numbers caused some duplicates to be missed. The code
now checks for duplicates in a more robust way.

2024.4.30 -- Added utility for handling list definitions
* Add list_definition.py with parse_list()
* Updated makefile for doctests.
Expand Down
8 changes: 6 additions & 2 deletions seamm_util/list_definition.py
Original file line number Diff line number Diff line change
Expand Up @@ -131,8 +131,12 @@ def parse_list(input, duplicates=True, sort=False, **kwargs):

# Add a very small number for roundoff in floats
while sign * (stop - value + stop / 1.0e8) >= 0:
if not duplicates and value in result:
pass
if not duplicates:
for tmp in result:
if abs(value - tmp) < 1.0e-8:
break
else:
result.append(value)
else:
result.append(value)
value += step
Expand Down

0 comments on commit 4c20d30

Please sign in to comment.