From: Stefan BrĂ¼ns Date: Sat, 14 Jan 2017 19:48:08 +0000 (+0100) Subject: strutil: Fix sr_period_string output X-Git-Tag: libsigrok-0.5.0~139 X-Git-Url: https://sigrok.org/gitweb/?p=libsigrok.git;a=commitdiff_plain;h=a547531bf1be0d263a76c1ce53605d70d9a9740b strutil: Fix sr_period_string output The output was wrong for all frequencies but 1 Hz, 1 kHz, 1 MHz and 1 GHz. With this changes, the output may still be off due to rounding, but will be correct as to the shown accuracy. --- diff --git a/src/strutil.c b/src/strutil.c index fc6c7580..4b5b9ec7 100644 --- a/src/strutil.c +++ b/src/strutil.c @@ -369,13 +369,13 @@ SR_API char *sr_period_string(uint64_t frequency) o = g_malloc0(30 + 1); if (frequency >= SR_GHZ(1)) - r = snprintf(o, 30, "%" PRIu64 " ns", frequency / 1000000000); + r = snprintf(o, 30, "%lld ps", 1000000000000ull / frequency); else if (frequency >= SR_MHZ(1)) - r = snprintf(o, 30, "%" PRIu64 " us", frequency / 1000000); + r = snprintf(o, 30, "%lld ns", 1000000000ull / frequency); else if (frequency >= SR_KHZ(1)) - r = snprintf(o, 30, "%" PRIu64 " ms", frequency / 1000); + r = snprintf(o, 30, "%lld us", 1000000ull / frequency); else - r = snprintf(o, 30, "%" PRIu64 " s", frequency); + r = snprintf(o, 30, "%lld ms", 1000ull / frequency); if (r < 0) { /* Something went wrong... */