Skip to content

Commit 77a2946

Browse files
committed
sys: util: Add SIGN macro
Add a macro to determine the sign of a value. Signed-off-by: Phi Bang Nguyen <[email protected]> Signed-off-by: Trung Hieu Le <[email protected]>
1 parent 6cc7bdb commit 77a2946

File tree

1 file changed

+11
-0
lines changed

1 file changed

+11
-0
lines changed

include/zephyr/sys/util.h

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1027,6 +1027,17 @@ static inline size_t sys_count_bits(const void *value, size_t len)
10271027
return cnt;
10281028
}
10291029

1030+
/**
1031+
* @brief Returns the sign of a number.
1032+
*
1033+
* @param x The input value to determine the sign
1034+
*
1035+
* @retval 1 if x is positive
1036+
* @retval -1 if x is negative
1037+
* @retval 0 if x is zero
1038+
*/
1039+
#define SIGN(x) ((x > 0) - (x < 0))
1040+
10301041
#ifdef __cplusplus
10311042
}
10321043
#endif

0 commit comments

Comments
 (0)