annotate eval.c @ 3756:9813c594dac5 libavcodec

Missing extern declaration for av_strtod.
author takis
date Sun, 24 Sep 2006 10:53:54 +0000
parents 882cf925ff7a
children ea345e1e440f
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
3753
82ceab4ada49 Define NAN -if not already defined- as 0.0/0.0
takis
parents: 3731
diff changeset
38 #define NAN 0.0/0.0
614
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
3756
9813c594dac5 Missing extern declaration for av_strtod.
takis
parents: 3755
diff changeset
57 extern double av_strtod(const char *name, char **tail);
9813c594dac5 Missing extern declaration for av_strtod.
takis
parents: 3755
diff changeset
58
2434
24aa9209e8b0 simplify
michael
parents: 2433
diff changeset
59 static double evalExpression(Parser *p);
612
c0005de2be59 new ratecontrol code
michaelni
parents:
diff changeset
60
1057
bb5de8a59da8 * static,const,compiler warning cleanup
kabi
parents: 627
diff changeset
61 static int strmatch(const char *s, const char *prefix){
612
c0005de2be59 new ratecontrol code
michaelni
parents:
diff changeset
62 int i;
c0005de2be59 new ratecontrol code
michaelni
parents:
diff changeset
63 for(i=0; prefix[i]; i++){
c0005de2be59 new ratecontrol code
michaelni
parents:
diff changeset
64 if(prefix[i] != s[i]) return 0;
c0005de2be59 new ratecontrol code
michaelni
parents:
diff changeset
65 }
c0005de2be59 new ratecontrol code
michaelni
parents:
diff changeset
66 return 1;
c0005de2be59 new ratecontrol code
michaelni
parents:
diff changeset
67 }
c0005de2be59 new ratecontrol code
michaelni
parents:
diff changeset
68
2434
24aa9209e8b0 simplify
michael
parents: 2433
diff changeset
69 static double evalPrimary(Parser *p){
612
c0005de2be59 new ratecontrol code
michaelni
parents:
diff changeset
70 double d, d2=NAN;
c0005de2be59 new ratecontrol code
michaelni
parents:
diff changeset
71 char *next= p->s;
c0005de2be59 new ratecontrol code
michaelni
parents:
diff changeset
72 int i;
c0005de2be59 new ratecontrol code
michaelni
parents:
diff changeset
73
c0005de2be59 new ratecontrol code
michaelni
parents:
diff changeset
74 /* number */
3731
8b8773577dd9 Add support for SI (k, M, ...) and IEC/IEEE (Ki, Mi, ...) units.
takis
parents: 3730
diff changeset
75 d= av_strtod(p->s, &next);
612
c0005de2be59 new ratecontrol code
michaelni
parents:
diff changeset
76 if(next != p->s){
c0005de2be59 new ratecontrol code
michaelni
parents:
diff changeset
77 p->s= next;
2434
24aa9209e8b0 simplify
michael
parents: 2433
diff changeset
78 return d;
612
c0005de2be59 new ratecontrol code
michaelni
parents:
diff changeset
79 }
2967
ef2149182f1c COSMETICS: Remove all trailing whitespace.
diego
parents: 2436
diff changeset
80
612
c0005de2be59 new ratecontrol code
michaelni
parents:
diff changeset
81 /* named constants */
2433
0934621b6453 simplify, null pointer, selftest
michael
parents: 1815
diff changeset
82 for(i=0; p->const_name && p->const_name[i]; i++){
612
c0005de2be59 new ratecontrol code
michaelni
parents:
diff changeset
83 if(strmatch(p->s, p->const_name[i])){
c0005de2be59 new ratecontrol code
michaelni
parents:
diff changeset
84 p->s+= strlen(p->const_name[i]);
2434
24aa9209e8b0 simplify
michael
parents: 2433
diff changeset
85 return p->const_value[i];
612
c0005de2be59 new ratecontrol code
michaelni
parents:
diff changeset
86 }
c0005de2be59 new ratecontrol code
michaelni
parents:
diff changeset
87 }
2967
ef2149182f1c COSMETICS: Remove all trailing whitespace.
diego
parents: 2436
diff changeset
88
612
c0005de2be59 new ratecontrol code
michaelni
parents:
diff changeset
89 p->s= strchr(p->s, '(');
c0005de2be59 new ratecontrol code
michaelni
parents:
diff changeset
90 if(p->s==NULL){
1598
932d306bf1dc av_log() patch by (Michel Bardiaux <mbardiaux at peaktime dot be>)
michael
parents: 1106
diff changeset
91 av_log(NULL, AV_LOG_ERROR, "Parser: missing ( in \"%s\"\n", next);
3754
6f219b6839ba segfault fix
michael
parents: 3753
diff changeset
92 p->s= next;
2434
24aa9209e8b0 simplify
michael
parents: 2433
diff changeset
93 return NAN;
612
c0005de2be59 new ratecontrol code
michaelni
parents:
diff changeset
94 }
c0005de2be59 new ratecontrol code
michaelni
parents:
diff changeset
95 p->s++; // "("
2434
24aa9209e8b0 simplify
michael
parents: 2433
diff changeset
96 d= evalExpression(p);
1815
2152760d08ad avoid negative array indices
alex
parents: 1598
diff changeset
97 if(p->s[0]== ','){
2152760d08ad avoid negative array indices
alex
parents: 1598
diff changeset
98 p->s++; // ","
2434
24aa9209e8b0 simplify
michael
parents: 2433
diff changeset
99 d2= evalExpression(p);
612
c0005de2be59 new ratecontrol code
michaelni
parents:
diff changeset
100 }
1815
2152760d08ad avoid negative array indices
alex
parents: 1598
diff changeset
101 if(p->s[0] != ')'){
2152760d08ad avoid negative array indices
alex
parents: 1598
diff changeset
102 av_log(NULL, AV_LOG_ERROR, "Parser: missing ) in \"%s\"\n", next);
2434
24aa9209e8b0 simplify
michael
parents: 2433
diff changeset
103 return NAN;
1815
2152760d08ad avoid negative array indices
alex
parents: 1598
diff changeset
104 }
2152760d08ad avoid negative array indices
alex
parents: 1598
diff changeset
105 p->s++; // ")"
2967
ef2149182f1c COSMETICS: Remove all trailing whitespace.
diego
parents: 2436
diff changeset
106
612
c0005de2be59 new ratecontrol code
michaelni
parents:
diff changeset
107 if( strmatch(next, "sinh" ) ) d= sinh(d);
c0005de2be59 new ratecontrol code
michaelni
parents:
diff changeset
108 else if( strmatch(next, "cosh" ) ) d= cosh(d);
c0005de2be59 new ratecontrol code
michaelni
parents:
diff changeset
109 else if( strmatch(next, "tanh" ) ) d= tanh(d);
c0005de2be59 new ratecontrol code
michaelni
parents:
diff changeset
110 else if( strmatch(next, "sin" ) ) d= sin(d);
c0005de2be59 new ratecontrol code
michaelni
parents:
diff changeset
111 else if( strmatch(next, "cos" ) ) d= cos(d);
c0005de2be59 new ratecontrol code
michaelni
parents:
diff changeset
112 else if( strmatch(next, "tan" ) ) d= tan(d);
c0005de2be59 new ratecontrol code
michaelni
parents:
diff changeset
113 else if( strmatch(next, "exp" ) ) d= exp(d);
c0005de2be59 new ratecontrol code
michaelni
parents:
diff changeset
114 else if( strmatch(next, "log" ) ) d= log(d);
c0005de2be59 new ratecontrol code
michaelni
parents:
diff changeset
115 else if( strmatch(next, "squish") ) d= 1/(1+exp(4*d));
c0005de2be59 new ratecontrol code
michaelni
parents:
diff changeset
116 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
117 else if( strmatch(next, "abs" ) ) d= fabs(d);
3755
882cf925ff7a cosmetic
michael
parents: 3754
diff changeset
118 else if( strmatch(next, "max" ) ) d= d > d2 ? d : d2;
882cf925ff7a cosmetic
michael
parents: 3754
diff changeset
119 else if( strmatch(next, "min" ) ) d= d < d2 ? d : d2;
882cf925ff7a cosmetic
michael
parents: 3754
diff changeset
120 else if( strmatch(next, "gt" ) ) d= d > d2 ? 1.0 : 0.0;
882cf925ff7a cosmetic
michael
parents: 3754
diff changeset
121 else if( strmatch(next, "gte" ) ) d= d >= d2 ? 1.0 : 0.0;
882cf925ff7a cosmetic
michael
parents: 3754
diff changeset
122 else if( strmatch(next, "lt" ) ) d= d > d2 ? 0.0 : 1.0;
882cf925ff7a cosmetic
michael
parents: 3754
diff changeset
123 else if( strmatch(next, "lte" ) ) d= d >= d2 ? 0.0 : 1.0;
612
c0005de2be59 new ratecontrol code
michaelni
parents:
diff changeset
124 else if( strmatch(next, "eq" ) ) d= d == d2 ? 1.0 : 0.0;
2434
24aa9209e8b0 simplify
michael
parents: 2433
diff changeset
125 else if( strmatch(next, "(" ) ) d= d;
612
c0005de2be59 new ratecontrol code
michaelni
parents:
diff changeset
126 // else if( strmatch(next, "l1" ) ) d= 1 + d2*(d - 1);
c0005de2be59 new ratecontrol code
michaelni
parents:
diff changeset
127 // else if( strmatch(next, "sq01" ) ) d= (d >= 0.0 && d <=1.0) ? 1.0 : 0.0;
c0005de2be59 new ratecontrol code
michaelni
parents:
diff changeset
128 else{
c0005de2be59 new ratecontrol code
michaelni
parents:
diff changeset
129 for(i=0; p->func1_name && p->func1_name[i]; i++){
c0005de2be59 new ratecontrol code
michaelni
parents:
diff changeset
130 if(strmatch(next, p->func1_name[i])){
2434
24aa9209e8b0 simplify
michael
parents: 2433
diff changeset
131 return p->func1[i](p->opaque, d);
612
c0005de2be59 new ratecontrol code
michaelni
parents:
diff changeset
132 }
c0005de2be59 new ratecontrol code
michaelni
parents:
diff changeset
133 }
c0005de2be59 new ratecontrol code
michaelni
parents:
diff changeset
134
c0005de2be59 new ratecontrol code
michaelni
parents:
diff changeset
135 for(i=0; p->func2_name && p->func2_name[i]; i++){
c0005de2be59 new ratecontrol code
michaelni
parents:
diff changeset
136 if(strmatch(next, p->func2_name[i])){
2434
24aa9209e8b0 simplify
michael
parents: 2433
diff changeset
137 return p->func2[i](p->opaque, d, d2);
612
c0005de2be59 new ratecontrol code
michaelni
parents:
diff changeset
138 }
c0005de2be59 new ratecontrol code
michaelni
parents:
diff changeset
139 }
c0005de2be59 new ratecontrol code
michaelni
parents:
diff changeset
140
2433
0934621b6453 simplify, null pointer, selftest
michael
parents: 1815
diff changeset
141 av_log(NULL, AV_LOG_ERROR, "Parser: unknown function in \"%s\"\n", next);
2434
24aa9209e8b0 simplify
michael
parents: 2433
diff changeset
142 return NAN;
612
c0005de2be59 new ratecontrol code
michaelni
parents:
diff changeset
143 }
2433
0934621b6453 simplify, null pointer, selftest
michael
parents: 1815
diff changeset
144
2434
24aa9209e8b0 simplify
michael
parents: 2433
diff changeset
145 return d;
2967
ef2149182f1c COSMETICS: Remove all trailing whitespace.
diego
parents: 2436
diff changeset
146 }
2436
86d14aebd527 simplify
michael
parents: 2434
diff changeset
147
2434
24aa9209e8b0 simplify
michael
parents: 2433
diff changeset
148 static double evalPow(Parser *p){
2436
86d14aebd527 simplify
michael
parents: 2434
diff changeset
149 int sign= (*p->s == '+') - (*p->s == '-');
86d14aebd527 simplify
michael
parents: 2434
diff changeset
150 p->s += sign&1;
86d14aebd527 simplify
michael
parents: 2434
diff changeset
151 return (sign|1) * evalPrimary(p);
2434
24aa9209e8b0 simplify
michael
parents: 2433
diff changeset
152 }
612
c0005de2be59 new ratecontrol code
michaelni
parents:
diff changeset
153
2434
24aa9209e8b0 simplify
michael
parents: 2433
diff changeset
154 static double evalFactor(Parser *p){
24aa9209e8b0 simplify
michael
parents: 2433
diff changeset
155 double ret= evalPow(p);
24aa9209e8b0 simplify
michael
parents: 2433
diff changeset
156 while(p->s[0]=='^'){
612
c0005de2be59 new ratecontrol code
michaelni
parents:
diff changeset
157 p->s++;
2434
24aa9209e8b0 simplify
michael
parents: 2433
diff changeset
158 ret= pow(ret, evalPow(p));
612
c0005de2be59 new ratecontrol code
michaelni
parents:
diff changeset
159 }
2434
24aa9209e8b0 simplify
michael
parents: 2433
diff changeset
160 return ret;
612
c0005de2be59 new ratecontrol code
michaelni
parents:
diff changeset
161 }
c0005de2be59 new ratecontrol code
michaelni
parents:
diff changeset
162
2434
24aa9209e8b0 simplify
michael
parents: 2433
diff changeset
163 static double evalTerm(Parser *p){
24aa9209e8b0 simplify
michael
parents: 2433
diff changeset
164 double ret= evalFactor(p);
24aa9209e8b0 simplify
michael
parents: 2433
diff changeset
165 while(p->s[0]=='*' || p->s[0]=='/'){
24aa9209e8b0 simplify
michael
parents: 2433
diff changeset
166 if(*p->s++ == '*') ret*= evalFactor(p);
24aa9209e8b0 simplify
michael
parents: 2433
diff changeset
167 else ret/= evalFactor(p);
612
c0005de2be59 new ratecontrol code
michaelni
parents:
diff changeset
168 }
2434
24aa9209e8b0 simplify
michael
parents: 2433
diff changeset
169 return ret;
612
c0005de2be59 new ratecontrol code
michaelni
parents:
diff changeset
170 }
c0005de2be59 new ratecontrol code
michaelni
parents:
diff changeset
171
2434
24aa9209e8b0 simplify
michael
parents: 2433
diff changeset
172 static double evalExpression(Parser *p){
2436
86d14aebd527 simplify
michael
parents: 2434
diff changeset
173 double ret= 0;
612
c0005de2be59 new ratecontrol code
michaelni
parents:
diff changeset
174
2434
24aa9209e8b0 simplify
michael
parents: 2433
diff changeset
175 if(p->stack_index <= 0) //protect against stack overflows
24aa9209e8b0 simplify
michael
parents: 2433
diff changeset
176 return NAN;
24aa9209e8b0 simplify
michael
parents: 2433
diff changeset
177 p->stack_index--;
24aa9209e8b0 simplify
michael
parents: 2433
diff changeset
178
2436
86d14aebd527 simplify
michael
parents: 2434
diff changeset
179 do{
86d14aebd527 simplify
michael
parents: 2434
diff changeset
180 ret += evalTerm(p);
86d14aebd527 simplify
michael
parents: 2434
diff changeset
181 }while(*p->s == '+' || *p->s == '-');
612
c0005de2be59 new ratecontrol code
michaelni
parents:
diff changeset
182
2434
24aa9209e8b0 simplify
michael
parents: 2433
diff changeset
183 p->stack_index++;
612
c0005de2be59 new ratecontrol code
michaelni
parents:
diff changeset
184
2434
24aa9209e8b0 simplify
michael
parents: 2433
diff changeset
185 return ret;
612
c0005de2be59 new ratecontrol code
michaelni
parents:
diff changeset
186 }
c0005de2be59 new ratecontrol code
michaelni
parents:
diff changeset
187
1057
bb5de8a59da8 * static,const,compiler warning cleanup
kabi
parents: 627
diff changeset
188 double ff_eval(char *s, double *const_value, const char **const_name,
bb5de8a59da8 * static,const,compiler warning cleanup
kabi
parents: 627
diff changeset
189 double (**func1)(void *, double), const char **func1_name,
612
c0005de2be59 new ratecontrol code
michaelni
parents:
diff changeset
190 double (**func2)(void *, double, double), char **func2_name,
c0005de2be59 new ratecontrol code
michaelni
parents:
diff changeset
191 void *opaque){
c0005de2be59 new ratecontrol code
michaelni
parents:
diff changeset
192 Parser p;
2967
ef2149182f1c COSMETICS: Remove all trailing whitespace.
diego
parents: 2436
diff changeset
193
2434
24aa9209e8b0 simplify
michael
parents: 2433
diff changeset
194 p.stack_index=100;
612
c0005de2be59 new ratecontrol code
michaelni
parents:
diff changeset
195 p.s= s;
c0005de2be59 new ratecontrol code
michaelni
parents:
diff changeset
196 p.const_value= const_value;
c0005de2be59 new ratecontrol code
michaelni
parents:
diff changeset
197 p.const_name = const_name;
c0005de2be59 new ratecontrol code
michaelni
parents:
diff changeset
198 p.func1 = func1;
c0005de2be59 new ratecontrol code
michaelni
parents:
diff changeset
199 p.func1_name = func1_name;
c0005de2be59 new ratecontrol code
michaelni
parents:
diff changeset
200 p.func2 = func2;
c0005de2be59 new ratecontrol code
michaelni
parents:
diff changeset
201 p.func2_name = func2_name;
c0005de2be59 new ratecontrol code
michaelni
parents:
diff changeset
202 p.opaque = opaque;
2967
ef2149182f1c COSMETICS: Remove all trailing whitespace.
diego
parents: 2436
diff changeset
203
2434
24aa9209e8b0 simplify
michael
parents: 2433
diff changeset
204 return evalExpression(&p);
612
c0005de2be59 new ratecontrol code
michaelni
parents:
diff changeset
205 }
2433
0934621b6453 simplify, null pointer, selftest
michael
parents: 1815
diff changeset
206
0934621b6453 simplify, null pointer, selftest
michael
parents: 1815
diff changeset
207 #ifdef TEST
2967
ef2149182f1c COSMETICS: Remove all trailing whitespace.
diego
parents: 2436
diff changeset
208 #undef printf
2433
0934621b6453 simplify, null pointer, selftest
michael
parents: 1815
diff changeset
209 static double const_values[]={
0934621b6453 simplify, null pointer, selftest
michael
parents: 1815
diff changeset
210 M_PI,
0934621b6453 simplify, null pointer, selftest
michael
parents: 1815
diff changeset
211 M_E,
0934621b6453 simplify, null pointer, selftest
michael
parents: 1815
diff changeset
212 0
0934621b6453 simplify, null pointer, selftest
michael
parents: 1815
diff changeset
213 };
0934621b6453 simplify, null pointer, selftest
michael
parents: 1815
diff changeset
214 static const char *const_names[]={
0934621b6453 simplify, null pointer, selftest
michael
parents: 1815
diff changeset
215 "PI",
0934621b6453 simplify, null pointer, selftest
michael
parents: 1815
diff changeset
216 "E",
0934621b6453 simplify, null pointer, selftest
michael
parents: 1815
diff changeset
217 0
0934621b6453 simplify, null pointer, selftest
michael
parents: 1815
diff changeset
218 };
0934621b6453 simplify, null pointer, selftest
michael
parents: 1815
diff changeset
219 main(){
2436
86d14aebd527 simplify
michael
parents: 2434
diff changeset
220 int i;
2433
0934621b6453 simplify, null pointer, selftest
michael
parents: 1815
diff changeset
221 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));
3730
aae4aed137ea K prefix
michael
parents: 3729
diff changeset
222 printf("%f == 0.931322575\n", ff_eval("80G/80Gi", const_values, const_names, NULL, NULL, NULL, NULL, NULL));
2967
ef2149182f1c COSMETICS: Remove all trailing whitespace.
diego
parents: 2436
diff changeset
223
2436
86d14aebd527 simplify
michael
parents: 2434
diff changeset
224 for(i=0; i<1050; i++){
86d14aebd527 simplify
michael
parents: 2434
diff changeset
225 START_TIMER
86d14aebd527 simplify
michael
parents: 2434
diff changeset
226 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
227 STOP_TIMER("ff_eval")
86d14aebd527 simplify
michael
parents: 2434
diff changeset
228 }
2433
0934621b6453 simplify, null pointer, selftest
michael
parents: 1815
diff changeset
229 }
0934621b6453 simplify, null pointer, selftest
michael
parents: 1815
diff changeset
230 #endif