SDL: SDL_stdinc.h: Add an SDL_clamp() function

From 35c1bbfa49b1247c2c6240f7f95871f3b3331874 Mon Sep 17 00:00:00 2001
From: David Gow <[EMAIL REDACTED]>
Date: Fri, 13 Aug 2021 21:43:00 +0800
Subject: [PATCH] SDL_stdinc.h: Add an SDL_clamp() function

Add a function to clamp a value to a range.

SDL_clamp(x, a, b) is equivalent to SDL_min(a, SDL_max(x, b)): it
ensures that x is not smaller than a, nor larger than b.

While, as best I can tell, this isn't actually standardised anywhere,
it's a very useful function/macro to have.
 include/SDL_stdinc.h | 1 +
 1 file changed, 1 insertion(+)

diff --git a/include/SDL_stdinc.h b/include/SDL_stdinc.h
index c7f9068170..a86ed7993e 100644
--- a/include/SDL_stdinc.h
+++ b/include/SDL_stdinc.h
@@ -444,6 +444,7 @@ extern DECLSPEC int SDLCALL SDL_abs(int x);
 /* NOTE: these double-evaluate their arguments, so you should never have side effects in the parameters */
 #define SDL_min(x, y) (((x) < (y)) ? (x) : (y))
 #define SDL_max(x, y) (((x) > (y)) ? (x) : (y))
+#define SDL_clamp(x, a, b) ((x) < (a)) ? (a) : (((x) > (b)) ? (b) : (x))
 extern DECLSPEC int SDLCALL SDL_isalpha(int x);
 extern DECLSPEC int SDLCALL SDL_isalnum(int x);