#define REAL_SINGLE 0
#define REAL_DOUBLE 1
#define REAL_LONG_DOUBLE 2
-#define REAL_SINGLE_FAST2SUM 3 //TODO: Remove, is FITH
+#define REAL_VFPU 3
#define REAL_RATIONAL 4
#define REAL_RATIONAL_ARBINT 5
#error "REAL was not defined!"
#endif
-#if REAL >= REAL_SINGLE_FAST2SUM
- #include "real_fast2sum.h"
-#endif //REAL
+#if REAL == REAL_VFPU
+ #include "vfpu.h"
+#endif
#if REAL == REAL_RATIONAL
#include "rational.h"
typedef double Real;
#elif REAL == REAL_LONG_DOUBLE
typedef long double Real;
-#elif REAL == REAL_SINGLE_FAST2SUM
- typedef RealF2S<float> Real;
+#elif REAL == REAL_VFPU
+ typedef VFPU::Float Real;
inline float Float(const Real & r) {return r.m_value;}
inline double Double(const Real & r) {return r.m_value;}
#elif REAL == REAL_RATIONAL
namespace VFPU
{
-
+
static const char g_fpu[] = "vfpu";
static bool g_running = false;
Register Exec(const Register & a, const Register & b, Opcode op, Rmode rmode)
{
assert(g_running);
- Fatal("Unsupported");
stringstream s;
- //TODO: Make it compile again
- //s << hex << setw(8) << setfill('0') << a.to_ullong() << "\n" << b.to_ullong() << "\n" << setw(1) << op <<"\n" << setw(1) << rmode << "\n";
+ //TODO: Make it compile on non C++11
+ s << hex << setw(8) << setfill('0') << a.to_ullong() << "\n" << b.to_ullong() << "\n" << setw(1) << op <<"\n" << setw(1) << rmode << "\n";
string str(s.str());
//Debug("Writing: %s", str.c_str());
}
stringstream s2;
- //TODO: Make it comp[ile again
- //s2 << hex << result.to_ullong();
+ //TODO: Make it compile on non C++11
+ s2 << hex << result.to_ullong();
//Debug("Result is: %s", s2.str().c_str());
return result;
}
typedef std::bitset<32> Register;
extern Register Exec(const Register & a, const Register & b, Opcode op, Rmode rmode = EVEN); // operate with registers
extern float Exec(float a, float b, Opcode op, Rmode rmode = EVEN); //converts floats into registers and back
+
+ class Float
+ {
+ public:
+ Float(float f = 0) : m_value(f)
+ {
+ static bool init = false;
+ if (!init)
+ {
+ init = true;
+ VFPU::Start();
+ }
+ }
+ Float(const Float & cpy) : m_value(cpy.m_value) {}
+ virtual ~Float()
+ {
+
+ }
+
+ Float & operator+=(const Float & op)
+ {
+ m_value = Exec(m_value, op.m_value, ADD);
+ return *this;
+ }
+ Float & operator-=(const Float & op)
+ {
+ m_value = Exec(m_value, op.m_value, SUB);
+ return *this;
+ }
+ Float & operator*=(const Float & op)
+ {
+ m_value = Exec(m_value, op.m_value, MULT);
+ return *this;
+ }
+ Float & operator/=(const Float & op)
+ {
+ m_value = Exec(m_value, op.m_value, DIV);
+ return *this;
+ }
+
+ Float operator+(const Float & op) const {Float f(*this); f+=op; return f;}
+ Float operator-(const Float & op) const {Float f(*this); f-=op; return f;}
+ Float operator*(const Float & op) const {Float f(*this); f*=op; return f;}
+ Float operator/(const Float & op) const {Float f(*this); f/=op; return f;}
+
+ bool operator==(const Float & op) const
+ {
+ Float f(op);
+ f -= *this;
+ return (f.m_value == 0);
+ }
+ bool operator!=(const Float & op) const {return !this->operator==(op);}
+ bool operator<(const Float & op) const
+ {
+ Float f(op);
+ f -= *this;
+ return (f.m_value > 0);
+ }
+ bool operator<=(const Float & op) const
+ {
+ Float f(op);
+ f -= *this;
+ return (f.m_value >= 0);
+ }
+ bool operator>(const Float & op) const {return !this->operator<=(op);}
+ bool operator>=(const Float & op) const {return !this->operator<(op);}
+
+ float m_value;
+
+ };
+
+ inline Float pow(const Float & a, const Float & b)
+ {
+ return Float(pow(a.m_value, b.m_value));
+ }
}
#endif //_VFPU_H