From 42df56ff08dc72af4bf0504aac5f9641b00e2948 Mon Sep 17 00:00:00 2001 From: Marian Buschsieweke Date: Fri, 12 Mar 2021 20:34:30 +0100 Subject: [PATCH] tests/periph_ptp_clock: fix bug in debug print The API doc of ptp_clock_adjust_speed says regarding the correction parameter: 1. A call with @p correction set to `0` restores the nominal clock speed. 2. A call with a positive value for @p correction speeds the clock up by `correction / (1 << 32)` (so up to ~50% for `INT32_MAX`). 3. A call with a negative value for @p correction slows the clock down by `-correction / (1 << 32)` (so up to 50% for `INT32_MIN`). So we need to divide by 2^32, not 2^32 - 1 (or `UINT32_MAX`). --- tests/periph_ptp_clock/main.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/tests/periph_ptp_clock/main.c b/tests/periph_ptp_clock/main.c index ef7a21d247..425573fcf1 100644 --- a/tests/periph_ptp_clock/main.c +++ b/tests/periph_ptp_clock/main.c @@ -67,7 +67,8 @@ static int test_speed_adjustment(const int32_t speed) print_str(" (~"); { int64_t tmp = speed * 100000ULL; - tmp /= UINT32_MAX; + /* trusting compiler to use arithmetic right shift, when available instead of division */ + tmp /= 1LL << 32; tmp += 100000ULL; char output[16]; print(output, fmt_s32_dfp(output, (int32_t)tmp, -3));