mirror of
https://github.com/RIOT-OS/RIOT.git
synced 2024-12-29 04:50:03 +01:00
sys/matstat: fix compilation with newlib
newlib (nano) does not support 64 bit types (neither in stdio nor with corresponding `PRI*64` macros). With GCC 13.2.1 (as shipped in Ubuntu 24.04.1 LTS), this triggers the following compilation error (even with `ENABLE_DEBUG == 0`): sys/matstat/matstat.c:57:21: error: expected ')' before 'PRIu64' 57 | DEBUG("Var: (%" PRIu64 " / (%" PRId32 " - 1)) = %" PRIu64 "\n", | ^~~~~~ This fixes the issue by falling back to printing 32 bit values when the `PRIu64` macro is not defined. A `!trunc` is appended when the 64 bit exceeds the range of [0:UINT32_MAX].
This commit is contained in:
parent
85172eda49
commit
54f4cd7cd1
@ -53,8 +53,15 @@ uint64_t matstat_variance(const matstat_state_t *state)
|
||||
return 0;
|
||||
}
|
||||
uint64_t variance = state->sum_sq / (state->count - 1);
|
||||
#ifdef PRIu64
|
||||
DEBUG("Var: (%" PRIu64 " / (%" PRId32 " - 1)) = %" PRIu64 "\n",
|
||||
state->sum_sq, state->count, variance);
|
||||
#else
|
||||
DEBUG("Var: (%" PRIu32 "%s / (%" PRId32 " - 1)) = %" PRIu32 "%s\n",
|
||||
(uint32_t)state->sum_sq, (state->sum_sq > UINT32_MAX) ? "!trunc " : "",
|
||||
state->count,
|
||||
(uint32_t)variance, (variance > UINT32_MAX) ? "!trunc " : "");
|
||||
#endif
|
||||
return variance;
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user