mirror of https://git.ffmpeg.org/ffmpeg.git
eval: Allow specifying the variable id.
Reviewed-by: Nicolas George <nicolas.george@normalesup.org> Signed-off-by: Michael Niedermayer <michaelni@gmx.at>
This commit is contained in:
parent
02670762d2
commit
923092697a
|
@ -107,9 +107,10 @@ the evaluation of @var{y}, return 0 otherwise.
|
||||||
Evaluate @var{x}, and if the result is zero return the result of the
|
Evaluate @var{x}, and if the result is zero return the result of the
|
||||||
evaluation of @var{y}, return 0 otherwise.
|
evaluation of @var{y}, return 0 otherwise.
|
||||||
|
|
||||||
@item taylor(expr, x)
|
@item taylor(expr, x) taylor(expr, x, id)
|
||||||
Evaluate a taylor series at x.
|
Evaluate a taylor series at x.
|
||||||
expr represents the LD(0)-th derivates of f(x) at 0.
|
expr represents the LD(id)-th derivates of f(x) at 0. If id is not specified
|
||||||
|
then 0 is assumed.
|
||||||
note, when you have the derivatives at y instead of 0
|
note, when you have the derivatives at y instead of 0
|
||||||
taylor(expr, x-y) can be used
|
taylor(expr, x-y) can be used
|
||||||
When the series does not converge the results are undefined.
|
When the series does not converge the results are undefined.
|
||||||
|
|
|
@ -184,18 +184,19 @@ static double eval_expr(Parser *p, AVExpr *e)
|
||||||
case e_taylor: {
|
case e_taylor: {
|
||||||
double t = 1, d = 0, v;
|
double t = 1, d = 0, v;
|
||||||
double x = eval_expr(p, e->param[1]);
|
double x = eval_expr(p, e->param[1]);
|
||||||
|
int id = e->param[2] ? av_clip(eval_expr(p, e->param[2]), 0, VARS-1) : 0;
|
||||||
int i;
|
int i;
|
||||||
double var0 = p->var[0];
|
double var0 = p->var[id];
|
||||||
for(i=0; i<1000; i++) {
|
for(i=0; i<1000; i++) {
|
||||||
double ld = d;
|
double ld = d;
|
||||||
p->var[0] = i;
|
p->var[id] = i;
|
||||||
v = eval_expr(p, e->param[0]);
|
v = eval_expr(p, e->param[0]);
|
||||||
d += t*v;
|
d += t*v;
|
||||||
if(ld==d && v)
|
if(ld==d && v)
|
||||||
break;
|
break;
|
||||||
t *= x / (i+1);
|
t *= x / (i+1);
|
||||||
}
|
}
|
||||||
p->var[0] = var0;
|
p->var[id] = var0;
|
||||||
return d;
|
return d;
|
||||||
}
|
}
|
||||||
default: {
|
default: {
|
||||||
|
@ -523,6 +524,9 @@ static int verify_expr(AVExpr *e)
|
||||||
case e_not:
|
case e_not:
|
||||||
case e_random:
|
case e_random:
|
||||||
return verify_expr(e->param[0]) && !e->param[2];
|
return verify_expr(e->param[0]) && !e->param[2];
|
||||||
|
case e_taylor:
|
||||||
|
return verify_expr(e->param[0]) && verify_expr(e->param[1])
|
||||||
|
&& (!e->param[2] || verify_expr(e->param[2]));
|
||||||
default: return verify_expr(e->param[0]) && verify_expr(e->param[1]) && !e->param[2];
|
default: return verify_expr(e->param[0]) && verify_expr(e->param[1]) && !e->param[2];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -722,7 +726,7 @@ int main(int argc, char **argv)
|
||||||
"ifnot(0, 23)",
|
"ifnot(0, 23)",
|
||||||
"ifnot(1, NaN) + if(0, 1)",
|
"ifnot(1, NaN) + if(0, 1)",
|
||||||
"taylor(1, 1)",
|
"taylor(1, 1)",
|
||||||
"taylor(eq(mod(ld(0),4),1)-eq(mod(ld(0),4),3), PI/2)",
|
"taylor(eq(mod(ld(1),4),1)-eq(mod(ld(1),4),3), PI/2, 1)",
|
||||||
NULL
|
NULL
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -172,8 +172,8 @@ Evaluating 'ifnot(1, NaN) + if(0, 1)'
|
||||||
Evaluating 'taylor(1, 1)'
|
Evaluating 'taylor(1, 1)'
|
||||||
'taylor(1, 1)' -> 2.718282
|
'taylor(1, 1)' -> 2.718282
|
||||||
|
|
||||||
Evaluating 'taylor(eq(mod(ld(0),4),1)-eq(mod(ld(0),4),3), PI/2)'
|
Evaluating 'taylor(eq(mod(ld(1),4),1)-eq(mod(ld(1),4),3), PI/2, 1)'
|
||||||
'taylor(eq(mod(ld(0),4),1)-eq(mod(ld(0),4),3), PI/2)' -> 1.000000
|
'taylor(eq(mod(ld(1),4),1)-eq(mod(ld(1),4),3), PI/2, 1)' -> 1.000000
|
||||||
|
|
||||||
12.700000 == 12.7
|
12.700000 == 12.7
|
||||||
0.931323 == 0.931322575
|
0.931323 == 0.931322575
|
||||||
|
|
Loading…
Reference in New Issue