简体   繁体   English

数学printf风格计算

[英]mathematical printf style calculation

I'm looking for an flexible but also considerably fast way to do simple value conversion and calculations at the basis of descriptive calculator strings. 我正在寻找一种灵活但快速的方法来在描述性计算器字符串的基础上进行简单的值转换和计算。

For example something like this: 例如这样的事情:

double r = 1.0;
double d = mathf( "sin(%1)+2*%2", r, M_PI );
double e = mathf( "%1 / 180.0 * %2", r, M_PI );

The important think is the mathematical operations can be evaluated at runtime and loaded from config file. 重要的想法是可以在运行时评估数学运算并从配置文件加载。 I was even considering some sort of scripting language integration but it seems that doesn't come in sleek and fast? 我甚至考虑过某种脚本语言集成,但似乎并不是时髦而快速的?

Any ideas if something like mathf exists for C++? 如果像C ++这样的东西存在于C ++中的任何想法?

Try searching around a little more. 尝试多搜索一下。 This is a pretty common thing. 这是很常见的事情。 It's parsing, and every compiler does it. 它正在解析,每个编译器都会这样做。 Makes this a bit like parsception. 使这有点像parsception。

Solve equation from string to result in C 从字符串求解方程式到C的结果

Evaluate a simple string mathmatical expression 评估一个简单的字符串数学表达式

Convert string to mathematical evaluation 将字符串转换为数学评估

etc etc. 等等

There's two ways to go about it, one is write your own, the second is find a library which seems like what you're looking for. 有两种方法可以解决它,一种是自己编写,另一种是找到一个看起来像你正在寻找的库。 I don't know of anything like that in the C++ standard libs, in ruby and a bunch of other languages for sure, you can just eval the string, but in C++ you're probably going to have to borrow a library from the web or something. 我不知道C ++标准库中的任何类似内容,ruby和其他一些语言肯定,你可以只评估字符串,但在C ++中你可能不得不从Web借用一个库或者其他的东西。 Try that last link, it looked promising for that. 尝试最后一个链接,看起来很有希望。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM