我有一个返回双精度数组的函数。在我的调试器中,我检查了数组,发现它的值为 {6.5, 1.5}。但是,当我将数组打印到 cout 时,我看到“6.5,3.30525e+230”。我的猜测是 << 正在改变我的值或者我没有正确格式化
double *result;
result = haar1d(series, 2, seriesAverage);
--> 在断点处,我看到了 result[0] == 6.5 和 result[1] == 1.5
for(int i = 0; i < 2; i++)
{
cout << result[i] << ",";
}
固定:这就是我最终得到的。
vector<double> haar1d(vector<double> vec, double seriesAverage)
{
vector<double> transVec(vec.size(), 0);
vector<double>::size_type length = vec.size();
if(vec[0] == seriesAverage)
{
return vec;
}
int diffFromAvgs = length / 2;
for(int i = 0; i < length; i += 2)
{
double pairAverage = (vec[i] + vec[i + 1]) / 2;
transVec[i] = pairAverage;
transVec[diffFromAvgs+i] = vec[i] - pairAverage;
}
return haar1d(transVec, seriesAverage);
}
主要:
vector<double> result = haar1d(series, avg);
for(vector<double>::iterator it = result.begin(); it != result.end(); ++it)
{
cout << *it << ",";
}