SPH
Interval.cpp
Go to the documentation of this file.
2 #include <iomanip>
3 
5 
6 // wrapper over float printing "infinity/-infinity" instead of value itself
7 struct Printer {
9 
10  friend std::ostream& operator<<(std::ostream& stream, const Printer w) {
11  stream << std::setw(20);
12  if (w.value == INFTY) {
13  stream << "infinity";
14  } else if (w.value == -INFTY) {
15  stream << "-infinity";
16  } else {
17  stream << w.value;
18  }
19  return stream;
20  }
21 };
22 
23 std::ostream& operator<<(std::ostream& stream, const Interval& range) {
24  stream << Printer{ range.lower() } << Printer{ range.upper() };
25  return stream;
26 }
27 
NAMESPACE_SPH_BEGIN
Definition: BarnesHut.cpp:13
double Float
Precision used withing the code. Use Float instead of float or double where precision is important.
Definition: Globals.h:13
std::ostream & operator<<(std::ostream &stream, const Interval &range)
Definition: Interval.cpp:23
Object representing interval of real values.
constexpr Float INFTY
Definition: MathUtils.h:38
#define NAMESPACE_SPH_END
Definition: Object.h:12
Object representing a 1D interval of real numbers.
Definition: Interval.h:17
INLINE Float lower() const
Returns lower bound of the interval.
Definition: Interval.h:74
INLINE Float upper() const
Returns upper bound of the interval.
Definition: Interval.h:79
Float value
Definition: Interval.cpp:8
friend std::ostream & operator<<(std::ostream &stream, const Printer w)
Definition: Interval.cpp:10