You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

667 lines
20KB

  1. /*
  2. * Copyright (c) 2002-2006 Michael Niedermayer <michaelni@gmx.at>
  3. * Copyright (c) 2006 Oded Shimon <ods15@ods15.dyndns.org>
  4. *
  5. * This file is part of FFmpeg.
  6. *
  7. * FFmpeg is free software; you can redistribute it and/or
  8. * modify it under the terms of the GNU Lesser General Public
  9. * License as published by the Free Software Foundation; either
  10. * version 2.1 of the License, or (at your option) any later version.
  11. *
  12. * FFmpeg is distributed in the hope that it will be useful,
  13. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  15. * Lesser General Public License for more details.
  16. *
  17. * You should have received a copy of the GNU Lesser General Public
  18. * License along with FFmpeg; if not, write to the Free Software
  19. * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  20. */
  21. /**
  22. * @file
  23. * simple arithmetic expression evaluator.
  24. *
  25. * see http://joe.hotchkiss.com/programming/eval/eval.html
  26. */
  27. #include "libavutil/avutil.h"
  28. #include "eval.h"
  29. typedef struct Parser {
  30. const AVClass *class;
  31. int stack_index;
  32. char *s;
  33. const double *const_values;
  34. const char * const *const_names; // NULL terminated
  35. double (* const *funcs1)(void *, double a); // NULL terminated
  36. const char * const *func1_names; // NULL terminated
  37. double (* const *funcs2)(void *, double a, double b); // NULL terminated
  38. const char * const *func2_names; // NULL terminated
  39. void *opaque;
  40. int log_offset;
  41. void *log_ctx;
  42. #define VARS 10
  43. double var[VARS];
  44. } Parser;
  45. static const AVClass class = { "Eval", av_default_item_name, NULL, LIBAVUTIL_VERSION_INT, offsetof(Parser,log_offset), offsetof(Parser,log_ctx) };
  46. static const int8_t si_prefixes['z' - 'E' + 1] = {
  47. ['y'-'E']= -24,
  48. ['z'-'E']= -21,
  49. ['a'-'E']= -18,
  50. ['f'-'E']= -15,
  51. ['p'-'E']= -12,
  52. ['n'-'E']= - 9,
  53. ['u'-'E']= - 6,
  54. ['m'-'E']= - 3,
  55. ['c'-'E']= - 2,
  56. ['d'-'E']= - 1,
  57. ['h'-'E']= 2,
  58. ['k'-'E']= 3,
  59. ['K'-'E']= 3,
  60. ['M'-'E']= 6,
  61. ['G'-'E']= 9,
  62. ['T'-'E']= 12,
  63. ['P'-'E']= 15,
  64. ['E'-'E']= 18,
  65. ['Z'-'E']= 21,
  66. ['Y'-'E']= 24,
  67. };
  68. double av_strtod(const char *numstr, char **tail)
  69. {
  70. double d;
  71. char *next;
  72. d = strtod(numstr, &next);
  73. /* if parsing succeeded, check for and interpret postfixes */
  74. if (next!=numstr) {
  75. if (*next >= 'E' && *next <= 'z') {
  76. int e= si_prefixes[*next - 'E'];
  77. if (e) {
  78. if (next[1] == 'i') {
  79. d*= pow( 2, e/0.3);
  80. next+=2;
  81. } else {
  82. d*= pow(10, e);
  83. next++;
  84. }
  85. }
  86. }
  87. if (*next=='B') {
  88. d*=8;
  89. next++;
  90. }
  91. }
  92. /* if requested, fill in tail with the position after the last parsed
  93. character */
  94. if (tail)
  95. *tail = next;
  96. return d;
  97. }
  98. #define IS_IDENTIFIER_CHAR(c) ((c) - '0' <= 9U || (c) - 'a' <= 25U || (c) - 'A' <= 25U || (c) == '_')
  99. static int strmatch(const char *s, const char *prefix)
  100. {
  101. int i;
  102. for (i=0; prefix[i]; i++) {
  103. if (prefix[i] != s[i]) return 0;
  104. }
  105. /* return 1 only if the s identifier is terminated */
  106. return !IS_IDENTIFIER_CHAR(s[i]);
  107. }
  108. struct AVExpr {
  109. enum {
  110. e_value, e_const, e_func0, e_func1, e_func2,
  111. e_squish, e_gauss, e_ld, e_isnan,
  112. e_mod, e_max, e_min, e_eq, e_gt, e_gte,
  113. e_pow, e_mul, e_div, e_add,
  114. e_last, e_st, e_while, e_floor, e_ceil, e_trunc,
  115. e_sqrt,
  116. } type;
  117. double value; // is sign in other types
  118. union {
  119. int const_index;
  120. double (*func0)(double);
  121. double (*func1)(void *, double);
  122. double (*func2)(void *, double, double);
  123. } a;
  124. struct AVExpr *param[2];
  125. };
  126. static double eval_expr(Parser *p, AVExpr *e)
  127. {
  128. switch (e->type) {
  129. case e_value: return e->value;
  130. case e_const: return e->value * p->const_values[e->a.const_index];
  131. case e_func0: return e->value * e->a.func0(eval_expr(p, e->param[0]));
  132. case e_func1: return e->value * e->a.func1(p->opaque, eval_expr(p, e->param[0]));
  133. case e_func2: return e->value * e->a.func2(p->opaque, eval_expr(p, e->param[0]), eval_expr(p, e->param[1]));
  134. case e_squish: return 1/(1+exp(4*eval_expr(p, e->param[0])));
  135. case e_gauss: { double d = eval_expr(p, e->param[0]); return exp(-d*d/2)/sqrt(2*M_PI); }
  136. case e_ld: return e->value * p->var[av_clip(eval_expr(p, e->param[0]), 0, VARS-1)];
  137. case e_isnan: return e->value * !!isnan(eval_expr(p, e->param[0]));
  138. case e_floor: return e->value * floor(eval_expr(p, e->param[0]));
  139. case e_ceil : return e->value * ceil (eval_expr(p, e->param[0]));
  140. case e_trunc: return e->value * trunc(eval_expr(p, e->param[0]));
  141. case e_sqrt: return e->value * sqrt (eval_expr(p, e->param[0]));
  142. case e_while: {
  143. double d = NAN;
  144. while (eval_expr(p, e->param[0]))
  145. d=eval_expr(p, e->param[1]);
  146. return d;
  147. }
  148. default: {
  149. double d = eval_expr(p, e->param[0]);
  150. double d2 = eval_expr(p, e->param[1]);
  151. switch (e->type) {
  152. case e_mod: return e->value * (d - floor(d/d2)*d2);
  153. case e_max: return e->value * (d > d2 ? d : d2);
  154. case e_min: return e->value * (d < d2 ? d : d2);
  155. case e_eq: return e->value * (d == d2 ? 1.0 : 0.0);
  156. case e_gt: return e->value * (d > d2 ? 1.0 : 0.0);
  157. case e_gte: return e->value * (d >= d2 ? 1.0 : 0.0);
  158. case e_pow: return e->value * pow(d, d2);
  159. case e_mul: return e->value * (d * d2);
  160. case e_div: return e->value * (d / d2);
  161. case e_add: return e->value * (d + d2);
  162. case e_last:return e->value * d2;
  163. case e_st : return e->value * (p->var[av_clip(d, 0, VARS-1)]= d2);
  164. }
  165. }
  166. }
  167. return NAN;
  168. }
  169. static int parse_expr(AVExpr **e, Parser *p);
  170. void av_expr_free(AVExpr *e)
  171. {
  172. if (!e) return;
  173. av_expr_free(e->param[0]);
  174. av_expr_free(e->param[1]);
  175. av_freep(&e);
  176. }
  177. static int parse_primary(AVExpr **e, Parser *p)
  178. {
  179. AVExpr *d = av_mallocz(sizeof(AVExpr));
  180. char *next = p->s, *s0 = p->s;
  181. int ret, i;
  182. if (!d)
  183. return AVERROR(ENOMEM);
  184. /* number */
  185. d->value = av_strtod(p->s, &next);
  186. if (next != p->s) {
  187. d->type = e_value;
  188. p->s= next;
  189. *e = d;
  190. return 0;
  191. }
  192. d->value = 1;
  193. /* named constants */
  194. for (i=0; p->const_names && p->const_names[i]; i++) {
  195. if (strmatch(p->s, p->const_names[i])) {
  196. p->s+= strlen(p->const_names[i]);
  197. d->type = e_const;
  198. d->a.const_index = i;
  199. *e = d;
  200. return 0;
  201. }
  202. }
  203. p->s= strchr(p->s, '(');
  204. if (p->s==NULL) {
  205. av_log(p, AV_LOG_ERROR, "Undefined constant or missing '(' in '%s'\n", s0);
  206. p->s= next;
  207. av_expr_free(d);
  208. return AVERROR(EINVAL);
  209. }
  210. p->s++; // "("
  211. if (*next == '(') { // special case do-nothing
  212. av_freep(&d);
  213. if ((ret = parse_expr(&d, p)) < 0)
  214. return ret;
  215. if (p->s[0] != ')') {
  216. av_log(p, AV_LOG_ERROR, "Missing ')' in '%s'\n", s0);
  217. av_expr_free(d);
  218. return AVERROR(EINVAL);
  219. }
  220. p->s++; // ")"
  221. *e = d;
  222. return 0;
  223. }
  224. if ((ret = parse_expr(&(d->param[0]), p)) < 0) {
  225. av_expr_free(d);
  226. return ret;
  227. }
  228. if (p->s[0]== ',') {
  229. p->s++; // ","
  230. parse_expr(&d->param[1], p);
  231. }
  232. if (p->s[0] != ')') {
  233. av_log(p, AV_LOG_ERROR, "Missing ')' or too many args in '%s'\n", s0);
  234. av_expr_free(d);
  235. return AVERROR(EINVAL);
  236. }
  237. p->s++; // ")"
  238. d->type = e_func0;
  239. if (strmatch(next, "sinh" )) d->a.func0 = sinh;
  240. else if (strmatch(next, "cosh" )) d->a.func0 = cosh;
  241. else if (strmatch(next, "tanh" )) d->a.func0 = tanh;
  242. else if (strmatch(next, "sin" )) d->a.func0 = sin;
  243. else if (strmatch(next, "cos" )) d->a.func0 = cos;
  244. else if (strmatch(next, "tan" )) d->a.func0 = tan;
  245. else if (strmatch(next, "atan" )) d->a.func0 = atan;
  246. else if (strmatch(next, "asin" )) d->a.func0 = asin;
  247. else if (strmatch(next, "acos" )) d->a.func0 = acos;
  248. else if (strmatch(next, "exp" )) d->a.func0 = exp;
  249. else if (strmatch(next, "log" )) d->a.func0 = log;
  250. else if (strmatch(next, "abs" )) d->a.func0 = fabs;
  251. else if (strmatch(next, "squish")) d->type = e_squish;
  252. else if (strmatch(next, "gauss" )) d->type = e_gauss;
  253. else if (strmatch(next, "mod" )) d->type = e_mod;
  254. else if (strmatch(next, "max" )) d->type = e_max;
  255. else if (strmatch(next, "min" )) d->type = e_min;
  256. else if (strmatch(next, "eq" )) d->type = e_eq;
  257. else if (strmatch(next, "gte" )) d->type = e_gte;
  258. else if (strmatch(next, "gt" )) d->type = e_gt;
  259. else if (strmatch(next, "lte" )) { AVExpr *tmp = d->param[1]; d->param[1] = d->param[0]; d->param[0] = tmp; d->type = e_gt; }
  260. else if (strmatch(next, "lt" )) { AVExpr *tmp = d->param[1]; d->param[1] = d->param[0]; d->param[0] = tmp; d->type = e_gte; }
  261. else if (strmatch(next, "ld" )) d->type = e_ld;
  262. else if (strmatch(next, "isnan" )) d->type = e_isnan;
  263. else if (strmatch(next, "st" )) d->type = e_st;
  264. else if (strmatch(next, "while" )) d->type = e_while;
  265. else if (strmatch(next, "floor" )) d->type = e_floor;
  266. else if (strmatch(next, "ceil" )) d->type = e_ceil;
  267. else if (strmatch(next, "trunc" )) d->type = e_trunc;
  268. else if (strmatch(next, "sqrt" )) d->type = e_sqrt;
  269. else {
  270. for (i=0; p->func1_names && p->func1_names[i]; i++) {
  271. if (strmatch(next, p->func1_names[i])) {
  272. d->a.func1 = p->funcs1[i];
  273. d->type = e_func1;
  274. *e = d;
  275. return 0;
  276. }
  277. }
  278. for (i=0; p->func2_names && p->func2_names[i]; i++) {
  279. if (strmatch(next, p->func2_names[i])) {
  280. d->a.func2 = p->funcs2[i];
  281. d->type = e_func2;
  282. *e = d;
  283. return 0;
  284. }
  285. }
  286. av_log(p, AV_LOG_ERROR, "Unknown function in '%s'\n", s0);
  287. av_expr_free(d);
  288. return AVERROR(EINVAL);
  289. }
  290. *e = d;
  291. return 0;
  292. }
  293. static AVExpr *new_eval_expr(int type, int value, AVExpr *p0, AVExpr *p1)
  294. {
  295. AVExpr *e = av_mallocz(sizeof(AVExpr));
  296. if (!e)
  297. return NULL;
  298. e->type =type ;
  299. e->value =value ;
  300. e->param[0] =p0 ;
  301. e->param[1] =p1 ;
  302. return e;
  303. }
  304. static int parse_pow(AVExpr **e, Parser *p, int *sign)
  305. {
  306. *sign= (*p->s == '+') - (*p->s == '-');
  307. p->s += *sign&1;
  308. return parse_primary(e, p);
  309. }
  310. static int parse_factor(AVExpr **e, Parser *p)
  311. {
  312. int sign, sign2, ret;
  313. AVExpr *e0, *e1, *e2;
  314. if ((ret = parse_pow(&e0, p, &sign)) < 0)
  315. return ret;
  316. while(p->s[0]=='^'){
  317. e1 = e0;
  318. p->s++;
  319. if ((ret = parse_pow(&e2, p, &sign2)) < 0) {
  320. av_expr_free(e1);
  321. return ret;
  322. }
  323. e0 = new_eval_expr(e_pow, 1, e1, e2);
  324. if (!e0) {
  325. av_expr_free(e1);
  326. av_expr_free(e2);
  327. return AVERROR(ENOMEM);
  328. }
  329. if (e0->param[1]) e0->param[1]->value *= (sign2|1);
  330. }
  331. if (e0) e0->value *= (sign|1);
  332. *e = e0;
  333. return 0;
  334. }
  335. static int parse_term(AVExpr **e, Parser *p)
  336. {
  337. int ret;
  338. AVExpr *e0, *e1, *e2;
  339. if ((ret = parse_factor(&e0, p)) < 0)
  340. return ret;
  341. while (p->s[0]=='*' || p->s[0]=='/') {
  342. int c= *p->s++;
  343. e1 = e0;
  344. if ((ret = parse_factor(&e2, p)) < 0) {
  345. av_expr_free(e1);
  346. return ret;
  347. }
  348. e0 = new_eval_expr(c == '*' ? e_mul : e_div, 1, e1, e2);
  349. if (!e0) {
  350. av_expr_free(e1);
  351. av_expr_free(e2);
  352. return AVERROR(ENOMEM);
  353. }
  354. }
  355. *e = e0;
  356. return 0;
  357. }
  358. static int parse_subexpr(AVExpr **e, Parser *p)
  359. {
  360. int ret;
  361. AVExpr *e0, *e1, *e2;
  362. if ((ret = parse_term(&e0, p)) < 0)
  363. return ret;
  364. while (*p->s == '+' || *p->s == '-') {
  365. e1 = e0;
  366. if ((ret = parse_term(&e2, p)) < 0) {
  367. av_expr_free(e1);
  368. return ret;
  369. }
  370. e0 = new_eval_expr(e_add, 1, e1, e2);
  371. if (!e0) {
  372. av_expr_free(e1);
  373. av_expr_free(e2);
  374. return AVERROR(ENOMEM);
  375. }
  376. };
  377. *e = e0;
  378. return 0;
  379. }
  380. static int parse_expr(AVExpr **e, Parser *p)
  381. {
  382. int ret;
  383. AVExpr *e0, *e1, *e2;
  384. if (p->stack_index <= 0) //protect against stack overflows
  385. return AVERROR(EINVAL);
  386. p->stack_index--;
  387. if ((ret = parse_subexpr(&e0, p)) < 0)
  388. return ret;
  389. while (*p->s == ';') {
  390. p->s++;
  391. e1 = e0;
  392. if ((ret = parse_subexpr(&e2, p)) < 0) {
  393. av_expr_free(e1);
  394. return ret;
  395. }
  396. e0 = new_eval_expr(e_last, 1, e1, e2);
  397. if (!e0) {
  398. av_expr_free(e1);
  399. av_expr_free(e2);
  400. return AVERROR(ENOMEM);
  401. }
  402. };
  403. p->stack_index++;
  404. *e = e0;
  405. return 0;
  406. }
  407. static int verify_expr(AVExpr *e)
  408. {
  409. if (!e) return 0;
  410. switch (e->type) {
  411. case e_value:
  412. case e_const: return 1;
  413. case e_func0:
  414. case e_func1:
  415. case e_squish:
  416. case e_ld:
  417. case e_gauss:
  418. case e_isnan:
  419. case e_floor:
  420. case e_ceil:
  421. case e_trunc:
  422. case e_sqrt:
  423. return verify_expr(e->param[0]);
  424. default: return verify_expr(e->param[0]) && verify_expr(e->param[1]);
  425. }
  426. }
  427. int av_expr_parse(AVExpr **expr, const char *s,
  428. const char * const *const_names,
  429. const char * const *func1_names, double (* const *funcs1)(void *, double),
  430. const char * const *func2_names, double (* const *funcs2)(void *, double, double),
  431. int log_offset, void *log_ctx)
  432. {
  433. Parser p;
  434. AVExpr *e = NULL;
  435. char *w = av_malloc(strlen(s) + 1);
  436. char *wp = w;
  437. const char *s0 = s;
  438. int ret = 0;
  439. if (!w)
  440. return AVERROR(ENOMEM);
  441. while (*s)
  442. if (!isspace(*s++)) *wp++ = s[-1];
  443. *wp++ = 0;
  444. p.class = &class;
  445. p.stack_index=100;
  446. p.s= w;
  447. p.const_names = const_names;
  448. p.funcs1 = funcs1;
  449. p.func1_names = func1_names;
  450. p.funcs2 = funcs2;
  451. p.func2_names = func2_names;
  452. p.log_offset = log_offset;
  453. p.log_ctx = log_ctx;
  454. if ((ret = parse_expr(&e, &p)) < 0)
  455. goto end;
  456. if (*p.s) {
  457. av_log(&p, AV_LOG_ERROR, "Invalid chars '%s' at the end of expression '%s'\n", p.s, s0);
  458. ret = AVERROR(EINVAL);
  459. goto end;
  460. }
  461. if (!verify_expr(e)) {
  462. av_expr_free(e);
  463. ret = AVERROR(EINVAL);
  464. goto end;
  465. }
  466. *expr = e;
  467. end:
  468. av_free(w);
  469. return ret;
  470. }
  471. double av_expr_eval(AVExpr *e, const double *const_values, void *opaque)
  472. {
  473. Parser p;
  474. p.const_values = const_values;
  475. p.opaque = opaque;
  476. return eval_expr(&p, e);
  477. }
  478. int av_expr_parse_and_eval(double *d, const char *s,
  479. const char * const *const_names, const double *const_values,
  480. const char * const *func1_names, double (* const *funcs1)(void *, double),
  481. const char * const *func2_names, double (* const *funcs2)(void *, double, double),
  482. void *opaque, int log_offset, void *log_ctx)
  483. {
  484. AVExpr *e = NULL;
  485. int ret = av_expr_parse(&e, s, const_names, func1_names, funcs1, func2_names, funcs2, log_offset, log_ctx);
  486. if (ret < 0) {
  487. *d = NAN;
  488. return ret;
  489. }
  490. *d = av_expr_eval(e, const_values, opaque);
  491. av_expr_free(e);
  492. return isnan(*d) ? AVERROR(EINVAL) : 0;
  493. }
  494. #if FF_API_OLD_EVAL_NAMES
  495. int av_parse_expr(AVExpr **expr, const char *s,
  496. const char * const *const_names,
  497. const char * const *func1_names, double (* const *funcs1)(void *, double),
  498. const char * const *func2_names, double (* const *funcs2)(void *, double, double),
  499. int log_offset, void *log_ctx)
  500. {
  501. return av_expr_parse(expr, s, const_names, func1_names, funcs1, func2_names, funcs2,
  502. log_offset, log_ctx);
  503. }
  504. double av_eval_expr(AVExpr *e, const double *const_values, void *opaque)
  505. {
  506. return av_expr_eval(e, const_values, opaque);
  507. }
  508. int av_parse_and_eval_expr(double *res, const char *s,
  509. const char * const *const_names, const double *const_values,
  510. const char * const *func1_names, double (* const *funcs1)(void *, double),
  511. const char * const *func2_names, double (* const *funcs2)(void *, double, double),
  512. void *opaque, int log_offset, void *log_ctx)
  513. {
  514. return av_expr_parse_and_eval(res, s, const_names, const_values, func1_names, funcs1, func2_names, funcs2,
  515. opaque, log_offset, log_ctx);
  516. }
  517. void av_free_expr(AVExpr *e)
  518. {
  519. av_expr_free(e);
  520. }
  521. #endif /* FF_API_OLD_EVAL_NAMES */
  522. #ifdef TEST
  523. #undef printf
  524. static double const_values[] = {
  525. M_PI,
  526. M_E,
  527. 0
  528. };
  529. static const char *const_names[] = {
  530. "PI",
  531. "E",
  532. 0
  533. };
  534. int main(void)
  535. {
  536. int i;
  537. double d;
  538. const char **expr, *exprs[] = {
  539. "",
  540. "1;2",
  541. "-20",
  542. "-PI",
  543. "+PI",
  544. "1+(5-2)^(3-1)+1/2+sin(PI)-max(-2.2,-3.1)",
  545. "80G/80Gi"
  546. "1k",
  547. "1Gi",
  548. "1gi",
  549. "1GiFoo",
  550. "1k+1k",
  551. "1Gi*3foo",
  552. "foo",
  553. "foo(",
  554. "foo()",
  555. "foo)",
  556. "sin",
  557. "sin(",
  558. "sin()",
  559. "sin)",
  560. "sin 10",
  561. "sin(1,2,3)",
  562. "sin(1 )",
  563. "1",
  564. "1foo",
  565. "bar + PI + E + 100f*2 + foo",
  566. "13k + 12f - foo(1, 2)",
  567. "1gi",
  568. "1Gi",
  569. "st(0, 123)",
  570. "st(1, 123); ld(1)",
  571. /* compute 1+2+...+N */
  572. "st(0, 1); while(lte(ld(0), 100), st(1, ld(1)+ld(0));st(0, ld(0)+1)); ld(1)",
  573. /* compute Fib(N) */
  574. "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)",
  575. "while(0, 10)",
  576. "st(0, 1); while(lte(ld(0),100), st(1, ld(1)+ld(0)); st(0, ld(0)+1))",
  577. "isnan(1)",
  578. "isnan(NAN)",
  579. "floor(NAN)",
  580. "floor(123.123)",
  581. "floor(-123.123)",
  582. "trunc(123.123)",
  583. "trunc(-123.123)",
  584. "ceil(123.123)",
  585. "ceil(-123.123)",
  586. "sqrt(1764)",
  587. "sqrt(-1)",
  588. NULL
  589. };
  590. for (expr = exprs; *expr; expr++) {
  591. printf("Evaluating '%s'\n", *expr);
  592. av_expr_parse_and_eval(&d, *expr,
  593. const_names, const_values,
  594. NULL, NULL, NULL, NULL, NULL, 0, NULL);
  595. printf("'%s' -> %f\n\n", *expr, d);
  596. }
  597. av_expr_parse_and_eval(&d, "1+(5-2)^(3-1)+1/2+sin(PI)-max(-2.2,-3.1)",
  598. const_names, const_values,
  599. NULL, NULL, NULL, NULL, NULL, 0, NULL);
  600. printf("%f == 12.7\n", d);
  601. av_expr_parse_and_eval(&d, "80G/80Gi",
  602. const_names, const_values,
  603. NULL, NULL, NULL, NULL, NULL, 0, NULL);
  604. printf("%f == 0.931322575\n", d);
  605. for (i=0; i<1050; i++) {
  606. START_TIMER
  607. av_expr_parse_and_eval(&d, "1+(5-2)^(3-1)+1/2+sin(PI)-max(-2.2,-3.1)",
  608. const_names, const_values,
  609. NULL, NULL, NULL, NULL, NULL, 0, NULL);
  610. STOP_TIMER("av_expr_parse_and_eval")
  611. }
  612. return 0;
  613. }
  614. #endif