annotate eval.c @ 3470:c6071e607062 libavcodec

cleanup
author michael
date Fri, 14 Jul 2006 19:14:25 +0000
parents 0b546eab515d
children 58483364f021
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
612
c0005de2be59 new ratecontrol code
michaelni
parents:
diff changeset
1 /*
c0005de2be59 new ratecontrol code
michaelni
parents:
diff changeset
2 * simple arithmetic expression evaluator
c0005de2be59 new ratecontrol code
michaelni
parents:
diff changeset
3 *
c0005de2be59 new ratecontrol code
michaelni
parents:
diff changeset
4 * Copyright (c) 2002 Michael Niedermayer <michaelni@gmx.at>
c0005de2be59 new ratecontrol code
michaelni
parents:
diff changeset
5 *
c0005de2be59 new ratecontrol code
michaelni
parents:
diff changeset
6 * This library is free software; you can redistribute it and/or
c0005de2be59 new ratecontrol code
michaelni
parents:
diff changeset
7 * modify it under the terms of the GNU Lesser General Public
c0005de2be59 new ratecontrol code
michaelni
parents:
diff changeset
8 * License as published by the Free Software Foundation; either
c0005de2be59 new ratecontrol code
michaelni
parents:
diff changeset
9 * version 2 of the License, or (at your option) any later version.
c0005de2be59 new ratecontrol code
michaelni
parents:
diff changeset
10 *
c0005de2be59 new ratecontrol code
michaelni
parents:
diff changeset
11 * This library is distributed in the hope that it will be useful,
c0005de2be59 new ratecontrol code
michaelni
parents:
diff changeset
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
c0005de2be59 new ratecontrol code
michaelni
parents:
diff changeset
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
c0005de2be59 new ratecontrol code
michaelni
parents:
diff changeset
14 * Lesser General Public License for more details.
c0005de2be59 new ratecontrol code
michaelni
parents:
diff changeset
15 *
c0005de2be59 new ratecontrol code
michaelni
parents:
diff changeset
16 * You should have received a copy of the GNU Lesser General Public
c0005de2be59 new ratecontrol code
michaelni
parents:
diff changeset
17 * License along with this library; if not, write to the Free Software
3036
0b546eab515d Update licensing information: The FSF changed postal address.
diego
parents: 2967
diff changeset
18 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
612
c0005de2be59 new ratecontrol code
michaelni
parents:
diff changeset
19 *
c0005de2be59 new ratecontrol code
michaelni
parents:
diff changeset
20 */
c0005de2be59 new ratecontrol code
michaelni
parents:
diff changeset
21
1106
1e39f273ecd6 per file doxy
michaelni
parents: 1057
diff changeset
22 /**
1e39f273ecd6 per file doxy
michaelni
parents: 1057
diff changeset
23 * @file eval.c
1e39f273ecd6 per file doxy
michaelni
parents: 1057
diff changeset
24 * simple arithmetic expression evaluator.
1e39f273ecd6 per file doxy
michaelni
parents: 1057
diff changeset
25 *
612
c0005de2be59 new ratecontrol code
michaelni
parents:
diff changeset
26 * see http://joe.hotchkiss.com/programming/eval/eval.html
c0005de2be59 new ratecontrol code
michaelni
parents:
diff changeset
27 */
c0005de2be59 new ratecontrol code
michaelni
parents:
diff changeset
28
1057
bb5de8a59da8 * static,const,compiler warning cleanup
kabi
parents: 627
diff changeset
29 #include "avcodec.h"
bb5de8a59da8 * static,const,compiler warning cleanup
kabi
parents: 627
diff changeset
30 #include "mpegvideo.h"
bb5de8a59da8 * static,const,compiler warning cleanup
kabi
parents: 627
diff changeset
31
612
c0005de2be59 new ratecontrol code
michaelni
parents:
diff changeset
32 #include <stdio.h>
c0005de2be59 new ratecontrol code
michaelni
parents:
diff changeset
33 #include <stdlib.h>
c0005de2be59 new ratecontrol code
michaelni
parents:
diff changeset
34 #include <string.h>
c0005de2be59 new ratecontrol code
michaelni
parents:
diff changeset
35 #include <math.h>
c0005de2be59 new ratecontrol code
michaelni
parents:
diff changeset
36
614
b786f15df503 NAN doesnt exist on FreeBSD patch by (Rmi Guyomarch <rguyom at pobox dot com>)
michaelni
parents: 612
diff changeset
37 #ifndef NAN
b786f15df503 NAN doesnt exist on FreeBSD patch by (Rmi Guyomarch <rguyom at pobox dot com>)
michaelni
parents: 612
diff changeset
38 #define NAN 0
b786f15df503 NAN doesnt exist on FreeBSD patch by (Rmi Guyomarch <rguyom at pobox dot com>)
michaelni
parents: 612
diff changeset
39 #endif
b786f15df503 NAN doesnt exist on FreeBSD patch by (Rmi Guyomarch <rguyom at pobox dot com>)
michaelni
parents: 612
diff changeset
40
627
79c43f519d02 undefined M_PI / M_E fix
michaelni
parents: 614
diff changeset
41 #ifndef M_PI
79c43f519d02 undefined M_PI / M_E fix
michaelni
parents: 614
diff changeset
42 #define M_PI 3.14159265358979323846
79c43f519d02 undefined M_PI / M_E fix
michaelni
parents: 614
diff changeset
43 #endif
79c43f519d02 undefined M_PI / M_E fix
michaelni
parents: 614
diff changeset
44
612
c0005de2be59 new ratecontrol code
michaelni
parents:
diff changeset
45 typedef struct Parser{
c0005de2be59 new ratecontrol code
michaelni
parents:
diff changeset
46 int stack_index;
c0005de2be59 new ratecontrol code
michaelni
parents:
diff changeset
47 char *s;
c0005de2be59 new ratecontrol code
michaelni
parents:
diff changeset
48 double *const_value;
1057
bb5de8a59da8 * static,const,compiler warning cleanup
kabi
parents: 627
diff changeset
49 const char **const_name; // NULL terminated
612
c0005de2be59 new ratecontrol code
michaelni
parents:
diff changeset
50 double (**func1)(void *, double a); // NULL terminated
1057
bb5de8a59da8 * static,const,compiler warning cleanup
kabi
parents: 627
diff changeset
51 const char **func1_name; // NULL terminated
612
c0005de2be59 new ratecontrol code
michaelni
parents:
diff changeset
52 double (**func2)(void *, double a, double b); // NULL terminated
c0005de2be59 new ratecontrol code
michaelni
parents:
diff changeset
53 char **func2_name; // NULL terminated
c0005de2be59 new ratecontrol code
michaelni
parents:
diff changeset
54 void *opaque;
c0005de2be59 new ratecontrol code
michaelni
parents:
diff changeset
55 } Parser;
c0005de2be59 new ratecontrol code
michaelni
parents:
diff changeset
56
2434
24aa9209e8b0 simplify
michael
parents: 2433
diff changeset
57 static double evalExpression(Parser *p);
612
c0005de2be59 new ratecontrol code
michaelni
parents:
diff changeset
58
1057
bb5de8a59da8 * static,const,compiler warning cleanup
kabi
parents: 627
diff changeset
59 static int strmatch(const char *s, const char *prefix){
612
c0005de2be59 new ratecontrol code
michaelni
parents:
diff changeset
60 int i;
c0005de2be59 new ratecontrol code
michaelni
parents:
diff changeset
61 for(i=0; prefix[i]; i++){
c0005de2be59 new ratecontrol code
michaelni
parents:
diff changeset
62 if(prefix[i] != s[i]) return 0;
c0005de2be59 new ratecontrol code
michaelni
parents:
diff changeset
63 }
c0005de2be59 new ratecontrol code
michaelni
parents:
diff changeset
64 return 1;
c0005de2be59 new ratecontrol code
michaelni
parents:
diff changeset
65 }
c0005de2be59 new ratecontrol code
michaelni
parents:
diff changeset
66
2434
24aa9209e8b0 simplify
michael
parents: 2433
diff changeset
67 static double evalPrimary(Parser *p){
612
c0005de2be59 new ratecontrol code
michaelni
parents:
diff changeset
68 double d, d2=NAN;
c0005de2be59 new ratecontrol code
michaelni
parents:
diff changeset
69 char *next= p->s;
c0005de2be59 new ratecontrol code
michaelni
parents:
diff changeset
70 int i;
c0005de2be59 new ratecontrol code
michaelni
parents:
diff changeset
71
c0005de2be59 new ratecontrol code
michaelni
parents:
diff changeset
72 /* number */
c0005de2be59 new ratecontrol code
michaelni
parents:
diff changeset
73 d= strtod(p->s, &next);
c0005de2be59 new ratecontrol code
michaelni
parents:
diff changeset
74 if(next != p->s){
c0005de2be59 new ratecontrol code
michaelni
parents:
diff changeset
75 p->s= next;
2434
24aa9209e8b0 simplify
michael
parents: 2433
diff changeset
76 return d;
612
c0005de2be59 new ratecontrol code
michaelni
parents:
diff changeset
77 }
2967
ef2149182f1c COSMETICS: Remove all trailing whitespace.
diego
parents: 2436
diff changeset
78
612
c0005de2be59 new ratecontrol code
michaelni
parents:
diff changeset
79 /* named constants */
2433
0934621b6453 simplify, null pointer, selftest
michael
parents: 1815
diff changeset
80 for(i=0; p->const_name && p->const_name[i]; i++){
612
c0005de2be59 new ratecontrol code
michaelni
parents:
diff changeset
81 if(strmatch(p->s, p->const_name[i])){
c0005de2be59 new ratecontrol code
michaelni
parents:
diff changeset
82 p->s+= strlen(p->const_name[i]);
2434
24aa9209e8b0 simplify
michael
parents: 2433
diff changeset
83 return p->const_value[i];
612
c0005de2be59 new ratecontrol code
michaelni
parents:
diff changeset
84 }
c0005de2be59 new ratecontrol code
michaelni
parents:
diff changeset
85 }
2967
ef2149182f1c COSMETICS: Remove all trailing whitespace.
diego
parents: 2436
diff changeset
86
612
c0005de2be59 new ratecontrol code
michaelni
parents:
diff changeset
87 p->s= strchr(p->s, '(');
c0005de2be59 new ratecontrol code
michaelni
parents:
diff changeset
88 if(p->s==NULL){
1598
932d306bf1dc av_log() patch by (Michel Bardiaux <mbardiaux at peaktime dot be>)
michael
parents: 1106
diff changeset
89 av_log(NULL, AV_LOG_ERROR, "Parser: missing ( in \"%s\"\n", next);
2434
24aa9209e8b0 simplify
michael
parents: 2433
diff changeset
90 return NAN;
612
c0005de2be59 new ratecontrol code
michaelni
parents:
diff changeset
91 }
c0005de2be59 new ratecontrol code
michaelni
parents:
diff changeset
92 p->s++; // "("
2434
24aa9209e8b0 simplify
michael
parents: 2433
diff changeset
93 d= evalExpression(p);
1815
2152760d08ad avoid negative array indices
alex
parents: 1598
diff changeset
94 if(p->s[0]== ','){
2152760d08ad avoid negative array indices
alex
parents: 1598
diff changeset
95 p->s++; // ","
2434
24aa9209e8b0 simplify
michael
parents: 2433
diff changeset
96 d2= evalExpression(p);
612
c0005de2be59 new ratecontrol code
michaelni
parents:
diff changeset
97 }
1815
2152760d08ad avoid negative array indices
alex
parents: 1598
diff changeset
98 if(p->s[0] != ')'){
2152760d08ad avoid negative array indices
alex
parents: 1598
diff changeset
99 av_log(NULL, AV_LOG_ERROR, "Parser: missing ) in \"%s\"\n", next);
2434
24aa9209e8b0 simplify
michael
parents: 2433
diff changeset
100 return NAN;
1815
2152760d08ad avoid negative array indices
alex
parents: 1598
diff changeset
101 }
2152760d08ad avoid negative array indices
alex
parents: 1598
diff changeset
102 p->s++; // ")"
2967
ef2149182f1c COSMETICS: Remove all trailing whitespace.
diego
parents: 2436
diff changeset
103
612
c0005de2be59 new ratecontrol code
michaelni
parents:
diff changeset
104 if( strmatch(next, "sinh" ) ) d= sinh(d);
c0005de2be59 new ratecontrol code
michaelni
parents:
diff changeset
105 else if( strmatch(next, "cosh" ) ) d= cosh(d);
c0005de2be59 new ratecontrol code
michaelni
parents:
diff changeset
106 else if( strmatch(next, "tanh" ) ) d= tanh(d);
c0005de2be59 new ratecontrol code
michaelni
parents:
diff changeset
107 else if( strmatch(next, "sin" ) ) d= sin(d);
c0005de2be59 new ratecontrol code
michaelni
parents:
diff changeset
108 else if( strmatch(next, "cos" ) ) d= cos(d);
c0005de2be59 new ratecontrol code
michaelni
parents:
diff changeset
109 else if( strmatch(next, "tan" ) ) d= tan(d);
c0005de2be59 new ratecontrol code
michaelni
parents:
diff changeset
110 else if( strmatch(next, "exp" ) ) d= exp(d);
c0005de2be59 new ratecontrol code
michaelni
parents:
diff changeset
111 else if( strmatch(next, "log" ) ) d= log(d);
c0005de2be59 new ratecontrol code
michaelni
parents:
diff changeset
112 else if( strmatch(next, "squish") ) d= 1/(1+exp(4*d));
c0005de2be59 new ratecontrol code
michaelni
parents:
diff changeset
113 else if( strmatch(next, "gauss" ) ) d= exp(-d*d/2)/sqrt(2*M_PI);
1057
bb5de8a59da8 * static,const,compiler warning cleanup
kabi
parents: 627
diff changeset
114 else if( strmatch(next, "abs" ) ) d= fabs(d);
612
c0005de2be59 new ratecontrol code
michaelni
parents:
diff changeset
115 else if( strmatch(next, "max" ) ) d= d > d2 ? d : d2;
c0005de2be59 new ratecontrol code
michaelni
parents:
diff changeset
116 else if( strmatch(next, "min" ) ) d= d < d2 ? d : d2;
c0005de2be59 new ratecontrol code
michaelni
parents:
diff changeset
117 else if( strmatch(next, "gt" ) ) d= d > d2 ? 1.0 : 0.0;
1815
2152760d08ad avoid negative array indices
alex
parents: 1598
diff changeset
118 else if( strmatch(next, "gte" ) ) d= d >= d2 ? 1.0 : 0.0;
612
c0005de2be59 new ratecontrol code
michaelni
parents:
diff changeset
119 else if( strmatch(next, "lt" ) ) d= d > d2 ? 0.0 : 1.0;
1815
2152760d08ad avoid negative array indices
alex
parents: 1598
diff changeset
120 else if( strmatch(next, "lte" ) ) d= d >= d2 ? 0.0 : 1.0;
612
c0005de2be59 new ratecontrol code
michaelni
parents:
diff changeset
121 else if( strmatch(next, "eq" ) ) d= d == d2 ? 1.0 : 0.0;
2434
24aa9209e8b0 simplify
michael
parents: 2433
diff changeset
122 else if( strmatch(next, "(" ) ) d= d;
612
c0005de2be59 new ratecontrol code
michaelni
parents:
diff changeset
123 // else if( strmatch(next, "l1" ) ) d= 1 + d2*(d - 1);
c0005de2be59 new ratecontrol code
michaelni
parents:
diff changeset
124 // else if( strmatch(next, "sq01" ) ) d= (d >= 0.0 && d <=1.0) ? 1.0 : 0.0;
c0005de2be59 new ratecontrol code
michaelni
parents:
diff changeset
125 else{
c0005de2be59 new ratecontrol code
michaelni
parents:
diff changeset
126 for(i=0; p->func1_name && p->func1_name[i]; i++){
c0005de2be59 new ratecontrol code
michaelni
parents:
diff changeset
127 if(strmatch(next, p->func1_name[i])){
2434
24aa9209e8b0 simplify
michael
parents: 2433
diff changeset
128 return p->func1[i](p->opaque, d);
612
c0005de2be59 new ratecontrol code
michaelni
parents:
diff changeset
129 }
c0005de2be59 new ratecontrol code
michaelni
parents:
diff changeset
130 }
c0005de2be59 new ratecontrol code
michaelni
parents:
diff changeset
131
c0005de2be59 new ratecontrol code
michaelni
parents:
diff changeset
132 for(i=0; p->func2_name && p->func2_name[i]; i++){
c0005de2be59 new ratecontrol code
michaelni
parents:
diff changeset
133 if(strmatch(next, p->func2_name[i])){
2434
24aa9209e8b0 simplify
michael
parents: 2433
diff changeset
134 return p->func2[i](p->opaque, d, d2);
612
c0005de2be59 new ratecontrol code
michaelni
parents:
diff changeset
135 }
c0005de2be59 new ratecontrol code
michaelni
parents:
diff changeset
136 }
c0005de2be59 new ratecontrol code
michaelni
parents:
diff changeset
137
2433
0934621b6453 simplify, null pointer, selftest
michael
parents: 1815
diff changeset
138 av_log(NULL, AV_LOG_ERROR, "Parser: unknown function in \"%s\"\n", next);
2434
24aa9209e8b0 simplify
michael
parents: 2433
diff changeset
139 return NAN;
612
c0005de2be59 new ratecontrol code
michaelni
parents:
diff changeset
140 }
2433
0934621b6453 simplify, null pointer, selftest
michael
parents: 1815
diff changeset
141
2434
24aa9209e8b0 simplify
michael
parents: 2433
diff changeset
142 return d;
2967
ef2149182f1c COSMETICS: Remove all trailing whitespace.
diego
parents: 2436
diff changeset
143 }
2436
86d14aebd527 simplify
michael
parents: 2434
diff changeset
144
2434
24aa9209e8b0 simplify
michael
parents: 2433
diff changeset
145 static double evalPow(Parser *p){
2436
86d14aebd527 simplify
michael
parents: 2434
diff changeset
146 int sign= (*p->s == '+') - (*p->s == '-');
86d14aebd527 simplify
michael
parents: 2434
diff changeset
147 p->s += sign&1;
86d14aebd527 simplify
michael
parents: 2434
diff changeset
148 return (sign|1) * evalPrimary(p);
2434
24aa9209e8b0 simplify
michael
parents: 2433
diff changeset
149 }
612
c0005de2be59 new ratecontrol code
michaelni
parents:
diff changeset
150
2434
24aa9209e8b0 simplify
michael
parents: 2433
diff changeset
151 static double evalFactor(Parser *p){
24aa9209e8b0 simplify
michael
parents: 2433
diff changeset
152 double ret= evalPow(p);
24aa9209e8b0 simplify
michael
parents: 2433
diff changeset
153 while(p->s[0]=='^'){
612
c0005de2be59 new ratecontrol code
michaelni
parents:
diff changeset
154 p->s++;
2434
24aa9209e8b0 simplify
michael
parents: 2433
diff changeset
155 ret= pow(ret, evalPow(p));
612
c0005de2be59 new ratecontrol code
michaelni
parents:
diff changeset
156 }
2434
24aa9209e8b0 simplify
michael
parents: 2433
diff changeset
157 return ret;
612
c0005de2be59 new ratecontrol code
michaelni
parents:
diff changeset
158 }
c0005de2be59 new ratecontrol code
michaelni
parents:
diff changeset
159
2434
24aa9209e8b0 simplify
michael
parents: 2433
diff changeset
160 static double evalTerm(Parser *p){
24aa9209e8b0 simplify
michael
parents: 2433
diff changeset
161 double ret= evalFactor(p);
24aa9209e8b0 simplify
michael
parents: 2433
diff changeset
162 while(p->s[0]=='*' || p->s[0]=='/'){
24aa9209e8b0 simplify
michael
parents: 2433
diff changeset
163 if(*p->s++ == '*') ret*= evalFactor(p);
24aa9209e8b0 simplify
michael
parents: 2433
diff changeset
164 else ret/= evalFactor(p);
612
c0005de2be59 new ratecontrol code
michaelni
parents:
diff changeset
165 }
2434
24aa9209e8b0 simplify
michael
parents: 2433
diff changeset
166 return ret;
612
c0005de2be59 new ratecontrol code
michaelni
parents:
diff changeset
167 }
c0005de2be59 new ratecontrol code
michaelni
parents:
diff changeset
168
2434
24aa9209e8b0 simplify
michael
parents: 2433
diff changeset
169 static double evalExpression(Parser *p){
2436
86d14aebd527 simplify
michael
parents: 2434
diff changeset
170 double ret= 0;
612
c0005de2be59 new ratecontrol code
michaelni
parents:
diff changeset
171
2434
24aa9209e8b0 simplify
michael
parents: 2433
diff changeset
172 if(p->stack_index <= 0) //protect against stack overflows
24aa9209e8b0 simplify
michael
parents: 2433
diff changeset
173 return NAN;
24aa9209e8b0 simplify
michael
parents: 2433
diff changeset
174 p->stack_index--;
24aa9209e8b0 simplify
michael
parents: 2433
diff changeset
175
2436
86d14aebd527 simplify
michael
parents: 2434
diff changeset
176 do{
86d14aebd527 simplify
michael
parents: 2434
diff changeset
177 ret += evalTerm(p);
86d14aebd527 simplify
michael
parents: 2434
diff changeset
178 }while(*p->s == '+' || *p->s == '-');
612
c0005de2be59 new ratecontrol code
michaelni
parents:
diff changeset
179
2434
24aa9209e8b0 simplify
michael
parents: 2433
diff changeset
180 p->stack_index++;
612
c0005de2be59 new ratecontrol code
michaelni
parents:
diff changeset
181
2434
24aa9209e8b0 simplify
michael
parents: 2433
diff changeset
182 return ret;
612
c0005de2be59 new ratecontrol code
michaelni
parents:
diff changeset
183 }
c0005de2be59 new ratecontrol code
michaelni
parents:
diff changeset
184
1057
bb5de8a59da8 * static,const,compiler warning cleanup
kabi
parents: 627
diff changeset
185 double ff_eval(char *s, double *const_value, const char **const_name,
bb5de8a59da8 * static,const,compiler warning cleanup
kabi
parents: 627
diff changeset
186 double (**func1)(void *, double), const char **func1_name,
612
c0005de2be59 new ratecontrol code
michaelni
parents:
diff changeset
187 double (**func2)(void *, double, double), char **func2_name,
c0005de2be59 new ratecontrol code
michaelni
parents:
diff changeset
188 void *opaque){
c0005de2be59 new ratecontrol code
michaelni
parents:
diff changeset
189 Parser p;
2967
ef2149182f1c COSMETICS: Remove all trailing whitespace.
diego
parents: 2436
diff changeset
190
2434
24aa9209e8b0 simplify
michael
parents: 2433
diff changeset
191 p.stack_index=100;
612
c0005de2be59 new ratecontrol code
michaelni
parents:
diff changeset
192 p.s= s;
c0005de2be59 new ratecontrol code
michaelni
parents:
diff changeset
193 p.const_value= const_value;
c0005de2be59 new ratecontrol code
michaelni
parents:
diff changeset
194 p.const_name = const_name;
c0005de2be59 new ratecontrol code
michaelni
parents:
diff changeset
195 p.func1 = func1;
c0005de2be59 new ratecontrol code
michaelni
parents:
diff changeset
196 p.func1_name = func1_name;
c0005de2be59 new ratecontrol code
michaelni
parents:
diff changeset
197 p.func2 = func2;
c0005de2be59 new ratecontrol code
michaelni
parents:
diff changeset
198 p.func2_name = func2_name;
c0005de2be59 new ratecontrol code
michaelni
parents:
diff changeset
199 p.opaque = opaque;
2967
ef2149182f1c COSMETICS: Remove all trailing whitespace.
diego
parents: 2436
diff changeset
200
2434
24aa9209e8b0 simplify
michael
parents: 2433
diff changeset
201 return evalExpression(&p);
612
c0005de2be59 new ratecontrol code
michaelni
parents:
diff changeset
202 }
2433
0934621b6453 simplify, null pointer, selftest
michael
parents: 1815
diff changeset
203
0934621b6453 simplify, null pointer, selftest
michael
parents: 1815
diff changeset
204 #ifdef TEST
2967
ef2149182f1c COSMETICS: Remove all trailing whitespace.
diego
parents: 2436
diff changeset
205 #undef printf
2433
0934621b6453 simplify, null pointer, selftest
michael
parents: 1815
diff changeset
206 static double const_values[]={
0934621b6453 simplify, null pointer, selftest
michael
parents: 1815
diff changeset
207 M_PI,
0934621b6453 simplify, null pointer, selftest
michael
parents: 1815
diff changeset
208 M_E,
0934621b6453 simplify, null pointer, selftest
michael
parents: 1815
diff changeset
209 0
0934621b6453 simplify, null pointer, selftest
michael
parents: 1815
diff changeset
210 };
0934621b6453 simplify, null pointer, selftest
michael
parents: 1815
diff changeset
211 static const char *const_names[]={
0934621b6453 simplify, null pointer, selftest
michael
parents: 1815
diff changeset
212 "PI",
0934621b6453 simplify, null pointer, selftest
michael
parents: 1815
diff changeset
213 "E",
0934621b6453 simplify, null pointer, selftest
michael
parents: 1815
diff changeset
214 0
0934621b6453 simplify, null pointer, selftest
michael
parents: 1815
diff changeset
215 };
0934621b6453 simplify, null pointer, selftest
michael
parents: 1815
diff changeset
216 main(){
2436
86d14aebd527 simplify
michael
parents: 2434
diff changeset
217 int i;
2433
0934621b6453 simplify, null pointer, selftest
michael
parents: 1815
diff changeset
218 printf("%f == 12.7\n", ff_eval("1+(5-2)^(3-1)+1/2+sin(PI)-max(-2.2,-3.1)", const_values, const_names, NULL, NULL, NULL, NULL, NULL));
2967
ef2149182f1c COSMETICS: Remove all trailing whitespace.
diego
parents: 2436
diff changeset
219
2436
86d14aebd527 simplify
michael
parents: 2434
diff changeset
220 for(i=0; i<1050; i++){
86d14aebd527 simplify
michael
parents: 2434
diff changeset
221 START_TIMER
86d14aebd527 simplify
michael
parents: 2434
diff changeset
222 ff_eval("1+(5-2)^(3-1)+1/2+sin(PI)-max(-2.2,-3.1)", const_values, const_names, NULL, NULL, NULL, NULL, NULL);
86d14aebd527 simplify
michael
parents: 2434
diff changeset
223 STOP_TIMER("ff_eval")
86d14aebd527 simplify
michael
parents: 2434
diff changeset
224 }
2433
0934621b6453 simplify, null pointer, selftest
michael
parents: 1815
diff changeset
225 }
0934621b6453 simplify, null pointer, selftest
michael
parents: 1815
diff changeset
226 #endif