X-Git-Url: https://git.ucc.asn.au/?p=ipdf%2Fcode.git;a=blobdiff_plain;f=src%2Freal.h;h=0cbc05d85f52ac1729cb7bb1c0af30b1f1f64437;hp=ecd3852c2189bba85de43295ae1d7aab3bdddced;hb=6472d20ee58d2ecc0aee8bc1a12a071b2afc8a27;hpb=612d71e94fa4a4ca394fb1f566926392e95a2fa8 diff --git a/src/real.h b/src/real.h index ecd3852..0cbc05d 100644 --- a/src/real.h +++ b/src/real.h @@ -2,6 +2,7 @@ #define _REAL_H #include "common.h" +#include #define REAL_SINGLE 0 @@ -40,7 +41,7 @@ namespace IPDF #elif REAL == REAL_LONG_DOUBLE typedef long double Real; #elif REAL == REAL_VFPU - typedef VFPU::Float Real; + typedef VFPU::VFloat 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 @@ -53,6 +54,8 @@ namespace IPDF typedef Rational Real; inline float Float(const Real & r) {return (float)r.ToDouble();} inline double Double(const Real & r) {return r.ToDouble();} + inline int64_t Int64(const Real & r) {return r.ToInt64();} + inline Rational Sqrt(const Rational & r) {return r.Sqrt();} #else #error "Type of Real unspecified." @@ -67,6 +70,9 @@ namespace IPDF inline double Double(float f) {return (double)f;} inline double Double(double f) {return (double)f;} inline double Double(long double f) {return (double)(f);} + inline double Sqrt(double f) {return sqrt(f);} + inline double Abs(double a) {return fabs(a);} + inline int64_t Int64(double a){return (int64_t)a;} inline Real Power(const Real & a, int n) { @@ -79,7 +85,34 @@ namespace IPDF r *= a; return r; } + struct Vec2 + { + Real x; + Real y; + Vec2() : x(0), y(0) {} + Vec2(Real _x, Real _y) : x(_x), y(_y) {} + Vec2(const std::pair & p) : x(p.first), y(p.second) {} + Vec2(const std::pair & p) : x(p.first), y(p.second) {} + + bool operator==(const Vec2& other) const { return (x == other.x) && (y == other.y); } + bool operator!=(const Vec2& other) const { return !(*this == other); } + + Vec2& operator=(const Vec2& other) { x = other.x; y = other.y; return *this; } + Vec2& operator+=(const Vec2& other) { x += other.x; y += other.y; return *this; } + Vec2& operator-=(const Vec2& other) { x -= other.x; y -= other.y; return *this; } + Vec2& operator*=(const Real& lambda) { x *= lambda; y *= lambda; return *this; } + Vec2& operator/=(const Real& lambda) { x /= lambda; y /= lambda; return *this; } + + Vec2 operator+(const Vec2& other) const { return Vec2(x + other.x, y + other.y); } + Vec2 operator-(const Vec2& other) const { return Vec2(x - other.x, y - other.y); } + Vec2 operator*(const Real& lambda) const { return Vec2(x * lambda, y * lambda); } + Vec2 operator/(const Real& lambda) const { return Vec2(x / lambda, y / lambda); } + + const Real SquareLength() const { return (x*x + y*y); } + }; + + } #endif //_REAL_H