mirror of
https://github.com/betaflight/betaflight.git
synced 2025-07-20 06:45:16 +03:00
Use slightly flatter directory structure since some developers did not
like too many folders. Extracted code from some files into separate files to fit with the new layout.
This commit is contained in:
parent
39adc34278
commit
3bd4cd2ed2
84 changed files with 732 additions and 645 deletions
42
src/maths.c
Normal file
42
src/maths.c
Normal file
|
@ -0,0 +1,42 @@
|
|||
#include <math.h>
|
||||
|
||||
#include "maths.h"
|
||||
|
||||
int constrain(int amt, int low, int high)
|
||||
{
|
||||
if (amt < low)
|
||||
return low;
|
||||
else if (amt > high)
|
||||
return high;
|
||||
else
|
||||
return amt;
|
||||
}
|
||||
|
||||
void devClear(stdev_t *dev)
|
||||
{
|
||||
dev->m_n = 0;
|
||||
}
|
||||
|
||||
void devPush(stdev_t *dev, float x)
|
||||
{
|
||||
dev->m_n++;
|
||||
if (dev->m_n == 1) {
|
||||
dev->m_oldM = dev->m_newM = x;
|
||||
dev->m_oldS = 0.0f;
|
||||
} else {
|
||||
dev->m_newM = dev->m_oldM + (x - dev->m_oldM) / dev->m_n;
|
||||
dev->m_newS = dev->m_oldS + (x - dev->m_oldM) * (x - dev->m_newM);
|
||||
dev->m_oldM = dev->m_newM;
|
||||
dev->m_oldS = dev->m_newS;
|
||||
}
|
||||
}
|
||||
|
||||
float devVariance(stdev_t *dev)
|
||||
{
|
||||
return ((dev->m_n > 1) ? dev->m_newS / (dev->m_n - 1) : 0.0f);
|
||||
}
|
||||
|
||||
float devStandardDeviation(stdev_t *dev)
|
||||
{
|
||||
return sqrtf(devVariance(dev));
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue