-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(DataTomeCumulative): ✨ add DataTomeCumulative class
add DataTomeCumulative to calculate the cumulative average #9
- Loading branch information
1 parent
0edbc8f
commit 7fa4acd
Showing
8 changed files
with
56 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
name=DataTome | ||
version=1.7.0 | ||
version=1.8.0 | ||
author=Alexandre Hiroyuki Yamauchi <[email protected]> | ||
maintainer=Alexandre Hiroyuki Yamauchi <[email protected]> | ||
sentence=Data analysis and filtering using time series for embedded devices (IoT). All in a single C++ library, Data Tome. | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
/*************************************************************** | ||
DataTomeCumulative.h | ||
Created by Alexandre Hiroyuki Yamauchi, September 23, 2024. | ||
***************************************************************/ | ||
|
||
#ifndef DATA_TOME_CUMULATIVE_H | ||
#define DATA_TOME_CUMULATIVE_H | ||
|
||
#include <limits.h> | ||
|
||
// WARNING: using this class with integer types may result in loss of precision | ||
// due to cumulative integer divisions rounding. | ||
template <typename TypeOfSum> | ||
class DataTomeCumulative { | ||
protected: | ||
TypeOfSum _cumulative_average; | ||
unsigned long int _count; | ||
|
||
public: | ||
DataTomeCumulative() : _cumulative_average(0), _count(0) {} | ||
|
||
DataTomeCumulative<TypeOfSum> &push(TypeOfSum input) { | ||
if (_count >= ULONG_MAX) { | ||
_cumulative_average = 0; | ||
_count = 0; | ||
} | ||
|
||
_cumulative_average += (input - _cumulative_average) / (_count + 1); | ||
|
||
_count++; | ||
return *this; | ||
} | ||
|
||
TypeOfSum get() { return _cumulative_average; } | ||
}; | ||
|
||
#endif // DATA_TOME_CUMULATIVE_H |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters