32 #ifndef HERMES_HERMES_NUMERIC_INTERVAL_H
33 #define HERMES_HERMES_NUMERIC_INTERVAL_H
46 static_assert(std::is_same<T, f32>::value || std::is_same<T, f64>::value || std::is_same<T, float>::value
47 || std::is_same<T, double>::value || std::is_same<T, i32>::value || std::is_same<T, i64>::value,
48 "Interval must hold an numeric type!");
115 return {Numbers::lowest<T>(), Numbers::greatest<T>()};
170 #define ARITHMETIC_OP(OP) \
171 template<typename T> \
172 HERMES_DEVICE_CALLABLE Interval<T> operator OP (T f, const Interval<T>& i) { \
173 return Interval<T>(f) OP i; } \
174 template<typename T> \
175 HERMES_DEVICE_CALLABLE Interval<T> operator OP (const Interval<T>& i, T f) { \
176 return i OP Interval<T>(f); }
191 std::ostream &operator<<(std::ostream &os,
const Interval<T> &i) {
192 os <<
"[" << i.
low <<
" " << i.
high <<
"]";
Represents a numeric interval that supports interval arithmetic.
Definition: interval.h:45
HERMES_DEVICE_CALLABLE T center() const
Gets interval center value.
Definition: interval.h:135
HERMES_DEVICE_CALLABLE Interval operator-() const
Negates interval.
Definition: interval.h:84
HERMES_DEVICE_CALLABLE Interval operator-(const Interval &i) const
Uses interval arithmetic subtraction.
Definition: interval.h:95
HERMES_DEVICE_CALLABLE Interval(T l, T h)
Construct from interval values.
Definition: interval.h:73
static HERMES_DEVICE_CALLABLE Interval withRadius(real_t c, real_t r)
Constructs interval from center and radius.
Definition: interval.h:57
HERMES_DEVICE_CALLABLE Interval sqrt() const
Computes arithmetic interval square root.
Definition: interval.h:157
HERMES_DEVICE_CALLABLE Interval operator/(const Interval &i) const
Uses interval arithmetic division.
Definition: interval.h:112
HERMES_DEVICE_CALLABLE T width() const
Gets interval diameter.
Definition: interval.h:141
HERMES_DEVICE_CALLABLE Interval(T v)
Constructs from center value.
Definition: interval.h:69
HERMES_DEVICE_CALLABLE Interval operator+(const Interval &i) const
Uses interval arithmetic addition.
Definition: interval.h:89
HERMES_DEVICE_CALLABLE Interval()
Default constructor.
Definition: interval.h:66
HERMES_DEVICE_CALLABLE bool isExact() const
Checks if interval contains a single value.
Definition: interval.h:144
T low
lowest interval value
Definition: interval.h:163
HERMES_DEVICE_CALLABLE bool contains(T v) const
Checks if this interval contains v.
Definition: interval.h:132
HERMES_DEVICE_CALLABLE T radius() const
Gets interval radius.
Definition: interval.h:138
HERMES_DEVICE_CALLABLE Interval sqr() const
Computes arithmetic interval square.
Definition: interval.h:147
HERMES_DEVICE_CALLABLE Interval operator*(const Interval &i) const
Uses interval arithmetic multiplication.
Definition: interval.h:101
T high
greatest interval value
Definition: interval.h:164
Interface used by all basic geometric entities.
Definition: math_element.h:44
float real_t
default floating point type
Definition: defs.h:75
#define HERMES_DEVICE_CALLABLE
Specifies that the function can be called from both host and device sides.
Definition: defs.h:45
#define ARITHMETIC_OP(OP)
asd
Definition: index.h:408
Base class for all geometric objects.
static constexpr HERMES_DEVICE_CALLABLE bool is_equal(T a, T b)
Checks if two numbers are at most 1e-8 apart.
Definition: numeric.h:847
static HERMES_DEVICE_CALLABLE real_t addRoundDown(real_t a, real_t b)
Adds and rounds down to the next smaller float value.
Definition: numeric.h:594
static constexpr HERMES_DEVICE_CALLABLE T min(const T &a, const T &b)
Computes minimum between two numbers.
Definition: numeric.h:117
static HERMES_DEVICE_CALLABLE real_t subRoundUp(real_t a, real_t b)
Subtracts and rounds up to the next float value.
Definition: numeric.h:639
static HERMES_DEVICE_CALLABLE void swap(T &a, T &b)
Swaps values.
Definition: numeric.h:184
static HERMES_DEVICE_CALLABLE real_t divRoundUp(real_t a, real_t b)
Divides and rounds up to the next float value.
Definition: numeric.h:579
static HERMES_DEVICE_CALLABLE real_t divRoundDown(real_t a, real_t b)
Divides and rounds down to the next smaller float value.
Definition: numeric.h:564
static HERMES_DEVICE_CALLABLE real_t mulRoundUp(real_t a, real_t b)
Multiplies and rounds up to the next float value.
Definition: numeric.h:549
static HERMES_DEVICE_CALLABLE real_t addRoundUp(real_t a, real_t b)
Adds and rounds up to the next float value.
Definition: numeric.h:609
static constexpr HERMES_DEVICE_CALLABLE T max(const T &a, const T &b)
Computes maximum between two numbers.
Definition: numeric.h:127
static HERMES_DEVICE_CALLABLE real_t sqrtRoundDown(real_t a)
Computes square root rounded down to the next smaller float value.
Definition: numeric.h:653
static HERMES_DEVICE_CALLABLE real_t mulRoundDown(real_t a, real_t b)
Multiplies and rounds down to the next smaller float value.
Definition: numeric.h:534
static HERMES_DEVICE_CALLABLE real_t sqrtRoundUp(real_t a)
Computes square root rounded up to the next float value.
Definition: numeric.h:667
static HERMES_DEVICE_CALLABLE real_t subRoundDown(real_t a, real_t b)
Subtracts and rounds down to the next smaller float value.
Definition: numeric.h:624