mirror of
https://github.com/RIOT-OS/RIOT.git
synced 2024-12-29 04:50:03 +01:00
macros/utils: add LIMIT() macro
This patch adds a macro that can be used to limit a value to a given range.
This commit is contained in:
parent
4df530663b
commit
78a1a18683
@ -63,6 +63,22 @@ extern "C" {
|
||||
#define MIN(a, b) ((a) < (b) ? (a) : (b))
|
||||
#endif
|
||||
|
||||
/**
|
||||
* @brief Limit a value to an inclusive range
|
||||
*
|
||||
* If @p val is > @p high, @p high is returned. If @p val is < @p low, @p low
|
||||
* is returned. Otherwise, @p val is returned.
|
||||
*
|
||||
* @note This macro evaluate its arguments more than once.
|
||||
*
|
||||
* @param[in] val value to limit
|
||||
* @param[in] low minimum limit
|
||||
* @param[in] high maximum limit
|
||||
*
|
||||
* @return range limited value
|
||||
*/
|
||||
#define LIMIT(val, low, high) ((val < low) ? low : (val > high) ? high : val)
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
Loading…
Reference in New Issue
Block a user