10 #define REAL_LONG_DOUBLE 2
12 #define REAL_RATIONAL 4
13 #define REAL_RATIONAL_ARBINT 5
16 #error "REAL was not defined!"
23 #if REAL == REAL_RATIONAL
27 #if REAL == REAL_RATIONAL_ARBINT
35 extern const char * g_real_name[];
37 #if REAL == REAL_SINGLE
39 #elif REAL == REAL_DOUBLE
41 #elif REAL == REAL_LONG_DOUBLE
42 typedef long double Real;
43 #elif REAL == REAL_VFPU
44 typedef VFPU::VFloat Real;
45 inline float Float(const Real & r) {return r.m_value;}
46 inline double Double(const Real & r) {return r.m_value;}
47 #elif REAL == REAL_RATIONAL
48 typedef Rational<int64_t> Real;
49 inline float Float(const Real & r) {return (float)r.ToDouble();}
50 inline double Double(const Real & r) {return r.ToDouble();}
51 #elif REAL == REAL_RATIONAL_ARBINT
52 #define ARBINT Gmpint // Set to Gmpint or Arbint here
54 typedef Rational<ARBINT> Real;
55 inline float Float(const Real & r) {return (float)r.ToDouble();}
56 inline double Double(const Real & r) {return r.ToDouble();}
59 #error "Type of Real unspecified."
62 // Allow us to call Float on the primative types
63 // Useful so I can template some things that could be either (a more complicated) Real or a primitive type
64 // Mostly in the testers.
65 inline float Float(float f) {return (float)f;}
66 inline float Float(double f) {return (float)f;}
67 inline float Float(long double f) {return (float)(f);}
68 inline double Double(float f) {return (double)f;}
69 inline double Double(double f) {return (double)f;}
70 inline double Double(long double f) {return (double)(f);}
71 inline double Sqrt(double f) {return sqrt(f);}
73 inline Real Power(const Real & a, int n)
77 return Power(Real(1)/a, -n);
80 for (int i = 0; i < n; ++i)
89 Vec2() : x(0), y(0) {}
90 Vec2(Real _x, Real _y) : x(_x), y(_y) {}
92 bool operator==(const Vec2& other) const { return (x == other.x) && (y == other.y); }
93 bool operator!=(const Vec2& other) const { return !(*this == other); }
95 Vec2& operator=(const Vec2& other) { x = other.x; y = other.y; return *this; }
96 Vec2& operator+=(const Vec2& other) { x += other.x; y += other.y; return *this; }
97 Vec2& operator-=(const Vec2& other) { x -= other.x; y -= other.y; return *this; }
98 Vec2& operator*=(const Real& lambda) { x *= lambda; y *= lambda; return *this; }
99 Vec2& operator/=(const Real& lambda) { x /= lambda; y /= lambda; return *this; }
101 Vec2 operator+(const Vec2& other) const { return Vec2(x + other.x, y + other.y); }
102 Vec2 operator-(const Vec2& other) const { return Vec2(x - other.x, y - other.y); }
103 Vec2 operator*(const Real& lambda) const { return Vec2(x * lambda, y * lambda); }
104 Vec2 operator/(const Real& lambda) const { return Vec2(x / lambda, y / lambda); }
106 const Real SquareLength() const { return (x*x + y*y); }