8 #ifndef IMPALGEBRA_UTILITY_H
9 #define IMPALGEBRA_UTILITY_H
12 #include <IMP/algebra/algebra_config.h>
15 IMPALGEBRA_BEGIN_NAMESPACE
18 inline bool xorT(
bool x,
bool y) {
return (((x) && !(y)) || (!(x) && (y))); }
21 inline double get_squared(
double x) {
return x * x; }
45 return static_cast<int>((x) + 0.5);
47 return static_cast<int>((x) - 0.5);
67 if (x < x0)
return x0;
68 if (x > xF)
return xF;
98 if ((x - q) < (p - x)) {
109 const double epsilon) {
110 return (std::abs(a - b) < epsilon);
113 IMPALGEBRA_END_NAMESPACE
double get_next_larger_power_of_2(double x)
Closest power of 2 that can contain a number x.
int get_sign(const T &x)
Sign of a number. 1 if the number is higher or equal to 0 and -1 otherwise.
int get_rounded(const T &x)
Rounds a number to next integer.
bool get_are_almost_equal(const double a, const double b, const double epsilon)
Compares two values (intended for doubles)
Exception definitions and assertions.
T get_constrained(const T x, const T x0, const T xF)
Constrains a value between two given limits.
double get_closer_power_of_2(double x)
Closest power of 2 for a number, not necessarily higher.