summaryrefslogtreecommitdiffstats
path: root/src/libs/dxvk-native-1.9.2a/src/util/util_math.h
diff options
context:
space:
mode:
Diffstat (limited to 'src/libs/dxvk-native-1.9.2a/src/util/util_math.h')
-rw-r--r--src/libs/dxvk-native-1.9.2a/src/util/util_math.h34
1 files changed, 34 insertions, 0 deletions
diff --git a/src/libs/dxvk-native-1.9.2a/src/util/util_math.h b/src/libs/dxvk-native-1.9.2a/src/util/util_math.h
new file mode 100644
index 00000000..fdb3762b
--- /dev/null
+++ b/src/libs/dxvk-native-1.9.2a/src/util/util_math.h
@@ -0,0 +1,34 @@
+#pragma once
+
+#include <cmath>
+
+namespace dxvk {
+
+ constexpr size_t CACHE_LINE_SIZE = 64;
+
+ template<typename T>
+ constexpr T clamp(T n, T lo, T hi) {
+ if (n < lo) return lo;
+ if (n > hi) return hi;
+ return n;
+ }
+
+ template<typename T, typename U = T>
+ constexpr T align(T what, U to) {
+ return (what + to - 1) & ~(to - 1);
+ }
+
+ template<typename T, typename U = T>
+ constexpr T alignDown(T what, U to) {
+ return (what / to) * to;
+ }
+
+ // Equivalent of std::clamp for use with floating point numbers
+ // Handles (-){INFINITY,NAN} cases.
+ // Will return min in cases of NAN, etc.
+ inline float fclamp(float value, float min, float max) {
+ return std::fmin(
+ std::fmax(value, min), max);
+ }
+
+} \ No newline at end of file