diff options
author | Kacper Michajłow <kasper93@gmail.com> | 2023-09-17 17:06:50 +0200 |
---|---|---|
committer | Niklas Haas <github-daiK1o@haasn.dev> | 2023-10-14 12:30:46 +0200 |
commit | 9dddfc4fcce5f1ce0978d6bc3a964fdc6da48e05 (patch) | |
tree | e5099d96c95a131ca072524a0b44c04b320f7a1f | |
parent | 52fc3784942d572a790acf59144977160ac685ed (diff) | |
download | mpv-9dddfc4fcce5f1ce0978d6bc3a964fdc6da48e05.tar.bz2 mpv-9dddfc4fcce5f1ce0978d6bc3a964fdc6da48e05.tar.xz |
player/command: change how floating point number are printed
Use "%.7g" to show 7 significant digits. Removes the trailing zeros, and
in general makes it more readable, than fixed 3 decimal digits.
For avsync use "%+.2g" to add plus sign, similar to display-sync
values.
-rw-r--r-- | options/m_option.c | 10 | ||||
-rw-r--r-- | player/command.c | 9 |
2 files changed, 12 insertions, 7 deletions
diff --git a/options/m_option.c b/options/m_option.c index 892c38b422..7d3222b1d3 100644 --- a/options/m_option.c +++ b/options/m_option.c @@ -1023,12 +1023,12 @@ static char *print_double(const m_option_t *opt, const void *val) return talloc_asprintf(NULL, "%f", f); } -static char *print_double_f3(const m_option_t *opt, const void *val) +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, "%.3f", f); + return talloc_asprintf(NULL, "%.7g", f); } static void add_double(const m_option_t *opt, void *val, double add, bool wrap) @@ -1100,7 +1100,7 @@ const m_option_type_t m_option_type_double = { .size = sizeof(double), .parse = parse_double, .print = print_double, - .pretty_print = print_double_f3, + .pretty_print = print_double_7g, .copy = copy_opt, .add = add_double, .multiply = multiply_double, @@ -1126,7 +1126,7 @@ const m_option_type_t m_option_type_aspect = { .flags = M_OPT_TYPE_CHOICE | M_OPT_TYPE_USES_RANGE, .parse = parse_double_aspect, .print = print_double, - .pretty_print = print_double_f3, + .pretty_print = print_double_7g, .copy = copy_opt, .add = add_double, .multiply = multiply_double, @@ -1157,7 +1157,7 @@ static char *print_float(const m_option_t *opt, const void *val) static char *print_float_f3(const m_option_t *opt, const void *val) { double tmp = VAL(val); - return print_double_f3(opt, &tmp); + return print_double_7g(opt, &tmp); } static void add_float(const m_option_t *opt, void *val, double add, bool wrap) diff --git a/player/command.c b/player/command.c index 136609ccbc..3c069072f3 100644 --- a/player/command.c +++ b/player/command.c @@ -419,7 +419,7 @@ static int mp_property_av_speed_correction(void *ctx, struct m_property *prop, } if (action == M_PROPERTY_PRINT) { - *(char **)arg = talloc_asprintf(NULL, "%+.05f%%", (val - 1) * 100); + *(char **)arg = talloc_asprintf(NULL, "%+.3g%%", (val - 1) * 100); return M_PROPERTY_OK; } @@ -652,7 +652,12 @@ 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) { - *(char **)arg = talloc_asprintf(NULL, "%7.3f", mpctx->last_av_difference); + // Don't print small values resulting from calculation inaccuracies + if (fabs(mpctx->last_av_difference) < 1e-5) { + *(char **)arg = talloc_strdup(NULL, "0"); + } else { + *(char **)arg = talloc_asprintf(NULL, "%+.2g", mpctx->last_av_difference); + } return M_PROPERTY_OK; } return m_property_double_ro(action, arg, mpctx->last_av_difference); |