Skip to content

Commit

Permalink
Merge pull request #18849 from benpicco/core-SIGNOF
Browse files Browse the repository at this point in the history
core/macros: fix SIGNOF() macro when applied to size_t
  • Loading branch information
maribu authored Nov 9, 2022
2 parents 15448bf + 8f8bb6c commit e402e3f
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 2 deletions.
2 changes: 1 addition & 1 deletion core/include/macros/math.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ extern "C" {
unsigned int: 1, \
unsigned long: 1, \
unsigned long long: 1, \
default: (long long)(a) < 0 ? -1 : 1)
default: ((a) <= 0 ? ((a) == 0 ? 1L : -1L ): 1L))
/**
* @brief Calculates @p a/ @p b with arithmetic rounding
*/
Expand Down
4 changes: 3 additions & 1 deletion tests/unittests/tests-core/tests-core-macros.c
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,9 @@ static void test_math_signof(void)

static void test_math_div_round(void)
{
TEST_ASSERT_EQUAL_INT(3, DIV_ROUND(20, 7));
size_t a = 20;

TEST_ASSERT_EQUAL_INT(3, DIV_ROUND(a, 7));
TEST_ASSERT_EQUAL_INT(3, DIV_ROUND(21, 7));
TEST_ASSERT_EQUAL_INT(3, DIV_ROUND(22, 7));
TEST_ASSERT_EQUAL_INT(0, DIV_ROUND(1, UINT32_MAX));
Expand Down

0 comments on commit e402e3f

Please sign in to comment.