Opened 22 months ago

Last modified 21 months ago

#9817 new defect

libavutil/eval.c "double" error comparison is equal to

Reported by: 张文兵 Owned by:
Priority: normal Component: avutil
Version: git-master Keywords:
Cc: 张文兵 Blocked By:
Blocking: Reproduced by developer: no
Analyzed by developer: no

Description

libavutil/eval.c
func eval_expr

        case e_between: {
            double d = eval_expr(p, e->param[0]);
            return e->value * (d >= eval_expr(p, e->param[1]) &&
                               d <= eval_expr(p, e->param[2]));
        }

......
                case e_eq:  return e->value * (d == d2 ? 1.0 : 0.0);
                case e_gte: return e->value * (d >= d2 ? 1.0 : 0.0);
                case e_lte: return e->value * (d <= d2 ? 1.0 : 0.0);

Change History (4)

comment:1 by Gyan, 22 months ago

Can you elaborate what the bug is?

in reply to:  1 comment:2 by 张文兵, 22 months ago

Replying to Gyan:

Can you elaborate what the bug is?

Two "doubles" cannot be used directly as equals, because the precision problem will cause two values that look the same to be unequal.

ffmpeg -i <input> -vf "fps=fps=25,settb=AVTB,setpts=PTS-STARTPTS,delogo=x=432:y=1:w=173:h=463:enable='between(t,2376.760000,2381.400000)'" -s 1920x1080 -y -pix_fmt yuv420p -c:v libx264 -preset ultrafast -r 25.000000 -acodec aac -strict -2 -ac 2 -ar 48000 <output>

"between(t,2376.760000,2381.400000)'" cannot correctly determine 2376.760000

Here is how to reproduce.

#include <inttypes.h>
#include <math.h>
#include <stdio.h>

int main(void) {
    int64_t pts = 2376760000;
    double t = pts * (1 / (double)(1000000));

    double myt = 2376.76;

    printf("t:%.32f myt:%.32f pts:%lld %d\n",
           t,
           myt,
           pts,
           myt == t);
    return 0;
}

// int main(void) {
//     int64_t pts = 59419;
//     double t = pts * (1 / (double)(25));

//     double myt = 2376.76;

//     printf("t:%.32f myt:%.32f pts:%lld %d\n",
//            t,
//            myt,
//            pts,
//            myt == t);
//     return 0;
// }
Last edited 21 months ago by 张文兵 (previous) (diff)

comment:3 by Elon Musk, 22 months ago

can be changed by adding comparisions using DBL_EPSILON

comment:4 by Marton Balint, 21 months ago

Priority: importantnormal
Note: See TracTickets for help on using tickets.