X-Git-Url: https://git.ucc.asn.au/?p=ipdf%2Fcode.git;a=blobdiff_plain;f=src%2Freal_fast2sum.h;fp=src%2Freal_fast2sum.h;h=d6214404695ed6110eb92409cc2b0fc782f7212a;hp=0000000000000000000000000000000000000000;hb=5e19040b00e135ead52e535165e079ee72059727;hpb=c9ce50e17952b0feeec68758444a50302a0aafba diff --git a/src/real_fast2sum.h b/src/real_fast2sum.h new file mode 100644 index 0000000..d621440 --- /dev/null +++ b/src/real_fast2sum.h @@ -0,0 +1,57 @@ +#ifndef _REAL_FAST2SUM_H +#define _REAL_FAST2SUM_H + +#include +// otherwise the abs() function won't work + +namespace IPDF +{ + + template + struct RealF2S + { + RealF2S(const T & value = 0.0L) : m_value(value) {} //{Debug("Construct from value %f", m_value);} + RealF2S(const RealF2S & cpy) : m_value(cpy.m_value) {} //{Debug("Copy construct from value %f", m_value);} + + RealF2S & operator+=(const RealF2S & a) {this->operator=(RealF2S(*this) + a); return *this;} + RealF2S & operator-=(const RealF2S & a) {this->operator=(RealF2S(*this) - a); return *this;} + RealF2S & operator*=(const RealF2S & a) {this->operator=(RealF2S(*this) * a); return *this;} + RealF2S & operator/=(const RealF2S & a) {this->operator=(RealF2S(*this) / a); return *this;} + + RealF2S & operator=(const RealF2S & equ) {this->m_value = equ.m_value; return *this;} + RealF2S & operator=(const T & equ) {this->m_value = equ.m_value; return *this;} + + T m_value; + }; + + + + template RealF2S operator+(const RealF2S & a, const RealF2S & b) + { + // Use fast2sum + if (abs(T(a.m_value)) < abs(T(b.m_value))) + return b+a; + T z = a.m_value + b.m_value; + T w = z - a.m_value; + T zz = b.m_value - w; + return RealF2S(z + zz); + } + template RealF2S operator-(const RealF2S & a, const RealF2S & b) + { + // Use fast2sum + return a + RealF2S(-b.m_value); + } + + template RealF2S operator*(const RealF2S & a, const RealF2S & b) + { + return RealF2S(a.m_value * b.m_value); + } + template RealF2S operator/(const RealF2S & a, const RealF2S & b) + { + return RealF2S(a.m_value / b.m_value); + } + + +} + +#endif //_REAL_FAST2SUM_H