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: float
        The value of the Bound.
    """

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

        Parameters
        ----------
        value: float
            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: float
            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: float
            The actual value that should be checked for not exceeding the Bound.
        """

value: float property

Get the concrete value of the Bound.

__init__(value)

Initialize a Bound.

Parameters:

Name Type Description Default
value float

The value of the Bound.

required

Raises:

Type Description
ValueError

If value is nan or if value is +/-inf and the Bound type does not allow for infinite Bounds.

Source code in src/safeds/exceptions/_generic.py
def __init__(self, value: float):
    """
    Initialize a Bound.

    Parameters
    ----------
    value: float
        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

__str__()

Get a string representation of the concrete value of the Bound.

Source code in src/safeds/exceptions/_generic.py
def __str__(self) -> str:
    """Get a string representation of the concrete value of the Bound."""
    return str(self.value)