tbf/TestBenchFramework/BenchControl/Sequences/FloatStatistics.cs

64 lines
1.2 KiB
C#

using System;
namespace TBF.BenchControl.Sequences
{
public class FloatStatistics
{
float first;
float last;
float min;
float max;
float sum;
UInt32 count;
public float First { get { return first; } }
public float Last { get { return last; } }
public float Min { get { return min; } }
public float Max { get { return max; } }
public float Average { get { if (Count > 0) return sum / (float)count; else return 0; } }
public UInt32 Count { get { return count; } }
public FloatStatistics()
{
Clear();
}
/// <summary>
/// Resets statistics
/// </summary>
public void Clear()
{
sum = 0;
min = float.MaxValue;
max = float.MinValue;
first = 0;
last = 0;
count = 0;
}
/// <summary>
/// Updates statistics
/// </summary>
/// <param name="value">New value</param>
public void Update(float value)
{
if (count == 0) first = value;
last = value;
sum += value;
if (value < min) min = value;
if (value > max) max = value;
count++;
}
/// <summary>
/// Updates statistics
/// </summary>
/// <param name="value">New boxed value</param>
public void Update(TBF.Boxes.FloatBox box)
{
Update(box.Val);
}
}
}