From c47e538d7c3bb6b5032d3677fd7ce0c052d29b47 Mon Sep 17 00:00:00 2001 From: Nao Pross Date: Sun, 3 Mar 2024 14:59:11 +0100 Subject: Add docstrings to util.isclose and util.iszero --- mdpoly/util.py | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) 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.) -- cgit v1.2.1