在c#中进行不规则计算时会发生什么

本文关键字:什么 计算 不规则 | 更新日期: 2023-09-27 18:01:58

我目前正在实现一个函数绘图仪,到目前为止我得到了一切工作,除了我必须做不规则计算的情况,如1/(x-2), x=2

现在,我的代码看起来是这样的(当然是简化的):
for(int i = minxvalue; i <= maxxvalue; i++) {
    double y = ParseFunction(functionstring); //Parses the given string containing the user-entered function and returns the resulting y-value as double
    coordinatelist.Add(new Coordinate(i, y);}//Saves the value-pair to a list with all valid points of the function-graph

我的问题是,在计算Math.Sqrt(-2), 1/0等的情况下,我期望y是什么?到目前为止,我注意到受影响的计算被遗漏了,因为它没有出现在我的坐标列表中,但是必须有一个返回值,对吗?

在c#中进行不规则计算时会发生什么

您的计算可能返回Not A Number

可能需要更多的代码来看看会发生什么,但这里有MSDN文档: NaN