/* Copyright (c) 2003-2004, Roger Dingledine * Copyright (c) 2004-2006, Roger Dingledine, Nick Mathewson. * Copyright (c) 2007-2018, The Tor Project, Inc. */ /* See LICENSE for licensing information */ /** * \file cmp.h * * \brief Macro definitions for MIN, MAX, and CLAMP. **/ #ifndef TOR_INTMATH_CMP_H #define TOR_INTMATH_CMP_H /** Macros for MIN/MAX. Never use these when the arguments could have * side-effects. * {With GCC extensions we could probably define a safer MIN/MAX. But * depending on that safety would be dangerous, since not every platform * has it.} **/ #ifndef MAX #define MAX(a,b) ( ((a)<(b)) ? (b) : (a) ) #endif #ifndef MIN #define MIN(a,b) ( ((a)>(b)) ? (b) : (a) ) #endif /* Return v if it's between min and max. Otherwise * return min if v is smaller than min, or max if * b is larger than max. * * Requires that min is no more than max. May evaluate any of * its arguments more than once! */ #define CLAMP(min,v,max) \ ( ((v) < (min)) ? (min) : \ ((v) > (max)) ? (max) : \ (v) ) #endif /* !defined(TOR_INTMATH_CMP_H) */