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 is LessThanComparable or None.
Deprecated
This type variable is deprecated and it will be removed in a future version. Use
LessThanComparableT instead.
frequenz.core.math.LessThanComparableT
module-attribute
¤
LessThanComparableT = TypeVar(
"LessThanComparableT", bound=LessThanComparable
)
Type variable for a value that is LessThanComparable.
Classes¤
frequenz.core.math.Interval
dataclass
¤
Bases: Generic[LessThanComparableT]
An interval to test if a value is within its limits.
The .start and .end are inclusive, meaning that the
.start and .end limits 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. None is used purely as a bound marker; it is
never a value in the interval.
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 src/frequenz/core/math.py
Attributes¤
end
instance-attribute
¤
end: LessThanComparableT | None
The end of the interval, or None to indicate no upper bound (+∞).
start
instance-attribute
¤
start: LessThanComparableT | None
The start of the interval, or None to indicate no lower bound (-∞).
Methods:¤
__contains__ ¤
__contains__(item: LessThanComparableT) -> bool
Check if the value is within the range of the interval.
| PARAMETER | DESCRIPTION |
|---|---|
item
|
The value to check.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
bool
|
True if value is within the range, otherwise False. |
Source code in src/frequenz/core/math.py
__post_init__ ¤
Check if the start is less than or equal to the end.
Source code in src/frequenz/core/math.py
frequenz.core.math.LessThanComparable ¤
Bases: Protocol
A protocol that requires the __lt__ method to compare values.
Source code in src/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. |