1
0
mirror of https://github.com/elua/elua.git synced 2025-01-08 20:56:17 +08:00
elua/inc/utils.h

36 lines
1.1 KiB
C
Raw Normal View History

2008-08-19 20:21:10 +00:00
// General purpose function/macros
2008-07-29 11:08:54 +00:00
#ifndef __UTILS_H__
#define __UTILS_H__
#define ABSDIFF( x, y ) ( ( x ) >= ( y ) ? ( x ) - ( y ) : ( y ) - ( x ) )
#define UMIN( x, y ) ( ( x ) <= ( y ) ? ( x ) : ( y ) )
#define UMAX( x, y ) ( ( x ) >= ( y ) ? ( x ) : ( y ) )
#define UABS( x ) ( ( x ) >= 0 ? ( x ) : -( x ) )
// Macro version of Duff's device found in
// "A Reusable Duff Device" by Ralf Holly
// Dr Dobb's Journal, August 1, 2005
#define DUFF_DEVICE_8(count, action) \
do { \
int _count = ( count ); \
int _times = ( _count + 7 ) >> 3; \
switch ( _count & 7 ){ \
case 0: do { action; \
case 7: action; \
case 6: action; \
case 5: action; \
case 4: action; \
case 3: action; \
case 2: action; \
case 1: action; \
} while (--_times > 0); \
} \
} while (0)
#define STD_CTRLZ_CODE 26
2008-07-29 11:08:54 +00:00
#endif