Advertisement
TShiva

min_max

Sep 21st, 2017
266
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.63 KB | None | 0 0
  1.  
  2. #ifndef FIO_MIN_MAX_H
  3. #define FIO_MIN_MAX_H
  4.  
  5. #ifndef min
  6. #define min(x,y) ({ \
  7.         typeof(x) _x = (x);     \
  8.         typeof(y) _y = (y);     \
  9.         (void) (&_x == &_y);            \
  10.         _x < _y ? _x : _y; })
  11. #endif
  12.  
  13. #ifndef max
  14. #define max(x,y) ({ \
  15.         typeof(x) _x = (x);     \
  16.         typeof(y) _y = (y);     \
  17.         (void) (&_x == &_y);            \
  18.         _x > _y ? _x : _y; })
  19. #endif
  20.  
  21. #define min_not_zero(x, y) ({           \
  22.         typeof(x) __x = (x);            \
  23.         typeof(y) __y = (y);            \
  24.         __x == 0 ? __y : ((__y == 0) ? __x : min(__x, __y)); })
  25.  
  26. #endif
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement