Closed klaufir closed 10 years ago
SignalT<float> Average = Iterate( Input, 0.0f, [] (int sample, float oldAvg) { return (oldAvg + sample) / 2.0f; });
This does not calculate an average. This code calculates
Therefore, the code
Sensor mySensor; mySensor.Input << 10 << 5 << 10 << 8; cout << "Average: " << mySensor.Average() << endl;
Produces the output
Example 4 - Creating stateful signals (2) Average: 7.75
The average of the values (10, 5, 10, 8) is 8.25, not 7.75.
8.25
7.75
This does not calculate an average. This code calculates
Therefore, the code
Produces the output
The average of the values (10, 5, 10, 8) is
8.25
, not7.75
.