From 5d2cc1b29c00a3e4a63bcf87d6d0baac579aea76 Mon Sep 17 00:00:00 2001 From: Thorsten Sommer Date: Tue, 29 Sep 2020 17:30:07 +0200 Subject: [PATCH] Refactored --- FastRngTests/Double/RunningStatistics.cs | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/FastRngTests/Double/RunningStatistics.cs b/FastRngTests/Double/RunningStatistics.cs index f1b5210..4558a11 100644 --- a/FastRngTests/Double/RunningStatistics.cs +++ b/FastRngTests/Double/RunningStatistics.cs @@ -24,23 +24,23 @@ namespace FastRngTests.Double // See Knuth TAOCP vol 2, 3rd edition, page 232 if (this.NumberRecords == 1) { - previousM = nextM = x; - previousS = 0.0; + this.previousM = this.nextM = x; + this.previousS = 0.0; } else { - nextM = previousM + (x - previousM) / this.NumberRecords; - nextS = previousS + (x - previousM) * (x - nextM); + this.nextM = this.previousM + (x - this.previousM) / this.NumberRecords; + this.nextS = this.previousS + (x - this.previousM) * (x - this.nextM); // set up for next iteration - previousM = nextM; - previousS = nextS; + this.previousM = this.nextM; + this.previousS = this.nextS; } } - public double Mean => this.NumberRecords > 0 ? nextM : 0.0; + public double Mean => this.NumberRecords > 0 ? this.nextM : 0.0; - public double Variance => this.NumberRecords > 1 ? nextS / (NumberRecords - 1) : 0.0; + public double Variance => this.NumberRecords > 1 ? this.nextS / (this.NumberRecords - 1) : 0.0; public double StandardDeviation => Math.Sqrt(this.Variance); }