Skip to content

Commit

Permalink
Interval operations (#14)
Browse files Browse the repository at this point in the history
few additional operations on intervals
  • Loading branch information
sjunges authored Aug 26, 2023
1 parent 50bf251 commit e4adf81
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 0 deletions.
27 changes: 27 additions & 0 deletions src/carl/interval/Interval.h
Original file line number Diff line number Diff line change
Expand Up @@ -1088,6 +1088,10 @@ namespace carl
return this->isPointInterval() && (mContent.lower() == carl::constant_one<Number>().get());
}

inline bool isNan() const {
return (std::isnan(mContent.lower()) || std::isnan(mContent.upper()));
}

/**
* @return true, if it this interval contains only positive values.
*/
Expand Down Expand Up @@ -1941,6 +1945,11 @@ namespace carl
template<typename Number>
inline Interval<Number> operator/(const Interval<Number>& lhs, const Number& rhs);

template<typename Number>
inline Interval<Number> operator/(const Interval<Number>& lhs, size_t rhs) {
return lhs / Interval<Number>(rhs);
}

/**
* Operator for the division of an interval and a number with assignment.
* @param lhs Lefthand side.
Expand All @@ -1950,6 +1959,24 @@ namespace carl
template<typename Number>
inline Interval<Number>& operator/=(Interval<Number>& lhs, const Number& rhs);

template<typename Number>
inline Interval<Number>& operator/=(Interval<Number>& lhs, size_t rhs) {
return lhs /= fromInt<Number>(rhs);
}

template<typename Number>
inline Interval<Number> operator/(const Interval<Number>& lhs, const Interval<Number>& rhs)
{
return lhs.div(rhs);
}

template<typename Number>
inline Interval<Number>& operator/=(Interval<Number>& lhs, const Interval<Number>& rhs)
{
lhs.div_assign(rhs);
return lhs;
}

/*
* Comparison operators
*/
Expand Down
6 changes: 6 additions & 0 deletions src/carl/numbers/adaption_native/operations.h
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,12 @@ inline double toDouble(sint n) {
inline double toDouble(double n) {
return n;
}
inline double toDouble(unsigned n) {
return double(n);
}
inline double toDouble(unsigned long n) {
return double(n);
}

template<typename Integer>
inline Integer toInt(double n);
Expand Down

0 comments on commit e4adf81

Please sign in to comment.