/*
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*
*/
#include "precompiled.hpp"
#include "memory/allocation.inline.hpp"
#include "utilities/globalDefinitions.hpp"
#include "utilities/numberSeq.hpp"
}
if (_num == 0) {
// if the sequence is empty, the davg is the same as the value
// and the variance is 0
_dvariance = 0.0;
} else {
// otherwise, calculate both
}
}
if (_num == 0)
return 0.0;
else
}
if (_num <= 1)
return 0.0;
if (result < 0.0) {
// due to loss-of-precision errors, the variance might be negative
// by a small bit
// guarantee(-0.1 < result && result < 0.0,
// "if variance is negative, it should be very small");
result = 0.0;
}
return result;
}
}
return _davg;
}
if (_num <= 1)
return 0.0;
if (result < 0.0) {
// due to loss-of-precision errors, the variance might be negative
// by a small bit
"if variance is negative, it should be very small");
result = 0.0;
}
return result;
}
}
}
for (int i = 0; i < n; ++i) {
return false;
}
return true;
}
if (_num == 0) {
} else {
}
++_num;
}
for (int i = 0; i < _length; ++i)
_sequence[i] = 0.0;
}
TruncatedSeq::~TruncatedSeq() {
}
// get the oldest value in the sequence...
// ...remove it from the sum and sum of squares
// ...and update them with the new value
// now replace the old value with the new one
// only increase it if the buffer is not full
++_num;
}
// can't easily keep track of this incrementally...
if (_num == 0)
return 0.0;
for (int i = 1; i < _num; ++i) {
}
return ret;
}
if (_num == 0)
return 0.0;
return _sequence[last_index];
}
if (_num == 0)
return 0.0;
// index 0 always oldest value until the array is full
return _sequence[0];
else {
// since the array is full, _next is over the oldest value
}
}
if (_num == 0)
return 0.0;
for (int i = 0; i < _num; ++i) {
double x = (double) i;
x_squared_sum += x * x;
x_sum += x;
y_sum += y;
xy_sum += x * y;
}
}
s->print_cr("\t _num = %d, _sum = %7.3f, _sum_of_squares = %7.3f",
s->print_cr("\t _davg = %7.3f, _dvariance = %7.3f, _alpha = %7.3f",
}
}
for (int i = 0; i < _length; i++) {
if (i%5 == 0) {
s->cr();
s->print("\t");
}
}
s->print_cr("");
}