Skip to content

Misleading example in BasicSignals.cpp / Example 4 #2

@klaufir

Description

@klaufir
        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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions