diff options
author | Nao Pross <np@0hm.ch> | 2024-03-03 14:59:11 +0100 |
---|---|---|
committer | Nao Pross <np@0hm.ch> | 2024-03-03 15:06:42 +0100 |
commit | c47e538d7c3bb6b5032d3677fd7ce0c052d29b47 (patch) | |
tree | 4aa1b53791b2efecc806becad71e07dc402ba046 | |
parent | Fix numerical precision handling (diff) | |
download | mdpoly-c47e538d7c3bb6b5032d3677fd7ce0c052d29b47.tar.gz mdpoly-c47e538d7c3bb6b5032d3677fd7ce0c052d29b47.zip |
Add docstrings to util.isclose and util.iszero
Diffstat (limited to '')
-rw-r--r-- | mdpoly/util.py | 13 |
1 files changed, 12 insertions, 1 deletions
diff --git a/mdpoly/util.py b/mdpoly/util.py index ed7c234..937e7d4 100644 --- a/mdpoly/util.py +++ b/mdpoly/util.py @@ -1,7 +1,6 @@ from .constants import NUMERICS_EPS from itertools import tee, filterfalse -from math import abs def partition(pred, iterable): """Partition entries into false entries and true entries. @@ -14,8 +13,20 @@ def partition(pred, iterable): def isclose(x: float, y: float, eps: float =NUMERICS_EPS) -> bool: + r""" Check if two numbers are close. + + Close means :math:`|x - y| < \varepsilon` where :math:`\varepsilon` is the + given ``eps`` or the default value at + :py:data:`mdpoly.constants.NUMERICS_EPS`. + """ + # TODO: probably faster with math.isclose return abs(x - y) < eps def iszero(x: float, eps: float =NUMERICS_EPS) -> bool: + r""" Check a number is zero. + + Being zero means :math:`|x| < \varepsilon` where :math:`\varepsilon` is the given + ``eps`` or the default value at :py:data:`mdpoly.constants.NUMERICS_EPS`. + """ return isclose(x, 0.) |