#include <cstdlib> // For std::rand.
#include <cml/constants.h>
+#if defined(_MSC_VER)
+#pragma push_macro("min")
+#pragma push_macro("max")
+#undef min
+#undef max
+#endif
+
namespace cml {
/** Sign of input value as double. */
/** Test input value for inclusion in [min, max]. */
template < typename T >
bool in_range(T value, T min, T max) {
- return value >= min && value <= max;
+ return !(value < min) && !(value > max);
}
/** Map input value from [min1, max1] to [min2, max2]. */
}
-/** For convenient squaring of expressions. */
+/** Square a value. */
template < typename T >
T sqr(T value) {
return value * value;
}
+/** Cube a value. */
+template < typename T >
+T cub(T value) {
+ return value * value * value;
+}
+
/** Inverse square root. */
template < typename T >
T inv_sqrt(T value) {
return std::sqrt(length_squared(x,y,z));
}
+/** Index of maximum of 2 values. */
+template < typename T >
+size_t index_of_max(T a, T b) {
+ return a > b ? 0 : 1;
+}
+
+/** Index of maximum of 2 values by magnitude. */
+template < typename T >
+size_t index_of_max_abs(T a, T b) {
+ return index_of_max(std::fabs(a),std::fabs(b));
+}
+
+/** Index of minimum of 2 values. */
+template < typename T >
+size_t index_of_min(T a, T b) {
+ return a < b ? 0 : 1;
+}
+
+/** Index of minimum of 2 values by magnitude. */
+template < typename T >
+size_t index_of_min_abs(T a, T b) {
+ return index_of_min(std::fabs(a),std::fabs(b));
+}
+
/** Index of maximum of 3 values. */
template < typename T >
size_t index_of_max(T a, T b, T c) {
} // namespace cml
+#if defined(_MSC_VER)
+#pragma pop_macro("min")
+#pragma pop_macro("max")
+#endif
+
#endif
// -------------------------------------------------------------------------