165{
166 if (argc <= 2) {
167 fprintf(stderr, "calc \"var1 var2 ...\" \"function of var\"\n");
168 fprintf(stderr, "eg. calc x \"x*x\"\n");
169 fprintf(stderr, "eg. calc \"x y z\" \"x*x + y - z\"\n");
170 return 1;
171 }
172 const char *poly =
argv[2];
173 try {
174 std::vector<std::string> varTbl;
175
176
177 {
178 std::istringstream is(
argv[1]);
179 int i = 0;
181 while (is) {
182 std::string var;
183 is >> var;
184 if (var.empty()) break;
185 printf(
"%s:%d, ", var.c_str(), i);
186 varTbl.push_back(var);
187 i++;
188 }
190 }
193 boost::spirit::classic::parse_info<>
r = parse(poly, calc, boost::spirit::classic::space_p);
195 printf(
"err poly=%s\n", poly);
196 return 1;
197 }
198 funcGen.complete();
199 std::vector<double> valTbl;
200 valTbl.resize(varTbl.size());
201#ifdef XBYAK32
202 puts("32bit mode");
203 void (*func)(
double *
ret,
const double *valTbl) = funcGen.getCode<void (*)(
double *,
const double*)>();
204#else
205 puts("64bit mode");
206 double (*func)(const double *valTbl) = funcGen.getCode<double (*)(const double*)>();
207#endif
208 for (int i = 0; i < 10; i++) {
209 for (
size_t j = 0, n = valTbl.size();
j < n;
j++) {
210 valTbl[
j] = rand() % 7;
211 }
213#ifdef XBYAK32
214 func(&y, &valTbl[0]);
215#else
216 y =
func(&valTbl[0]);
217#endif
219 }
220 } catch (std::exception& e) {
221 printf(
"ERR:%s\n", e.what());
222 }
catch (
Error err) {
224 } catch (...) {
225 printf(
"unknown error\n");
226 }
227
228 return 0;
229}
LOGGING_API void printf(Category category, const char *format,...)
void calc(void const *src, size_t bytelength, unsigned char *hash)
Calculate a SHA1 hash.