10#ifndef MATH_ACCUM_HEADER
11#define MATH_ACCUM_HEADER
45 Accum (T
const& init);
48 void add (T
const& value,
float weight);
51 void sub (T
const& value,
float weight);
58 T normalized (
float weight)
const;
65 T normalized (
void)
const;
88 this->v += value * weight;
96 this->v -= value * weight;
104 return this->v / weight;
111 return this->v / this->w;
126 void add (
unsigned char const& value,
float weight);
127 void sub (
unsigned char const& value,
float weight);
149 this->v +=
static_cast<float>(value) * weight;
156 this->v -=
static_cast<float>(value) * weight;
163 return static_cast<unsigned char>(
math::round(this->v / weight));
169 return static_cast<unsigned char>(
math::round(this->v / this->w));
void add(unsigned char const &value, float weight)
Accum(unsigned char const &init)
unsigned char normalized(float weight) const
void sub(unsigned char const &value, float weight)
unsigned char normalized(void) const
Accumulator class that operates on arbitrary types.
T normalized(void) const
Returns a normalized version of the internal value, i.e.
void sub(T const &value, float weight)
Subtracts the weighted given value from the internal value.
void add(T const &value, float weight)
Adds the weighted given value to the internal value.
Accum(void)
Leaves internal value uninitialized.
#define MATH_NAMESPACE_BEGIN
#define MATH_NAMESPACE_END
T round(T const &x)
Removes the fractional part of the value to the closest integer.