[FFmpeg-devel] [PATCH] avutil/timestamp: avoid using INFINITY for log10 result in av_ts_make_time_string2

Michael Niedermayer michael at niedermayer.cc
Tue Aug 27 17:04:12 EEST 2024


On Tue, Aug 27, 2024 at 02:03:37AM +0200, Marton Balint wrote:
> Using INFINITY can cause issues with -ffast-math, and since we only use this
> value to decide the formatting, we can just as easily use 0 for log10 of zero.
> 
> Signed-off-by: Marton Balint <cus at passwd.hu>
> ---
>  libavutil/timestamp.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/libavutil/timestamp.c b/libavutil/timestamp.c
> index 6c231a517d..be4540d4c8 100644
> --- a/libavutil/timestamp.c
> +++ b/libavutil/timestamp.c
> @@ -24,7 +24,7 @@ char *av_ts_make_time_string2(char *buf, int64_t ts, AVRational tb)
>          snprintf(buf, AV_TS_MAX_STRING_SIZE, "NOPTS");
>      } else {
>          double val = av_q2d(tb) * ts;
> -        double log = (fpclassify(val) == FP_ZERO ? -INFINITY : floor(log10(fabs(val))));
> +        double log = (fpclassify(val) == FP_ZERO ? 0 : floor(log10(fabs(val))));
>          int precision = (isfinite(log) && log < 0) ? -log + 5 : 6;

please add a comment as log(0) = 0 is not correct (in the general case)
otherwise LGTM

thx

[...]
-- 
Michael     GnuPG fingerprint: 9FF2128B147EF6730BADF133611EC787040B0FAB

No human being will ever know the Truth, for even if they happen to say it
by chance, they would not even known they had done so. -- Xenophanes
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 195 bytes
Desc: not available
URL: <https://ffmpeg.org/pipermail/ffmpeg-devel/attachments/20240827/dcddf2d9/attachment.sig>


More information about the ffmpeg-devel mailing list