请注意,本文内容源自机器翻译,可能存在语法或其它翻译错误,仅供参考。如需获取准确内容,请参阅链接中的英语原文或自行翻译。
器件型号:MSP430FR2033 您好!
我将编写一个移动平均法函数、但得到标题中提到的错误。 我想了解误差的含义以及如何避免它。
下面是代码:
// This part resides in the source file
int movingAverage(int *ptrArrNumbers, long *ptrSum, int pos, int len, int nextNum)
{
*ptrSum = *ptrSum - ptrArrNumbers[pos] + nextNum;
ptrArrNumbers[pos] = nextNum;
return *ptrSum/len;
}
// This part resides in my main source file, but it is not "main.c".
// It is something else
if(pos0==arr0Length)
{
arr0Filled = 1;
pos0 = 0;
}
// If the array has not been fully filled we only consider the number of cases filled with a pressure value
// to calculate the average pressure (len0). When the array is filled, len0 is the length of the array
if(arr0Filled == 0)
{
len0=pos0+1;
}
else
{
len0=arr0Length;
}
// Moving average
newAvg0 = movingAvg(arr0Numbers, &sum0, pos0, len0, pressure0);
pos0++;
谢谢你