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 @a what pointed value to upper bound @a limit. */
43 int_upper_bound(register int *what
, register int limit
)
45 if (*what
> limit
) *what
= limit
;
48 /** Limit @a what pointed value to lower bound @a limit. */
50 int_lower_bound(register int *what
, register int limit
)
52 if (*what
< limit
) *what
= limit
;
55 /** Limit @a what pointed value to lower bound @a lower_limit and to
56 * upper bound @a upper_limit. */
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 /** Swap values @a a and @a b, both of type @a type.
69 * This is supposed to evaluate at compile time, giving no performance hit. */
70 #define swap_values(type, a, b) \
72 type swap_register_ = (a); \
74 (b) = (swap_register_); \