Commit 7f77ea04 authored by 潘栩锋's avatar 潘栩锋 🚴

修复 sigma函数没有检测数据范围

parent 7df48248
...@@ -283,6 +283,7 @@ namespace Misc ...@@ -283,6 +283,7 @@ namespace Misc
/// <returns></returns> /// <returns></returns>
public static double Sigma(IEnumerable<double> buf, int first, int last) public static double Sigma(IEnumerable<double> buf, int first, int last)
{ {
double avg = Avg(buf, first, last); double avg = Avg(buf, first, last);
if (double.IsNaN(avg)) if (double.IsNaN(avg))
return double.NaN; return double.NaN;
...@@ -291,6 +292,8 @@ namespace Misc ...@@ -291,6 +292,8 @@ namespace Misc
int cnt = 0; int cnt = 0;
for (int i = first; i <= last; i++) for (int i = first; i <= last; i++)
{
if ((i >= 0) && (i < buf.Count()))
{ {
if (!double.IsNaN(buf.ElementAt(i))) if (!double.IsNaN(buf.ElementAt(i)))
{ {
...@@ -298,6 +301,7 @@ namespace Misc ...@@ -298,6 +301,7 @@ namespace Misc
cnt++; cnt++;
} }
} }
}
if (cnt >= 3) if (cnt >= 3)
return (Math.Sqrt(sum / (cnt - 1))); return (Math.Sqrt(sum / (cnt - 1)));
else else
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment