47 double (*
const *
funcs1)(
void *,
double a);
49 double (*
const *
funcs2)(
void *,
double a,
double b);
65 [
'y'-
'E']= { 8.271806125530276749e-25, 1e-24, -24 },
66 [
'z'-
'E']= { 8.4703294725430034e-22, 1e-21, -21 },
67 [
'a'-
'E']= { 8.6736173798840355e-19, 1e-18, -18 },
68 [
'f'-
'E']= { 8.8817841970012523e-16, 1e-15, -15 },
69 [
'p'-
'E']= { 9.0949470177292824e-13, 1e-12, -12 },
70 [
'n'-
'E']= { 9.3132257461547852e-10, 1e-9, -9 },
71 [
'u'-
'E']= { 9.5367431640625e-7, 1e-6, -6 },
72 [
'm'-
'E']= { 9.765625e-4, 1e-3, -3 },
73 [
'c'-
'E']= { 9.8431332023036951e-3, 1e-2, -2 },
74 [
'd'-
'E']= { 9.921256574801246e-2, 1e-1, -1 },
75 [
'h'-
'E']= { 1.0159366732596479e2, 1e2, 2 },
76 [
'k'-
'E']= { 1.024e3, 1e3, 3 },
77 [
'K'-
'E']= { 1.024e3, 1e3, 3 },
78 [
'M'-
'E']= { 1.048576e6, 1e6, 6 },
79 [
'G'-
'E']= { 1.073741824e9, 1e9, 9 },
80 [
'T'-
'E']= { 1.099511627776e12, 1e12, 12 },
81 [
'P'-
'E']= { 1.125899906842624e15, 1e15, 15 },
82 [
'E'-
'E']= { 1.152921504606847e18, 1e18, 18 },
83 [
'Z'-
'E']= { 1.1805916207174113e21, 1e21, 21 },
84 [
'Y'-
'E']= { 1.2089258196146292e24, 1e24, 24 },
101 if(numstr[0]==
'0' && (numstr[1]|0x20)==
'x') {
102 d = strtoul(numstr, &next, 16);
104 d =
strtod(numstr, &next);
107 if (next[0] ==
'd' && next[1] ==
'B') {
111 }
else if (*next >=
'E' && *next <=
'z') {
114 if (next[1] ==
'i') {
136 #define IS_IDENTIFIER_CHAR(c) ((c) - '0' <= 9U || (c) - 'a' <= 25U || (c) - 'A' <= 25U || (c) == '_')
141 for (i=0; prefix[i]; i++) {
142 if (prefix[i] != s[i])
return 0;
163 double (*
func2)(
void *, double, double);
211 av_log(p, level,
"%f\n", x);
217 r= r*1664525+1013904223;
219 return e->
value * (r * (1.0/UINT64_MAX));
228 double t = 1, d = 0, v;
232 double var0 = p->
var[
id];
233 for(i=0; i<1000; i++) {
247 double low = -1, high = -1, v, low_v = -DBL_MAX, high_v = DBL_MAX;
248 double var0 = p->
var[0];
250 for(i=-1; i<1024; i++) {
254 p->
var[0] = x_max*pow(0.9, i-255);
255 if (i&1) p->
var[0] *= -1;
256 if (i&2) p->
var[0] += low;
257 else p->
var[0] += high;
260 if (v<=0 && v>low_v) {
264 if (v>=0 && v<high_v) {
268 if (low>=0 && high>=0){
269 for (j=0; j<1000; j++) {
270 p->
var[0] = (low+high)*0.5;
271 if (low == p->
var[0] || high == p->
var[0])
274 if (v<=0) low = p->
var[0];
275 if (v>=0) high= p->
var[0];
285 return -low_v<high_v ? low : high;
291 case e_mod:
return e->
value * (d - floor((!CONFIG_FTRAPV || d2) ? d / d2 : d *
INFINITY) * d2);
293 case e_max:
return e->
value * (d > d2 ? d : d2);
294 case e_min:
return e->
value * (d < d2 ? d : d2);
295 case e_eq:
return e->
value * (d == d2 ? 1.0 : 0.0);
296 case e_gt:
return e->
value * (d > d2 ? 1.0 : 0.0);
297 case e_gte:
return e->
value * (d >= d2 ? 1.0 : 0.0);
298 case e_lt:
return e->
value * (d < d2 ? 1.0 : 0.0);
299 case e_lte:
return e->
value * (d <= d2 ? 1.0 : 0.0);
330 char *next = p->
s, *
s0 = p->
s;
366 p->
s= strchr(p->
s,
'(');
378 if (p->
s[0] !=
')') {
399 if (p->
s[0] !=
')') {
495 *sign= (*p->
s ==
'+') - (*p->
s ==
'-');
507 if (next != p->
s && next[0] ==
'd' && next[1] ==
'B') {
517 int sign, sign2, ret;
519 if ((ret =
parse_dB(&e0, p, &sign)) < 0)
524 if ((ret =
parse_dB(&e2, p, &sign2)) < 0) {
536 if (e0) e0->
value *= (sign|1);
548 while (p->
s[0]==
'*' || p->
s[0]==
'/') {
572 while (*p->
s ==
'+' || *p->
s ==
'-') {
600 while (*p->
s ==
';') {
658 const char *
const *const_names,
660 const char *
const *func2_names,
double (*
const *funcs2)(
void *,
double,
double),
661 int log_offset,
void *log_ctx)
723 const char *
const *const_names,
const double *const_values,
724 const char *
const *func1_names,
double (*
const *
funcs1)(
void *,
double),
725 const char *
const *func2_names,
double (*
const *funcs2)(
void *,
double,
double),
726 void *opaque,
int log_offset,
void *log_ctx)
729 int ret =
av_expr_parse(&e, s, const_names, func1_names,
funcs1, func2_names, funcs2, log_offset, log_ctx);
743 static const double const_values[] = {
749 static const char *
const const_names[] = {
755 int main(
int argc,
char **argv)
759 const char *
const *expr;
760 static const char *
const exprs[] = {
766 "1+(5-2)^(3-1)+1/2+sin(PI)-max(-2.2,-3.1)",
787 "bar + PI + E + 100f*2 + foo",
788 "13k + 12f - foo(1, 2)",
802 "st(0, 1); while(lte(ld(0), 100), st(1, ld(1)+ld(0));st(0, ld(0)+1)); ld(1)",
804 "st(1, 1); st(2, 2); st(0, 1); while(lte(ld(0),10), st(3, ld(1)+ld(2)); st(1, ld(2)); st(2, ld(3)); st(0, ld(0)+1)); ld(3)",
806 "st(0, 1); while(lte(ld(0),100), st(1, ld(1)+ld(0)); st(0, ld(0)+1))",
835 "ifnot(1, NaN) + if(0, 1)",
839 "taylor(eq(mod(ld(1),4),1)-eq(mod(ld(1),4),3), PI/2, 1)",
840 "root(sin(ld(0))-1, 2)",
841 "root(sin(ld(0))+6+sin(ld(0)/12)-log(ld(0)), 100)",
842 "7000000B*random(0)",
846 "gcd(30,55)*print(min(9,1))",
850 "between(10, -3, 10)",
851 "between(-4, -2, -1)",
859 for (expr = exprs; *expr; expr++) {
860 printf(
"Evaluating '%s'\n", *expr);
862 const_names, const_values,
865 printf(
"'%s' -> nan\n\n", *expr);
867 printf(
"'%s' -> %f\n\n", *expr, d);
871 const_names, const_values,
873 printf(
"%f == 12.7\n", d);
875 const_names, const_values,
877 printf(
"%f == 0.931322575\n", d);
879 if (argc > 1 && !strcmp(argv[1],
"-t")) {
880 for (i = 0; i < 1050; i++) {
883 const_names, const_values,
static int verify_expr(AVExpr *e)
const char *const * func1_names
static const char *const func1_names[]
#define LIBAVUTIL_VERSION_INT
static av_const int av_isspace(int c)
Locale-independent conversion of ASCII isspace.
int av_expr_parse(AVExpr **expr, const char *s, const char *const *const_names, const char *const *func1_names, double(*const *funcs1)(void *, double), const char *const *func2_names, double(*const *funcs2)(void *, double, double), int log_offset, void *log_ctx)
Parse an expression.
Macro definitions for various function/variable attributes.
static const struct @195 constants[]
static int parse_dB(AVExpr **e, Parser *p, int *sign)
static av_cold int end(AVCodecContext *avctx)
static int parse_expr(AVExpr **e, Parser *p)
static double(*const funcs1[])(void *, double)
double strtod(const char *, char **)
const char *const * const_names
double(* func1)(void *, double)
static int parse_pow(AVExpr **e, Parser *p, int *sign)
static int parse_factor(AVExpr **e, Parser *p)
high precision timer, useful to profile code
static int parse_subexpr(AVExpr **e, Parser *p)
double(* func2)(void *, double, double)
static const struct @194 si_prefixes['z'- 'E'+1]
int av_expr_parse_and_eval(double *d, const char *s, const char *const *const_names, const double *const_values, const char *const *func1_names, double(*const *funcs1)(void *, double), const char *const *func2_names, double(*const *funcs2)(void *, double, double), void *opaque, int log_offset, void *log_ctx)
Parse and evaluate an expression.
const double * const_values
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
#define IS_IDENTIFIER_CHAR(c)
const uint8_t ff_reverse[256]
static int parse_term(AVExpr **e, Parser *p)
int64_t av_gcd(int64_t a, int64_t b)
Compute the greatest common divisor of a and b.
common internal API header
static av_const double hypot(double x, double y)
static double etime(double v)
GLsizei GLboolean const GLfloat * value
static av_always_inline av_const double trunc(double x)
static int strmatch(const char *s, const char *prefix)
static int parse_primary(AVExpr **e, Parser *p)
#define FF_ARRAY_ELEMS(a)
int64_t av_gettime(void)
Get the current time in microseconds.
double av_strtod(const char *numstr, char **tail)
Parse the string in numstr and return its value as a double.
#define AV_LOG_INFO
Standard information.
static double eval_expr(Parser *p, AVExpr *e)
void av_expr_free(AVExpr *e)
Free a parsed expression previously created with av_expr_parse().
Describe the class of an AVClass context structure.
static const AVClass eval_class
double(*const funcs1)(void *, double a)
const char *const * func2_names
common internal and external API header
double(*const funcs2)(void *, double a, double b)
double av_expr_eval(AVExpr *e, const double *const_values, void *opaque)
Evaluate a previously parsed expression.
#define FF_QP2LAMBDA
factor to convert from H.263 QP to lambda
static AVExpr * make_eval_expr(int type, int value, AVExpr *p0, AVExpr *p1)
static av_always_inline double ff_exp10(double x)
Compute 10^x for floating point values.
int main(int argc, char **argv)
void * av_mallocz(size_t size)
Allocate a block of size bytes with alignment suitable for all memory accesses (including vectors if ...
simple arithmetic expression evaluator