Skip to content
Snippets Groups Projects
Commit f02c2068 authored by Daniel Simon's avatar Daniel Simon
Browse files

Draft of Double precision. TODO: double precision algorhitms, operators

parent 37f2d50d
No related branches found
No related tags found
No related merge requests found
......@@ -3,4 +3,59 @@
* created: December 6, 2017 *
* author: Daniel Simon *
* mail: dansimon93@gmail.com *
***************************************************/
\ No newline at end of file
***************************************************/
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
......@@ -3,4 +3,75 @@
* created: December 6, 2017 *
* author: Daniel Simon *
* mail: dansimon93@gmail.com *
***************************************************/
\ No newline at end of file
***************************************************/
#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
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment