Skip to content

Bound

Bases: ABC

Abstract base class for (lower or upper) Bounds on a float value.

Parameters:

Name Type Description Default
value float

The value of the Bound.

required
Source code in src/safeds/exceptions/_generic.py
class Bound(ABC):
    """
    Abstract base class for (lower or upper) Bounds on a float value.

    Parameters
    ----------
    value:
        The value of the Bound.
    """

    def __init__(self, value: float):
        """
        Initialize a Bound.

        Parameters
        ----------
        value:
            The value of the Bound.

        Raises
        ------
        ValueError
            If value is nan or if value is +/-inf and the Bound type does not allow for infinite Bounds.
        """
        from numpy import isnan

        if isnan(value):
            raise ValueError("Bound must be a real number, not nan.")
        self._value = value

    def __str__(self) -> str:
        """Get a string representation of the concrete value of the Bound."""
        return str(self.value)

    @property
    def value(self) -> float:
        """Get the concrete value of the Bound."""
        return self._value

    @abstractmethod
    def _str_lower_bound(self) -> str:
        """Get a string representation of the Bound as the lower Bound of an interval."""

    @abstractmethod
    def _str_upper_bound(self) -> str:
        """Get a string representation of the Bound as the upper Bound of an interval."""

    @abstractmethod
    def _check_lower_bound(self, actual: float) -> bool:
        """
        Check that a value does not exceed the Bound on the lower side.

        Parameters
        ----------
        actual:
            The actual value that should be checked for not exceeding the Bound.
        """

    @abstractmethod
    def _check_upper_bound(self, actual: float) -> bool:
        """
        Check that a value does not exceed the Bound on the upper side.

        Parameters
        ----------
        actual:
            The actual value that should be checked for not exceeding the Bound.
        """

value: float property

Get the concrete value of the Bound.