Cockatrice 2026-09-01-Development-3.1.0-beta.10
A virtual tabletop for multiplayer card games
Loading...
Searching...
No Matches
clamped_arithmetic.h
Go to the documentation of this file.
1#ifndef CLAMPED_ARITHMETIC_H
2#define CLAMPED_ARITHMETIC_H
3
4#include <QtGlobal>
5#include <cstdint>
6
16inline int addClamped(int value, int delta, int minValue, int maxValue)
17{
18 const auto result = static_cast<int64_t>(value) + static_cast<int64_t>(delta);
19 return static_cast<int>(qBound(static_cast<int64_t>(minValue), result, static_cast<int64_t>(maxValue)));
20}
21
22#endif // CLAMPED_ARITHMETIC_H
int addClamped(int value, int delta, int minValue, int maxValue)
Overflow-safe clamped addition: returns value + delta bounded to [minValue, maxValue].
Definition clamped_arithmetic.h:16