cmp.h 1.1 KB

123456789101112131415161718192021222324252627282930313233
  1. /* Copyright (c) 2003-2004, Roger Dingledine
  2. * Copyright (c) 2004-2006, Roger Dingledine, Nick Mathewson.
  3. * Copyright (c) 2007-2018, The Tor Project, Inc. */
  4. /* See LICENSE for licensing information */
  5. #ifndef TOR_INTMATH_CMP_H
  6. #define TOR_INTMATH_CMP_H
  7. /** Macros for MIN/MAX. Never use these when the arguments could have
  8. * side-effects.
  9. * {With GCC extensions we could probably define a safer MIN/MAX. But
  10. * depending on that safety would be dangerous, since not every platform
  11. * has it.}
  12. **/
  13. #ifndef MAX
  14. #define MAX(a,b) ( ((a)<(b)) ? (b) : (a) )
  15. #endif
  16. #ifndef MIN
  17. #define MIN(a,b) ( ((a)>(b)) ? (b) : (a) )
  18. #endif
  19. /* Return <b>v</b> if it's between <b>min</b> and <b>max</b>. Otherwise
  20. * return <b>min</b> if <b>v</b> is smaller than <b>min</b>, or <b>max</b> if
  21. * <b>b</b> is larger than <b>max</b>.
  22. *
  23. * Requires that <b>min</b> is no more than <b>max</b>. May evaluate any of
  24. * its arguments more than once! */
  25. #define CLAMP(min,v,max) \
  26. ( ((v) < (min)) ? (min) : \
  27. ((v) > (max)) ? (max) : \
  28. (v) )
  29. #endif /* !defined(TOR_INTMATH_CMP_H) */