math
frequenz.core.math ¤
Math tools.
Attributes¤
frequenz.core.math.LessThanComparableOrNoneT
module-attribute
¤
LessThanComparableOrNoneT = TypeVar(
"LessThanComparableOrNoneT",
bound=LessThanComparable | None,
)
Type variable for a value that a LessThanComparable
or None
.
Classes¤
frequenz.core.math.Interval
dataclass
¤
Bases: Generic[LessThanComparableOrNoneT]
An interval to test if a value is within its limits.
The start
and end
are inclusive, meaning that the start
and end
limites are
included in the range when checking if a value is contained by the interval.
If the start
or end
is None
, it means that the interval is unbounded in that
direction.
If start
is bigger than end
, a ValueError
is raised.
The type stored in the interval must be comparable, meaning that it must implement
the __lt__
method to be able to compare values.
Source code in frequenz/core/math.py
Attributes¤
Functions¤
__contains__ ¤
__contains__(item: LessThanComparableOrNoneT) -> bool
Check if the value is within the range of the container.
PARAMETER | DESCRIPTION |
---|---|
item
|
The value to check. |
RETURNS | DESCRIPTION |
---|---|
bool
|
True if value is within the range, otherwise False.
TYPE:
|
Source code in frequenz/core/math.py
__post_init__ ¤
Check if the start is less than or equal to the end.
Source code in frequenz/core/math.py
frequenz.core.math.LessThanComparable ¤
Bases: Protocol
A protocol that requires the __lt__
method to compare values.
Source code in frequenz/core/math.py
Functions¤
frequenz.core.math.is_close_to_zero ¤
Check if a floating point value is close to zero.
A value of 1e-9 is a commonly used absolute tolerance to balance precision and robustness for floating-point numbers comparisons close to zero. Note that this is also the default value for the relative tolerance. For more technical details, see https://peps.python.org/pep-0485/#behavior-near-zero
PARAMETER | DESCRIPTION |
---|---|
value
|
The floating point value to compare to.
TYPE:
|
abs_tol
|
The minimum absolute tolerance. Defaults to 1e-9.
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
bool
|
Whether the floating point value is close to zero. |