Modular Megafauna Model 1.1.5
A physiological, dynamic herbivore simulator in C++.
Loading...
Searching...
No Matches
average.h
Go to the documentation of this file.
1// SPDX-FileCopyrightText: 2020 W. Traylor <wolfgang.traylor@senckenberg.de>
2//
3// SPDX-License-Identifier: LGPL-3.0-or-later
4
11#ifndef FAUNA_AVERAGE_H
12#define FAUNA_AVERAGE_H
13
14#include <vector>
15
16namespace Fauna {
17
19
28double average(const double a, const double b, const double weight_a = 1.0,
29 const double weight_b = 1.0);
30
32
45 public:
47
51 PeriodAverage(const int count);
52
54 void add_value(const double);
55
57
60 double get_average() const;
61
63
66 double get_first() const;
67
68 private:
69 std::vector<double> values;
70 unsigned int count; // constant
71 unsigned int current_index = 0;
72};
73
74} // namespace Fauna
75#endif // FAUNA_AVERAGE_H
Average of a double value over a given time period.
Definition: average.h:44
void add_value(const double)
Add a value to the record.
Definition: average.cpp:60
unsigned int count
Definition: average.h:70
double get_first() const
Get first (oldest) value in the record.
Definition: average.cpp:81
double get_average() const
Get arithmetic mean over all so-far recorded values.
Definition: average.cpp:71
unsigned int current_index
Definition: average.h:71
std::vector< double > values
Definition: average.h:69
Definition: average.h:16
double average(const double a, const double b, const double weight_a=1.0, const double weight_b=1.0)
Build weighted average of two numbers.
Definition: average.cpp:25