diff options
author | Nick Mathewson <nickm@torproject.org> | 2018-06-22 09:48:24 -0400 |
---|---|---|
committer | Nick Mathewson <nickm@torproject.org> | 2018-06-22 09:49:13 -0400 |
commit | 2cf033f238c111bef62552da16117568435d3a18 (patch) | |
tree | 34deb903de7bbdf42c399dce861e63c898c77dae /src/lib/intmath/cmp.h | |
parent | 3883338c8121212b3f6f9c020d489d50bbcdd855 (diff) | |
download | tor-2cf033f238c111bef62552da16117568435d3a18.tar.gz tor-2cf033f238c111bef62552da16117568435d3a18.zip |
Extract simple integer math into its own module
Diffstat (limited to 'src/lib/intmath/cmp.h')
-rw-r--r-- | src/lib/intmath/cmp.h | 20 |
1 files changed, 20 insertions, 0 deletions
diff --git a/src/lib/intmath/cmp.h b/src/lib/intmath/cmp.h new file mode 100644 index 0000000000..90ea3ca079 --- /dev/null +++ b/src/lib/intmath/cmp.h @@ -0,0 +1,20 @@ +/* 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 */ + +#ifndef TOR_INTMATH_CMP_H +#define TOR_INTMATH_CMP_H + +/* Return <b>v</b> if it's between <b>min</b> and <b>max</b>. Otherwise + * return <b>min</b> if <b>v</b> is smaller than <b>min</b>, or <b>max</b> if + * <b>b</b> is larger than <b>max</b>. + * + * Requires that <b>min</b> is no more than <b>max</b>. 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) */ |