improve `SWAP' macro

This commit is contained in:
rlar 2016-03-22 13:03:59 +01:00
parent f84d2d4e44
commit b36385e333
2 changed files with 12 additions and 2 deletions

View File

@ -36,7 +36,12 @@
#define ABS(a) ((a) < 0.0 ? -(a) : (a))
#define SGN(a) ((a) < 0.0 ? -(1.0) : (1.0))
#define SIGN(a,b) ( b >= 0 ? (a >= 0 ? a : - a) : (a >= 0 ? - a : a))
#define SWAP(type, a, b) {type swapx; swapx = a; a = b; b = swapx;}
#define SWAP(type, a, b) \
do { \
type SWAP_macro_local = a; \
a = b; \
b = SWAP_macro_local; \
} while(0)
#define ABORT() \

View File

@ -78,7 +78,12 @@
#define SQR(a) ((a)*(a))
/* Macro procedure that swaps two entities. */
#define SWAP(type, a, b) {type swapx; swapx = a; a = b; b = swapx;}
#define SWAP(type, a, b) \
do { \
type SWAP_macro_local = a; \
a = b; \
b = SWAP_macro_local; \
} while(0)