From 02d009bc5c2dca3326c1a2551093c4bc3a67a6f7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kacper=20Michaj=C5=82ow?= Date: Tue, 17 Oct 2023 02:53:11 +0200 Subject: [PATCH] player/command: truncate anything < 1e-4 in pretty printer To avoid switching to scientific notation. Apparently it is "jarring" for some users. This preserves status quo from before 9dddfc4f where pretty printer were truncated to 3 decimal places. --- options/m_option.c | 7 ++++++- player/command.c | 4 ++-- 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/options/m_option.c b/options/m_option.c index 7d3222b1d3..458d38bafc 100644 --- a/options/m_option.c +++ b/options/m_option.c @@ -1028,7 +1028,12 @@ static char *print_double_7g(const m_option_t *opt, const void *val) double f = VAL(val); if (isnan(f)) return print_double(opt, val); - return talloc_asprintf(NULL, "%.7g", f); + // Truncate anything < 1e-4 to avoid switching to scientific notation + if (fabs(f) < 1e-4) { + return talloc_strdup(NULL, "0"); + } else { + return talloc_asprintf(NULL, "%.7g", f); + } } static void add_double(const m_option_t *opt, void *val, double add, bool wrap) diff --git a/player/command.c b/player/command.c index b2ebb86b18..bfacc04282 100644 --- a/player/command.c +++ b/player/command.c @@ -652,8 +652,8 @@ static int mp_property_avsync(void *ctx, struct m_property *prop, if (!mpctx->ao_chain || !mpctx->vo_chain) return M_PROPERTY_UNAVAILABLE; if (action == M_PROPERTY_PRINT) { - // Don't print small values resulting from calculation inaccuracies - if (fabs(mpctx->last_av_difference) < 1e-5) { + // Truncate anything < 1e-4 to avoid switching to scientific notation + if (fabs(mpctx->last_av_difference) < 1e-4) { *(char **)arg = talloc_strdup(NULL, "0"); } else { *(char **)arg = talloc_asprintf(NULL, "%+.2g", mpctx->last_av_difference);