1 /* 2 Copyright 2008 Intel Corporation 3 4 Use, modification and distribution are subject to the Boost Software License, 5 Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at 6 http://www.boost.org/LICENSE_1_0.txt). 7 */ 8 #ifndef BOOST_POLYGON_GMP_OVERRIDE_HPP 9 #define BOOST_POLYGON_GMP_OVERRIDE_HPP 10 #include <gmpxx.h> 11 namespace boost { namespace polygon { 12 13 class gmp_int { 14 private: gmp_int(const mpq_class & input)15 inline gmp_int(const mpq_class& input) : v_(input) {} 16 public: gmp_int()17 inline gmp_int() {} gmp_int(long input)18 explicit inline gmp_int(long input) : v_(input) {} gmp_int(const gmp_int & input)19 inline gmp_int(const gmp_int& input) : v_(input.v_) {} operator =(const gmp_int & that)20 inline gmp_int& operator=(const gmp_int& that) { 21 v_ = that.v_; 22 return (*this); 23 } operator =(long that)24 inline gmp_int& operator=(long that) { 25 v_ = that; 26 return (*this); 27 } operator int() const28 inline operator int() const { 29 std::cout << "cast\n"; 30 mpz_class num = v_.get_num(); 31 mpz_class den = v_.get_den(); 32 num /= den; 33 return num.get_si(); 34 } get_d() const35 inline double get_d() const { 36 return v_.get_d(); 37 } get_num() const38 inline int get_num() const { 39 return v_.get_num().get_si(); 40 } get_den() const41 inline int get_den() const { 42 return v_.get_den().get_si(); 43 } operator ==(const gmp_int & that) const44 inline bool operator==(const gmp_int& that) const { 45 return v_ == that.v_; 46 } operator !=(const gmp_int & that) const47 inline bool operator!=(const gmp_int& that) const { 48 return v_ != that.v_; 49 } operator <(const gmp_int & that) const50 inline bool operator<(const gmp_int& that) const { 51 bool retval = v_ < that.v_; 52 return retval; 53 } operator <=(const gmp_int & that) const54 inline bool operator<=(const gmp_int& that) const { 55 return v_ <= that.v_; 56 } operator >(const gmp_int & that) const57 inline bool operator>(const gmp_int& that) const { 58 return v_ > that.v_; 59 } operator >=(const gmp_int & that) const60 inline bool operator>=(const gmp_int& that) const { 61 return v_ >= that.v_; 62 } operator +(const gmp_int & b)63 inline gmp_int operator+(const gmp_int& b) { 64 return gmp_int((*this).v_ + b.v_); 65 } operator -(const gmp_int & b)66 inline gmp_int operator-(const gmp_int& b) { 67 return gmp_int((*this).v_ - b.v_); 68 } operator *(const gmp_int & b)69 inline gmp_int operator*(const gmp_int& b) { 70 return gmp_int((*this).v_ * b.v_); 71 } operator /(const gmp_int & b)72 inline gmp_int operator/(const gmp_int& b) { 73 return gmp_int((*this).v_ / b.v_); 74 } operator +=(const gmp_int & b)75 inline gmp_int& operator+=(const gmp_int& b) { 76 (*this).v_ += b.v_; 77 return (*this); 78 } operator -=(const gmp_int & b)79 inline gmp_int& operator-=(const gmp_int& b) { 80 (*this).v_ -= b.v_; 81 return (*this); 82 } operator *=(const gmp_int & b)83 inline gmp_int& operator*=(const gmp_int& b) { 84 (*this).v_ *= b.v_; 85 return (*this); 86 } operator /=(const gmp_int & b)87 inline gmp_int& operator/=(const gmp_int& b) { 88 (*this).v_ /= b.v_; 89 return (*this); 90 } operator ++()91 inline gmp_int& operator++() { 92 ++v_; 93 return (*this); 94 } operator --()95 inline gmp_int& operator--() { 96 --v_; 97 return (*this); 98 } operator ++(int)99 inline gmp_int operator++(int) { 100 gmp_int retval(*this); 101 ++(*this); 102 return retval; 103 } operator --(int)104 inline gmp_int operator--(int) { 105 gmp_int retval(*this); 106 --(*this); 107 return retval; 108 } 109 private: 110 mpq_class v_; 111 }; 112 113 template <> 114 struct high_precision_type<int> { 115 typedef mpq_class type; 116 }; 117 118 template <> convert_high_precision_type(const mpq_class & v)119 int convert_high_precision_type<int>(const mpq_class& v) { 120 mpz_class num = v.get_num(); 121 mpz_class den = v.get_den(); 122 num /= den; 123 return num.get_si(); 124 }; 125 126 } 127 } 128 #endif 129