Mercurial > hg > vamp-build-and-test
comparison DEPENDENCIES/generic/include/boost/polygon/gmp_override.hpp @ 16:2665513ce2d3
Add boost headers
author | Chris Cannam |
---|---|
date | Tue, 05 Aug 2014 11:11:38 +0100 |
parents | |
children |
comparison
equal
deleted
inserted
replaced
15:663ca0da4350 | 16:2665513ce2d3 |
---|---|
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: | |
15 inline gmp_int(const mpq_class& input) : v_(input) {} | |
16 public: | |
17 inline gmp_int() {} | |
18 explicit inline gmp_int(long input) : v_(input) {} | |
19 inline gmp_int(const gmp_int& input) : v_(input.v_) {} | |
20 inline gmp_int& operator=(const gmp_int& that) { | |
21 v_ = that.v_; | |
22 return (*this); | |
23 } | |
24 inline gmp_int& operator=(long that) { | |
25 v_ = that; | |
26 return (*this); | |
27 } | |
28 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 } | |
35 inline double get_d() const { | |
36 return v_.get_d(); | |
37 } | |
38 inline int get_num() const { | |
39 return v_.get_num().get_si(); | |
40 } | |
41 inline int get_den() const { | |
42 return v_.get_den().get_si(); | |
43 } | |
44 inline bool operator==(const gmp_int& that) const { | |
45 return v_ == that.v_; | |
46 } | |
47 inline bool operator!=(const gmp_int& that) const { | |
48 return v_ != that.v_; | |
49 } | |
50 inline bool operator<(const gmp_int& that) const { | |
51 bool retval = v_ < that.v_; | |
52 return retval; | |
53 } | |
54 inline bool operator<=(const gmp_int& that) const { | |
55 return v_ <= that.v_; | |
56 } | |
57 inline bool operator>(const gmp_int& that) const { | |
58 return v_ > that.v_; | |
59 } | |
60 inline bool operator>=(const gmp_int& that) const { | |
61 return v_ >= that.v_; | |
62 } | |
63 inline gmp_int operator+(const gmp_int& b) { | |
64 return gmp_int((*this).v_ + b.v_); | |
65 } | |
66 inline gmp_int operator-(const gmp_int& b) { | |
67 return gmp_int((*this).v_ - b.v_); | |
68 } | |
69 inline gmp_int operator*(const gmp_int& b) { | |
70 return gmp_int((*this).v_ * b.v_); | |
71 } | |
72 inline gmp_int operator/(const gmp_int& b) { | |
73 return gmp_int((*this).v_ / b.v_); | |
74 } | |
75 inline gmp_int& operator+=(const gmp_int& b) { | |
76 (*this).v_ += b.v_; | |
77 return (*this); | |
78 } | |
79 inline gmp_int& operator-=(const gmp_int& b) { | |
80 (*this).v_ -= b.v_; | |
81 return (*this); | |
82 } | |
83 inline gmp_int& operator*=(const gmp_int& b) { | |
84 (*this).v_ *= b.v_; | |
85 return (*this); | |
86 } | |
87 inline gmp_int& operator/=(const gmp_int& b) { | |
88 (*this).v_ /= b.v_; | |
89 return (*this); | |
90 } | |
91 inline gmp_int& operator++() { | |
92 ++v_; | |
93 return (*this); | |
94 } | |
95 inline gmp_int& operator--() { | |
96 --v_; | |
97 return (*this); | |
98 } | |
99 inline gmp_int operator++(int) { | |
100 gmp_int retval(*this); | |
101 ++(*this); | |
102 return retval; | |
103 } | |
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 <> | |
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 |