--- trunk/gadget/popinfo.h 2014/02/10 17:09:07 1 +++ trunk/gadget/popinfo.h 2015/04/29 12:55:30 2 @@ -2,6 +2,7 @@ #define popinfo_h #include "gadget.h" +#include "mathfunc.h" /** * \class PopInfo @@ -48,7 +49,24 @@ * \brief This operator will add an existing PopInfo to the current PopInfo * \param a is the PopInfo to add */ - PopInfo& operator += (const PopInfo& a); + PopInfo& operator += (const PopInfo& a){ + if (isZero(N + a.N)) { + W = 0.0; + N = 0.0; + } else if (isZero(a.N)) { + //adding a zero popinfo, so don't do anything + } else if (isZero(N)) { + W = a.W; + N = a.N; + } else { + W = (N * W + a.N * a.W) / (N + a.N); + N = N + a.N; + } + return *this; + } + + + ; /** * \brief This operator will multiply the PopInfo by a constant * \param a is the constant