1
0
mirror of https://github.com/RIOT-OS/RIOT.git synced 2024-12-29 04:50:03 +01:00

Merge pull request #18849 from benpicco/core-SIGNOF

core/macros: fix SIGNOF() macro when applied to size_t
This commit is contained in:
Marian Buschsieweke 2022-11-09 17:54:00 +01:00 committed by GitHub
commit e402e3f57a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 4 additions and 2 deletions

View File

@ -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
*/

View File

@ -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));