From 9280818a573d48890153154089bc7eb2c4203da0 Mon Sep 17 00:00:00 2001 From: Joshua Ashton Date: Sat, 20 Apr 2019 21:24:02 +0100 Subject: [PATCH] [util] Implement fclamp for fp special cases --- src/util/util_math.h | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/src/util/util_math.h b/src/util/util_math.h index 806a563ba..29e052f0b 100644 --- a/src/util/util_math.h +++ b/src/util/util_math.h @@ -1,5 +1,7 @@ #pragma once +#include + namespace dxvk { constexpr size_t CACHE_LINE_SIZE = 64; @@ -15,5 +17,13 @@ namespace dxvk { constexpr T align(T what, U to) { return (what + to - 1) & ~(to - 1); } + + // 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