Mercurial > libavcodec.hg
comparison eval.c @ 2967:ef2149182f1c libavcodec
COSMETICS: Remove all trailing whitespace.
author | diego |
---|---|
date | Sat, 17 Dec 2005 18:14:38 +0000 |
parents | 86d14aebd527 |
children | 0b546eab515d |
comparison
equal
deleted
inserted
replaced
2966:564788471dd4 | 2967:ef2149182f1c |
---|---|
73 d= strtod(p->s, &next); | 73 d= strtod(p->s, &next); |
74 if(next != p->s){ | 74 if(next != p->s){ |
75 p->s= next; | 75 p->s= next; |
76 return d; | 76 return d; |
77 } | 77 } |
78 | 78 |
79 /* named constants */ | 79 /* named constants */ |
80 for(i=0; p->const_name && p->const_name[i]; i++){ | 80 for(i=0; p->const_name && p->const_name[i]; i++){ |
81 if(strmatch(p->s, p->const_name[i])){ | 81 if(strmatch(p->s, p->const_name[i])){ |
82 p->s+= strlen(p->const_name[i]); | 82 p->s+= strlen(p->const_name[i]); |
83 return p->const_value[i]; | 83 return p->const_value[i]; |
84 } | 84 } |
85 } | 85 } |
86 | 86 |
87 p->s= strchr(p->s, '('); | 87 p->s= strchr(p->s, '('); |
88 if(p->s==NULL){ | 88 if(p->s==NULL){ |
89 av_log(NULL, AV_LOG_ERROR, "Parser: missing ( in \"%s\"\n", next); | 89 av_log(NULL, AV_LOG_ERROR, "Parser: missing ( in \"%s\"\n", next); |
90 return NAN; | 90 return NAN; |
91 } | 91 } |
98 if(p->s[0] != ')'){ | 98 if(p->s[0] != ')'){ |
99 av_log(NULL, AV_LOG_ERROR, "Parser: missing ) in \"%s\"\n", next); | 99 av_log(NULL, AV_LOG_ERROR, "Parser: missing ) in \"%s\"\n", next); |
100 return NAN; | 100 return NAN; |
101 } | 101 } |
102 p->s++; // ")" | 102 p->s++; // ")" |
103 | 103 |
104 if( strmatch(next, "sinh" ) ) d= sinh(d); | 104 if( strmatch(next, "sinh" ) ) d= sinh(d); |
105 else if( strmatch(next, "cosh" ) ) d= cosh(d); | 105 else if( strmatch(next, "cosh" ) ) d= cosh(d); |
106 else if( strmatch(next, "tanh" ) ) d= tanh(d); | 106 else if( strmatch(next, "tanh" ) ) d= tanh(d); |
107 else if( strmatch(next, "sin" ) ) d= sin(d); | 107 else if( strmatch(next, "sin" ) ) d= sin(d); |
108 else if( strmatch(next, "cos" ) ) d= cos(d); | 108 else if( strmatch(next, "cos" ) ) d= cos(d); |
138 av_log(NULL, AV_LOG_ERROR, "Parser: unknown function in \"%s\"\n", next); | 138 av_log(NULL, AV_LOG_ERROR, "Parser: unknown function in \"%s\"\n", next); |
139 return NAN; | 139 return NAN; |
140 } | 140 } |
141 | 141 |
142 return d; | 142 return d; |
143 } | 143 } |
144 | 144 |
145 static double evalPow(Parser *p){ | 145 static double evalPow(Parser *p){ |
146 int sign= (*p->s == '+') - (*p->s == '-'); | 146 int sign= (*p->s == '+') - (*p->s == '-'); |
147 p->s += sign&1; | 147 p->s += sign&1; |
148 return (sign|1) * evalPrimary(p); | 148 return (sign|1) * evalPrimary(p); |
185 double ff_eval(char *s, double *const_value, const char **const_name, | 185 double ff_eval(char *s, double *const_value, const char **const_name, |
186 double (**func1)(void *, double), const char **func1_name, | 186 double (**func1)(void *, double), const char **func1_name, |
187 double (**func2)(void *, double, double), char **func2_name, | 187 double (**func2)(void *, double, double), char **func2_name, |
188 void *opaque){ | 188 void *opaque){ |
189 Parser p; | 189 Parser p; |
190 | 190 |
191 p.stack_index=100; | 191 p.stack_index=100; |
192 p.s= s; | 192 p.s= s; |
193 p.const_value= const_value; | 193 p.const_value= const_value; |
194 p.const_name = const_name; | 194 p.const_name = const_name; |
195 p.func1 = func1; | 195 p.func1 = func1; |
196 p.func1_name = func1_name; | 196 p.func1_name = func1_name; |
197 p.func2 = func2; | 197 p.func2 = func2; |
198 p.func2_name = func2_name; | 198 p.func2_name = func2_name; |
199 p.opaque = opaque; | 199 p.opaque = opaque; |
200 | 200 |
201 return evalExpression(&p); | 201 return evalExpression(&p); |
202 } | 202 } |
203 | 203 |
204 #ifdef TEST | 204 #ifdef TEST |
205 #undef printf | 205 #undef printf |
206 static double const_values[]={ | 206 static double const_values[]={ |
207 M_PI, | 207 M_PI, |
208 M_E, | 208 M_E, |
209 0 | 209 0 |
210 }; | 210 }; |
214 0 | 214 0 |
215 }; | 215 }; |
216 main(){ | 216 main(){ |
217 int i; | 217 int i; |
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)); | 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)); |
219 | 219 |
220 for(i=0; i<1050; i++){ | 220 for(i=0; i<1050; i++){ |
221 START_TIMER | 221 START_TIMER |
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); | 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); |
223 STOP_TIMER("ff_eval") | 223 STOP_TIMER("ff_eval") |
224 } | 224 } |