1 #ifndef ONCE_FP_GMP_INT_HH_
2 #define ONCE_FP_GMP_INT_HH_
9 /* A default of 256 bits will be used for all newly-instantiated GmpInt
10 objects. This default can be changed with the function below.
12 static void setDefaultNumberOfBits(unsigned long);
13 static unsigned long getDefaultNumberOfBits();
17 GmpInt(unsigned long value);
20 GmpInt(long double value);
22 GmpInt(const GmpInt&);
23 GmpInt& operator=(const GmpInt&);
24 GmpInt& operator=(signed long value);
29 /* This function can be used to retrieve the raw mpz_t data structure
30 used by this object. (The template trick is used to avoid a dependency
31 of this header file with <gmp.h>.)
32 In other words, it can be called like:
35 intValue.get_raw_mpz_data(raw_mpz_data);
37 Note that the returned mpz_t should be considered as read-only and
38 not be modified from the outside because it may be shared among
39 several objects. If the calling code needs to modify the data, it
40 should copy it for itself first with the appropriate GMP library
43 template<typename Mpz_t>
44 void get_raw_mpfr_data(Mpz_t& dest_mpz_t);
47 // Note that the returned char* points to an internal (shared) buffer
48 // which will be valid until the next time this function is called
50 const char* getAsString(int base = 10) const;
53 GmpInt& operator+=(const GmpInt&);
54 GmpInt& operator+=(long);
55 GmpInt& operator-=(const GmpInt&);
56 GmpInt& operator-=(long);
57 GmpInt& operator*=(const GmpInt&);
58 GmpInt& operator*=(long);
59 GmpInt& operator/=(const GmpInt&);
60 GmpInt& operator/=(long);
61 GmpInt& operator%=(const GmpInt&);
62 GmpInt& operator%=(long);
64 GmpInt& operator<<=(unsigned long);
65 GmpInt& operator>>=(unsigned long);
67 // Equivalent to "+= value1 * value2;"
68 void addProduct(const GmpInt& value1, const GmpInt& value2);
69 void addProduct(const GmpInt& value1, unsigned long value2);
71 // Equivalent to "-= value1 * value2;"
72 void subProduct(const GmpInt& value1, const GmpInt& value2);
73 void subProduct(const GmpInt& value1, unsigned long value2);
77 static GmpInt abs(const GmpInt&);
79 GmpInt operator+(const GmpInt&) const;
80 GmpInt operator+(long) const;
81 GmpInt operator-(const GmpInt&) const;
82 GmpInt operator-(long) const;
83 GmpInt operator*(const GmpInt&) const;
84 GmpInt operator*(long) const;
85 GmpInt operator/(const GmpInt&) const;
86 GmpInt operator/(long) const;
87 GmpInt operator%(const GmpInt&) const;
88 GmpInt operator%(long) const;
90 GmpInt operator-() const;
92 GmpInt operator<<(unsigned long) const;
93 GmpInt operator>>(unsigned long) const;
95 bool operator<(const GmpInt&) const;
96 bool operator<(long) const;
97 bool operator<=(const GmpInt&) const;
98 bool operator<=(long) const;
99 bool operator>(const GmpInt&) const;
100 bool operator>(long) const;
101 bool operator>=(const GmpInt&) const;
102 bool operator>=(long) const;
103 bool operator==(const GmpInt&) const;
104 bool operator==(long) const;
105 bool operator!=(const GmpInt&) const;
106 bool operator!=(long) const;
108 void parseValue(const char* value);
109 void parseValue(const char* value, char** endptr);
110 static GmpInt parseString(const char* str, char** endptr);
115 class GmpIntDataContainer;
119 enum DummyType { kNoInitialization };
123 static GmpIntDataContainer& gmpIntDataContainer();
125 friend GmpInt operator+(long lhs, const GmpInt& rhs);
126 friend GmpInt operator-(long lhs, const GmpInt& rhs);
129 GmpInt operator+(long lhs, const GmpInt& rhs);
130 GmpInt operator-(long lhs, const GmpInt& rhs);
131 GmpInt operator*(long lhs, const GmpInt& rhs);
132 GmpInt operator/(long lhs, const GmpInt& rhs);
133 GmpInt operator%(long lhs, const GmpInt& rhs);
135 inline bool operator<(long lhs, const GmpInt& rhs) { return rhs > lhs; }
136 inline bool operator<=(long lhs, const GmpInt& rhs) { return rhs >= lhs; }
137 inline bool operator>(long lhs, const GmpInt& rhs) { return rhs < lhs; }
138 inline bool operator>=(long lhs, const GmpInt& rhs) { return rhs <= lhs; }
139 inline bool operator==(long lhs, const GmpInt& rhs) { return rhs == lhs; }
140 inline bool operator!=(long lhs, const GmpInt& rhs) { return rhs != lhs; }
142 inline std::ostream& operator<<(std::ostream& os, const GmpInt& value)
144 os << value.getAsString();