SDL School

API reference / Math

SDL_clamp

Macro, SDL3

Keeps a value between a minimum and a maximum. This is a macro.

Declaration

#include <SDL3/SDL.h>

#define SDL_clamp(x, a, b)

Parameters

xThe value.
aThe minimum.
bThe maximum.

Return value

The limited value.

Example

Read the keyboard
square.x = SDL_clamp(square.x, 0.0f, WINDOW_WIDTH - square.w);

See this code run in Read the keyboard. Download the full program (.zip)

Notes

In SDL2

The name is the same.

See also