include: util: Add DIV_ROUND_CLOSEST helper

It's similar to DIV_ROUND_UP, but rounds to the nearest integer.
Some basic unit tests were introduced to check that it works as
intended.

Signed-off-by: Kornel Dulęba <mindal@semihalf.com>
This commit is contained in:
Kornel Dulęba 2023-07-17 08:36:52 +00:00 committed by Fabio Baltieri
commit 8fc913374f
3 changed files with 42 additions and 0 deletions

View file

@ -151,6 +151,11 @@ ZTEST(util_cxx, test_DIV_ROUND_UP)
run_DIV_ROUND_UP();
}
ZTEST(util_cxx, test_DIV_ROUND_CLOSEST)
{
run_DIV_ROUND_CLOSEST();
}
ZTEST_SUITE(util_cxx, NULL, NULL, NULL, NULL, NULL);
#if __cplusplus
@ -294,4 +299,9 @@ ZTEST(util_cc, test_DIV_ROUND_UP)
run_DIV_ROUND_UP();
}
ZTEST(util_cc, test_DIV_ROUND_CLOSEST)
{
run_DIV_ROUND_CLOSEST();
}
ZTEST_SUITE(util_cc, NULL, NULL, NULL, NULL, NULL);