[PATCH] avfilter: avoid testing float == 0
This fixes the hypothetical case of rounding errors causing incorrect values to be used. Signed-off-by: Michael Niedermayer <michaelni@gmx.at> --- libavfilter/avfilter.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libavfilter/avfilter.c b/libavfilter/avfilter.c index 3f94dde..6c3cb05 100644 --- a/libavfilter/avfilter.c +++ b/libavfilter/avfilter.c @@ -994,7 +994,7 @@ static int ff_filter_frame_framed(AVFilterLink *link, AVFrame *frame) dstctx->var_values[VAR_T] = pts == AV_NOPTS_VALUE ? NAN : pts * av_q2d(link->time_base); dstctx->var_values[VAR_POS] = pos == -1 ? NAN : pos; - dstctx->is_disabled = !av_expr_eval(dstctx->enable, dstctx->var_values, NULL); + dstctx->is_disabled = fabs( av_expr_eval(dstctx->enable, dstctx->var_values, NULL) ) < 0.5; if (dstctx->is_disabled) filter_frame = dst->passthrough_filter_frame ? dst->passthrough_filter_frame : default_filter_frame; -- 1.7.9.5
On Thu, May 09, 2013 at 04:56:39PM +0200, Michael Niedermayer wrote:
This fixes the hypothetical case of rounding errors causing incorrect values to be used.
Signed-off-by: Michael Niedermayer <michaelni@gmx.at> --- libavfilter/avfilter.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/libavfilter/avfilter.c b/libavfilter/avfilter.c index 3f94dde..6c3cb05 100644 --- a/libavfilter/avfilter.c +++ b/libavfilter/avfilter.c @@ -994,7 +994,7 @@ static int ff_filter_frame_framed(AVFilterLink *link, AVFrame *frame) dstctx->var_values[VAR_T] = pts == AV_NOPTS_VALUE ? NAN : pts * av_q2d(link->time_base); dstctx->var_values[VAR_POS] = pos == -1 ? NAN : pos;
- dstctx->is_disabled = !av_expr_eval(dstctx->enable, dstctx->var_values, NULL); + dstctx->is_disabled = fabs( av_expr_eval(dstctx->enable, dstctx->var_values, NULL) ) < 0.5;
Why a so high value? isn't 0.001 more than enough? nit: remove spaces after ( and before ) -- Clément B.
On Thu, May 9, 2013 at 6:21 PM, Clément Bœsch <ubitux@gmail.com> wrote:
On Thu, May 09, 2013 at 04:56:39PM +0200, Michael Niedermayer wrote:
This fixes the hypothetical case of rounding errors causing incorrect values to be used.
Signed-off-by: Michael Niedermayer <michaelni@gmx.at> --- libavfilter/avfilter.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/libavfilter/avfilter.c b/libavfilter/avfilter.c index 3f94dde..6c3cb05 100644 --- a/libavfilter/avfilter.c +++ b/libavfilter/avfilter.c @@ -994,7 +994,7 @@ static int ff_filter_frame_framed(AVFilterLink *link, AVFrame *frame) dstctx->var_values[VAR_T] = pts == AV_NOPTS_VALUE ? NAN : pts * av_q2d(link->time_base); dstctx->var_values[VAR_POS] = pos == -1 ? NAN : pos;
- dstctx->is_disabled = !av_expr_eval(dstctx->enable, dstctx->var_values, NULL); + dstctx->is_disabled = fabs( av_expr_eval(dstctx->enable, dstctx->var_values, NULL) ) < 0.5;
Why a so high value? isn't 0.001 more than enough?
nit: remove spaces after ( and before )
There is even a constant supposed to be used for such comparisons, if a float is an "inaccurate zero", FLT_EPSILON or DBL_EPSILON, depending on the type.
On Thu, May 09, 2013 at 06:32:46PM +0200, Hendrik Leppkes wrote:
On Thu, May 9, 2013 at 6:21 PM, Clément Bœsch <ubitux@gmail.com> wrote:
On Thu, May 09, 2013 at 04:56:39PM +0200, Michael Niedermayer wrote:
This fixes the hypothetical case of rounding errors causing incorrect values to be used.
Signed-off-by: Michael Niedermayer <michaelni@gmx.at> --- libavfilter/avfilter.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/libavfilter/avfilter.c b/libavfilter/avfilter.c index 3f94dde..6c3cb05 100644 --- a/libavfilter/avfilter.c +++ b/libavfilter/avfilter.c @@ -994,7 +994,7 @@ static int ff_filter_frame_framed(AVFilterLink *link, AVFrame *frame) dstctx->var_values[VAR_T] = pts == AV_NOPTS_VALUE ? NAN : pts * av_q2d(link->time_base); dstctx->var_values[VAR_POS] = pos == -1 ? NAN : pos;
- dstctx->is_disabled = !av_expr_eval(dstctx->enable, dstctx->var_values, NULL); + dstctx->is_disabled = fabs( av_expr_eval(dstctx->enable, dstctx->var_values, NULL) ) < 0.5;
Why a so high value? isn't 0.001 more than enough?
nit: remove spaces after ( and before )
There is even a constant supposed to be used for such comparisons, if a float is an "inaccurate zero", FLT_EPSILON or DBL_EPSILON, depending on the type.
What i was trying to sugest with the patch was to change the API of the expression to 0 is false, 1 is true, and the check is more or less what is closer to either. Another posibility would be positive vs negative but that might be less intuitiv to use The 0 / not 0 distinction is flawed in floats, epsilon is not solving that. Theres nothing that keeps a rounding error of a complex expression smaller than epsilon except sheer luck [...] -- Michael GnuPG fingerprint: 9FF2128B147EF6730BADF133611EC787040B0FAB The worst form of inequality is to try to make unequal things equal. -- Aristotle
On Thu, May 09, 2013 at 04:56:39PM +0200, Michael Niedermayer wrote:
This fixes the hypothetical case of rounding errors causing incorrect values to be used.
Signed-off-by: Michael Niedermayer <michaelni@gmx.at> --- libavfilter/avfilter.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/libavfilter/avfilter.c b/libavfilter/avfilter.c index 3f94dde..6c3cb05 100644 --- a/libavfilter/avfilter.c +++ b/libavfilter/avfilter.c @@ -994,7 +994,7 @@ static int ff_filter_frame_framed(AVFilterLink *link, AVFrame *frame) dstctx->var_values[VAR_T] = pts == AV_NOPTS_VALUE ? NAN : pts * av_q2d(link->time_base); dstctx->var_values[VAR_POS] = pos == -1 ? NAN : pos;
- dstctx->is_disabled = !av_expr_eval(dstctx->enable, dstctx->var_values, NULL); + dstctx->is_disabled = fabs( av_expr_eval(dstctx->enable, dstctx->var_values, NULL) ) < 0.5; if (dstctx->is_disabled) filter_frame = dst->passthrough_filter_frame ? dst->passthrough_filter_frame : default_filter_frame;
spaces fixed patch approved by nevcairiel on IRC commit message made more verbose patch applied [...] -- Michael GnuPG fingerprint: 9FF2128B147EF6730BADF133611EC787040B0FAB He who knows, does not speak. He who speaks, does not know. -- Lao Tsu
participants (3)
-
Clément Bœsch -
Hendrik Leppkes -
Michael Niedermayer