Loading src/TNL/Experimental/Arithmetics/Double.h +56 −1 Original line number Diff line number Diff line Loading @@ -4,3 +4,58 @@ * author: Daniel Simon * * mail: dansimon93@gmail.com * ***************************************************/ namespace TNL { template <class T> class Double { public: T data[2]; Double(); Double(const Double<T>& value); explicit Double(const T& value); explicit Double(int value); Double<T>& operator=(const Double<T>& rhs); Double<T>& operator-(); Double<T>& operator+(); Double<T>& operator+=(const Double<T>& rhs); Double<T>& operator-=(const Double<T>& rhs); Double<T>& operator*=(const Double<T>& rhs); Double<T>& operator/=(const Double<T>& rhs); Double<T> operator+(const Double<T>& rhs) const; Double<T> operator-(const Double<T>& rhs) const; Double<T> operator*(const Double<T>& rhs) const; Double<T> operator/(const Double<T>& rhs) const; bool operator==(const Double<T>& rhs) const; bool operator!=(const Double<T>& rhs) const; bool operator<(const Double<T>& rhs) const; bool operator>(const Double<T>& rhs) const; bool operator>=(const Double<T>& rhs) const; bool operator<=(const Double<T>& rhs) const; explicit operator T() const; }; /// TODO template <typename T> void zeroDouble(T *d); template <typename T> void twoSum(T a, T b, T *s, T *e); template <typename T> void quickTwoSum(T a, T b, T *s, T *e); template <typename T> void split(T a, T *a_hi, T *a_lo); template <typename T> void twoProduct(T a, T b, T *p, T *e); template <typename T> void renormalize(T *a, T *b); template <typename T> void doubleAdd(const T *a, const T *b, T *s); template <typename T> void doubleMul(const T *a, const T *b, T *s); template <typename T> void printDouble(T *d); } // namespace TNL No newline at end of file src/TNL/Experimental/Arithmetics/Double_impl.h +72 −1 Original line number Diff line number Diff line Loading @@ -4,3 +4,74 @@ * author: Daniel Simon * * mail: dansimon93@gmail.com * ***************************************************/ #include <cmath> #include <cstdio> #include "Double.h" namespace TNL { template <class T> Double<T>::Double() { zeroDouble(data); } template <class T> Double<T>::Double(const T& value) { data[0] = value; data[1] = 0; } template <class T> Double<T>::Double(int value) { data[0] = (T)value; data[1] = 0; } template <class T> Double<T>::Double(const Double<T>& other) { data[0] = other[0]; data[1] = other[1]; } template <class T> Double<T>& Double<T>::operator =(const Double<T>& rhs) { data[0] = rhs[0]; data[1] = rhs[1]; return *this; } template <class T> Double<T> Double<T>::operator +(const Double<T>& rhs) const{ Double<T> lhs(*this); lhs += rhs; return qd; } template <class T> Double<T> Double<T>::operator -(const Double<T>& rhs) const{ Double<T> lhs(*this); lhs += rhs; return qd; } template <class T> Double<T> Double<T>::operator *(const Double<T>& rhs) const{ Double<T> lhs(*this); lhs *= rhs; return qd; } template <class T> Double<T> Double<T>::operator /(const Double<T>& rhs) const{ Double<T> lhs(*this); lhs /= rhs; return qd; } /* TODO COMPARISON OPERATORS */ } // namespace TNL No newline at end of file Loading
src/TNL/Experimental/Arithmetics/Double.h +56 −1 Original line number Diff line number Diff line Loading @@ -4,3 +4,58 @@ * author: Daniel Simon * * mail: dansimon93@gmail.com * ***************************************************/ namespace TNL { template <class T> class Double { public: T data[2]; Double(); Double(const Double<T>& value); explicit Double(const T& value); explicit Double(int value); Double<T>& operator=(const Double<T>& rhs); Double<T>& operator-(); Double<T>& operator+(); Double<T>& operator+=(const Double<T>& rhs); Double<T>& operator-=(const Double<T>& rhs); Double<T>& operator*=(const Double<T>& rhs); Double<T>& operator/=(const Double<T>& rhs); Double<T> operator+(const Double<T>& rhs) const; Double<T> operator-(const Double<T>& rhs) const; Double<T> operator*(const Double<T>& rhs) const; Double<T> operator/(const Double<T>& rhs) const; bool operator==(const Double<T>& rhs) const; bool operator!=(const Double<T>& rhs) const; bool operator<(const Double<T>& rhs) const; bool operator>(const Double<T>& rhs) const; bool operator>=(const Double<T>& rhs) const; bool operator<=(const Double<T>& rhs) const; explicit operator T() const; }; /// TODO template <typename T> void zeroDouble(T *d); template <typename T> void twoSum(T a, T b, T *s, T *e); template <typename T> void quickTwoSum(T a, T b, T *s, T *e); template <typename T> void split(T a, T *a_hi, T *a_lo); template <typename T> void twoProduct(T a, T b, T *p, T *e); template <typename T> void renormalize(T *a, T *b); template <typename T> void doubleAdd(const T *a, const T *b, T *s); template <typename T> void doubleMul(const T *a, const T *b, T *s); template <typename T> void printDouble(T *d); } // namespace TNL No newline at end of file
src/TNL/Experimental/Arithmetics/Double_impl.h +72 −1 Original line number Diff line number Diff line Loading @@ -4,3 +4,74 @@ * author: Daniel Simon * * mail: dansimon93@gmail.com * ***************************************************/ #include <cmath> #include <cstdio> #include "Double.h" namespace TNL { template <class T> Double<T>::Double() { zeroDouble(data); } template <class T> Double<T>::Double(const T& value) { data[0] = value; data[1] = 0; } template <class T> Double<T>::Double(int value) { data[0] = (T)value; data[1] = 0; } template <class T> Double<T>::Double(const Double<T>& other) { data[0] = other[0]; data[1] = other[1]; } template <class T> Double<T>& Double<T>::operator =(const Double<T>& rhs) { data[0] = rhs[0]; data[1] = rhs[1]; return *this; } template <class T> Double<T> Double<T>::operator +(const Double<T>& rhs) const{ Double<T> lhs(*this); lhs += rhs; return qd; } template <class T> Double<T> Double<T>::operator -(const Double<T>& rhs) const{ Double<T> lhs(*this); lhs += rhs; return qd; } template <class T> Double<T> Double<T>::operator *(const Double<T>& rhs) const{ Double<T> lhs(*this); lhs *= rhs; return qd; } template <class T> Double<T> Double<T>::operator /(const Double<T>& rhs) const{ Double<T> lhs(*this); lhs /= rhs; return qd; } /* TODO COMPARISON OPERATORS */ } // namespace TNL No newline at end of file