102 lines
4.2 KiB
C
102 lines
4.2 KiB
C
/* - | Copyright |
|
|
-------------------------------------------------------------- Copyright (c)
|
|
2026 Randy Jordan
|
|
|
|
Permission is hereby granted, free of charge, to any person obtaining a copy of
|
|
this software and associated documentation files (the "Software"), to deal in
|
|
the Software without restriction, including without limitation the rights to
|
|
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
|
|
of the Software, and to permit persons to whom the Software is furnished to do
|
|
so, subject to the following conditions:
|
|
|
|
The above copyright notice and this permission notice shall be included in all
|
|
copies or substantial portions of the Software.
|
|
|
|
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
SOFTWARE.
|
|
|
|
* --------------------------------------------------------------------------*/
|
|
#ifndef CI2_MACROS_H
|
|
#define CI2_MACROS_H
|
|
|
|
#define UNUSED(x) (void)(x)
|
|
#define STR2(s) #s
|
|
#define STR(s) STR2(s)
|
|
|
|
#define U8_MIN 0u
|
|
#define U8_MAX 0xffu
|
|
#define I8_MIN (-0x7f - 1)
|
|
#define I8_MAX 0x7f
|
|
|
|
#define U16_MIN 0u
|
|
#define U16_MAX 0xffffu
|
|
#define I16_MIN (-0x7fff - 1)
|
|
#define I16_MAX 0x7fff
|
|
|
|
#define U32_MIN 0u
|
|
#define U32_MAX 0xffffffffu
|
|
#define I32_MIN (-0x7fffffff - 1)
|
|
#define I32_MAX 0x7fffffff
|
|
|
|
#define U64_MIN 0ull
|
|
#define U64_MAX 0xffffffffffffffffull
|
|
#define I64_MIN (-0x7fffffffffffffffll - 1)
|
|
#define I64_MAX 0x7fffffffffffffffll
|
|
|
|
#define F32_MIN 1.17549435e-38f
|
|
#define F32_MAX 3.40282347e+38f
|
|
|
|
#define F64_MIN 2.2250738585072014e-308
|
|
#define F64_MAX 1.7976931348623157e+308
|
|
|
|
#define PI 3.14159265
|
|
#define RAD2DEG(x) ((x) / PI * 180)
|
|
#define DEG2RAD(x) ((x) * PI / 180)
|
|
#define ALIGNB(x, align) (((x) + ((align) - 1)) & ~((align) - 1))
|
|
#define ALIGN(x, align) ((((x) + ((align) - 1)) / (align)) * (align))
|
|
#define FLOORB(x, align) ((x) & ~((align) - 1))
|
|
#define FLOOR(x, align) (((x) / (align)) * (align))
|
|
#define CEILB(x, align) ALIGNB(x, align)
|
|
#define CEIL(x, align) ALIGN(x, align)
|
|
#define CLIP(x, min, max) \
|
|
(((x) < (min)) ? (min) : (((x) > (max)) ? (max) : (x)))
|
|
#define UCLIP(x, max) (((x) > (max)) ? (max) : (x))
|
|
#define LCLIP(x, min) (((x) < (min)) ? (min) : (x))
|
|
#define MIN(x, y) (((x) < (y)) ? (x) : (y))
|
|
#define MAX(x, y) (((x) > (y)) ? (x) : (y))
|
|
#define ABS(x) (((x) < 0) ? -(x) : (x))
|
|
#define DIFF(a, b) ABS((a) - (b))
|
|
#define IS_NAN(x) ((x) != (x))
|
|
#define IMPLIES(x, y) (!(x) || (y))
|
|
#define COMPARE(x, y) (((x) > (y)) - ((x) < (y)))
|
|
#define SIGN(x) COMPARE(x, 0)
|
|
#define IS_ODD(num) ((num) & 1)
|
|
#define IS_EVEN(num) (!IS_ODD((num)))
|
|
#define IS_BETWEEN(n, L, H) ((unsigned char)((n) >= (L) && (n) <= (H)))
|
|
|
|
#define ARRAY_SIZE(a) (sizeof(a) / sizeof((a)[0]))
|
|
#define SET(d, n, v) \
|
|
do { \
|
|
size_t i_, n_; \
|
|
for (n_ = (n), i_ = 0; n_ > 0; --n_, ++i_) \
|
|
(d)[i_] = (v); \
|
|
} while (0)
|
|
#define ZERO(d, n) SET(d, n, 0)
|
|
#define SWAP(a, b) \
|
|
do { \
|
|
a ^= b; \
|
|
b ^= a; \
|
|
a ^= b; \
|
|
} while (0)
|
|
#define SORT(a, b) \
|
|
do { \
|
|
if ((a) > (b)) \
|
|
SWAP((a), (b)); \
|
|
} while (0)
|
|
#endif // ci2_macros.h
|