DOKK / manpages / debian 13 / libsdl3-doc / SDL_clamp.3.en
SDL_clamp(3) SDL3 FUNCTIONS SDL_clamp(3)

SDL_clamp - Return a value clamped to a range.

Defined in SDL3/SDL_stdinc.h

#include "SDL3/SDL.h"
#define SDL_clamp(x, a, b) (((x) < (a)) ? (a) : (((x) > (b)) ? (b) : (x)))

If x is outside the range a values between a and b , the returned value will be a or b as appropriate. Otherwise, x is returned.

This macro will produce incorrect results if b is less than a .

This is a helper macro that might be more clear than writing out the comparisons directly, and works with any type that can be compared with the < and > operators. However, it double-evaluates all its parameters, so do not use expressions with side-effects here.

Returns x, clamped between a and b.

It is safe to call this macro from any thread.

This macro is available since SDL 3.2.0.

SDL 3.2.10 Simple Directmedia Layer