static inline uint32_t ntohl(uint32_t val) __attribute__ ((alias ("byte_swap_32")));
static inline uint32_t htonl(uint32_t val) __attribute__ ((alias ("byte_swap_32")));
/* Short versions */
-static inline uint32_t ntohs(uint32_t val) __attribute__ ((alias ("byte_swap_16")));
-static inline uint32_t htons(uint32_t val) __attribute__ ((alias ("byte_swap_16")));
+static inline uint32_t ntohs(uint16_t val) __attribute__ ((alias ("byte_swap_16")));
+static inline uint32_t htons(uint16_t val) __attribute__ ((alias ("byte_swap_16")));
/* MIN and MAX */
#define MAX(a, b) (((a) > (b)) ? (a) : (b))
+/* abs
+ * Return absolute value of signed integer
+ */
+static inline uint32_t abs(int32_t val)
+{
+ return val < 0 ? -val : val;
+}
+
+
+/* constrain
+ * Return the value if it is between min and max
+ * Return min if the value is below min, or max if the value is above max
+ */
+static inline uint32_t constrain(int32_t val, int32_t min, int32_t max)
+{
+ return val < min ? min : val > max ? max : val;
+}
+
#endif /* LIB_UTILS_H */