mirror of
https://github.com/RIOT-OS/RIOT.git
synced 2025-12-30 17:01:19 +01:00
Merge pull request #4311 from kaspar030/remove_div_u32_by_10
sys: div: remove div_u32_by_10() (and _mod_10())
This commit is contained in:
commit
127495b1b2
@ -77,34 +77,6 @@ static inline uint32_t div_u32_by_15625div512(uint32_t val)
|
||||
return ((uint64_t)(val) * 0x431bde83ul) >> (12 + 32 - 9);
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Integer divide val by 10
|
||||
*
|
||||
* @param[in] n dividend
|
||||
* @return (n / 10)
|
||||
*/
|
||||
static inline uint32_t div_u32_by_10(uint32_t n) {
|
||||
uint32_t q, r;
|
||||
q = (n >> 1) + (n >> 2);
|
||||
q = q + (q >> 4);
|
||||
q = q + (q >> 8);
|
||||
q = q + (q >> 16);
|
||||
q = q >> 3;
|
||||
r = n - (((q << 2) + q) << 1);
|
||||
return q + (r > 9);
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Modulo 10
|
||||
*
|
||||
* @param[in] n dividend
|
||||
* @return (n % 10)
|
||||
*/
|
||||
static inline uint32_t div_u32_mod_10(uint32_t n)
|
||||
{
|
||||
return n - (div_u32_by_10(n)*10);
|
||||
}
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
@ -79,34 +79,12 @@ static void test_div_u64_by_1000000(void)
|
||||
}
|
||||
}
|
||||
|
||||
static void test_div_u32_by_10(void)
|
||||
{
|
||||
for (unsigned i = 0; i < N_U32_VALS; i++) {
|
||||
DEBUG("Dividing %"PRIu32" by 10...\n", u32_test_values[i]);
|
||||
TEST_ASSERT_EQUAL_INT(
|
||||
div_u32_by_10(u32_test_values[i]),
|
||||
u32_test_values[i]/10);
|
||||
}
|
||||
}
|
||||
|
||||
static void test_div_u32_mod_10(void)
|
||||
{
|
||||
for (unsigned i = 0; i < N_U32_VALS; i++) {
|
||||
DEBUG("Calculating %"PRIu32" % 10...\n", u32_test_values[i]);
|
||||
TEST_ASSERT_EQUAL_INT(
|
||||
div_u32_mod_10(u32_test_values[i]),
|
||||
u32_test_values[i]%10);
|
||||
}
|
||||
}
|
||||
|
||||
Test *tests_div_tests(void)
|
||||
{
|
||||
EMB_UNIT_TESTFIXTURES(fixtures) {
|
||||
new_TestFixture(test_div_u64_by_15625),
|
||||
new_TestFixture(test_div_u32_by_15625div512),
|
||||
new_TestFixture(test_div_u64_by_1000000),
|
||||
new_TestFixture(test_div_u32_by_10),
|
||||
new_TestFixture(test_div_u32_mod_10),
|
||||
};
|
||||
|
||||
EMB_UNIT_TESTCALLER(div_tests, NULL, NULL, fixtures);
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user