Tor
0.4.9.2-alpha-dev
Toggle main menu visibility
Main Page
Related Pages
Modules
Data Structures
Data Structures
Data Structure Index
Data Fields
All
_
a
b
c
d
e
f
g
h
i
j
k
l
m
n
o
p
q
r
s
t
u
v
w
x
Functions
Variables
_
a
b
c
d
e
f
g
h
i
j
k
l
m
n
o
p
q
r
s
t
u
v
w
x
Enumerator
Files
File List
Globals
All
_
a
b
c
d
e
f
g
h
i
j
k
l
m
n
o
p
q
r
s
t
u
v
w
x
z
Functions
a
b
c
d
e
f
g
h
i
k
l
m
n
o
p
q
r
s
t
u
v
w
x
Variables
a
b
c
d
e
f
g
h
i
k
l
m
n
o
p
q
r
s
t
u
v
w
x
z
Typedefs
b
c
d
f
g
h
l
m
n
o
p
r
s
v
Enumerations
a
b
c
d
f
g
h
i
k
l
m
n
o
p
q
r
s
t
u
v
w
Enumerator
a
b
c
d
e
g
h
i
m
n
o
p
q
r
s
t
v
w
Macros
_
a
b
c
d
e
f
g
h
i
j
l
m
n
o
p
r
s
t
u
v
w
x
•
All
Data Structures
Files
Functions
Variables
Typedefs
Enumerations
Enumerator
Macros
Modules
Pages
lib
intmath
cmp.h
Go to the documentation of this file.
1
/* Copyright (c) 2003-2004, Roger Dingledine
2
* Copyright (c) 2004-2006, Roger Dingledine, Nick Mathewson.
3
* Copyright (c) 2007-2021, The Tor Project, Inc. */
4
/* See LICENSE for licensing information */
5
6
/**
7
* \file cmp.h
8
*
9
* \brief Macro definitions for MIN, MAX, and CLAMP.
10
**/
11
12
#ifndef TOR_INTMATH_CMP_H
13
#define TOR_INTMATH_CMP_H
14
15
/** Macros for MIN/MAX. Never use these when the arguments could have
16
* side-effects.
17
* {With GCC extensions we could probably define a safer MIN/MAX. But
18
* depending on that safety would be dangerous, since not every platform
19
* has it.}
20
**/
21
#ifndef MAX
22
#define MAX(a,b) ( ((a)<(b)) ? (b) : (a) )
23
#endif
24
#ifndef MIN
25
#define MIN(a,b) ( ((a)>(b)) ? (b) : (a) )
26
#endif
27
28
/* Return <b>v</b> if it's between <b>min</b> and <b>max</b>. Otherwise
29
* return <b>min</b> if <b>v</b> is smaller than <b>min</b>, or <b>max</b> if
30
* <b>b</b> is larger than <b>max</b>.
31
*
32
* Requires that <b>min</b> is no more than <b>max</b>. May evaluate any of
33
* its arguments more than once! */
34
#define CLAMP(min,v,max) \
35
( ((v) < (min)) ? (min) : \
36
((v) > (max)) ? (max) : \
37
(v) )
38
39
/** Give the absolute value of <b>x</b>, independent of its type. */
40
#define ABS(x) ( ((x)<0) ? -(x) : (x) )
41
42
#endif
/* !defined(TOR_INTMATH_CMP_H) */
Generated by
1.9.4