ds/include/ds/number.h

16 lines
468 B
C
Raw Permalink Normal View History

2022-05-29 21:57:31 +02:00
// Copyright 2022 Darwin Schuppan <darwin@nobrain.org>
// SPDX license identifier: MIT
2022-05-29 20:46:25 +02:00
#ifndef __DS_NUMBER_H__
#define __DS_NUMBER_H__
/* Returns the smaller/larger value of x and y. */
#define min(x, y) ((x) < (y) ? (x) : y)
#define max(x, y) ((x) > (y) ? (x) : y)
/* Tries to calculate x - y. If the result would be negative, returns 0 instead.
* Can safely be used on unsigned types like size_t. */
#define sub_clamped(x, y) ((x) > (y) ? (x) - (y) : 0)
#endif