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