File tree Expand file tree Collapse file tree 1 file changed +25
-0
lines changed
Expand file tree Collapse file tree 1 file changed +25
-0
lines changed Original file line number Diff line number Diff line change 1+ # License: MIT
2+ # Copyright © 2023 Frequenz Energy-as-a-Service GmbH
3+
4+ """Internal math tools."""
5+
6+ import math
7+
8+
9+ def is_close_to_zero (value : float , abs_tol : float = 1e-9 ) -> bool :
10+ """Check if a floating point value is close to zero.
11+
12+ A value of 1e-9 is a commonly used absolute tolerance to balance precision
13+ and robustness for floating-point numbers comparisons close to zero. Note
14+ that this is also the default value for the relative tolerance.
15+ For more technical details, see https://peps.python.org/pep-0485/#behavior-near-zero
16+
17+ Args:
18+ value: the floating point value to compare to.
19+ abs_tol: the minimum absolute tolerance. Defaults to 1e-9.
20+
21+ Returns:
22+ whether the floating point value is close to zero.
23+ """
24+ zero : float = 0.0
25+ return math .isclose (a = value , b = zero , abs_tol = abs_tol )
You can’t perform that action at this time.
0 commit comments