/*
- * Copyright (c) 2008 Nicira, Inc.
+ * Copyright (c) 2008, 2012 Nicira, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
return x >= y ? x - y : 0;
}
-/* Saturating multiplication: overflow yields UINT_MAX. */
+/* Saturating multiplication of "unsigned int"s: overflow yields UINT_MAX. */
+#define SAT_MUL(X, Y) \
+ ((Y) == 0 ? 0 \
+ : (X) <= UINT_MAX / (Y) ? (unsigned int) (X) * (unsigned int) (Y) \
+ : UINT_MAX)
static inline unsigned int
sat_mul(unsigned int x, unsigned int y)
{
- return (!y ? 0
- : x <= UINT_MAX / y ? x * y
- : UINT_MAX);
+ return SAT_MUL(x, y);
}
#endif /* sat-math.h */