1 #ifndef EL__UTIL_MATH_H
2 #define EL__UTIL_MATH_H
5 /* It's evil to include this directly, elinks.h includes it for you
6 * at the right time. */
9 /* These macros will evaluate twice their arguments.
10 * Ie. MIN(a+b, c+d) will do 3 additions...
11 * Please prefer to use int_min() and int_max() if possible. */
13 /* FreeBSD needs this. */
22 #define MIN(x, y) ((x) < (y) ? (x) : (y))
23 #define MAX(x, y) ((x) > (y) ? (x) : (y))
27 int_min(register int x
, register int y
)
34 int_max(register int x
, register int y
)
41 /* Limit @what pointed value to upper bound @limit. */
43 int_upper_bound(register int *what
, register int limit
)
45 if (*what
> limit
) *what
= limit
;
48 /* Limit @what pointed value to lower bound @limit. */
50 int_lower_bound(register int *what
, register int limit
)
52 if (*what
< limit
) *what
= limit
;
55 /* Limit @what pointed value to lower bound @lower_limit and to upper bound
58 int_bounds(register int *what
, register int lower_limit
,
59 register int upper_limit
)
61 if (*what
< lower_limit
)
63 else if (*what
> upper_limit
)
68 /* This is supposed to evaluate at compile time, giving no performance hit. */
69 #define swap_values(type, a, b) \
71 type swap_register_ = (a); \
73 (b) = (swap_register_); \