gpt4 book ai didi

c# - 如何在 C# 中使用 System.Data.Compute() 计算 sin

转载 作者:行者123 更新时间:2023-11-30 14:48:01 24 4
gpt4 key购买 nike

我是新来的!我是 C# 新手。我的一位 friend 向我发起挑战,要求我创建科学计算器。我搜索并找到了一种简单的方法来实现它 - 使用 System.Data 库。例如,我们有这样的:

string math = "5 + 3 * 3";
string answer = new DataTable().Compute(math, null).ToString();

这对于基本表达式来说非常容易,但我似乎找不到一种方法让计算器能够计算 sin、cos 等。有人有想法吗?

PS:我英语不好,请原谅我

最佳答案

感谢 Mat J 告诉我有关 mXparser 的信息!我找到了一种无需更改大量代码即可计算的方法!

这是 mXparser:http://mathparser.org/

代码的变化如下:它是:

string math = "5 + 3 * 3";
string answer = new DataTable().Compute(math, null).ToString();

现在是:

string math = "5 + 3 * 3";
Expression e = new Expression(math);
math = e.calculate();

唯一的事情是它使用表达式而不是字符串,但它仍然工作得非常简单!

我要感谢大家的快速答复!你真的帮了我大忙!

关于c# - 如何在 C# 中使用 System.Data.Compute() 计算 sin,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42750507/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com