File: bigint.cpp

package info (click to toggle)
terraphast 0.1.0%2Bdfsg-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 844 kB
  • sloc: cpp: 5,923; sh: 92; ansic: 55; makefile: 27
file content (40 lines) | stat: -rw-r--r-- 1,058 bytes parent folder | download | duplicates (3)
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
#include <terraces/bigint.hpp>

#include <ostream>

#ifdef USE_GMP
namespace terraces {
big_integer::big_integer(index_t i) : m_value{i} {}
big_integer& big_integer::operator+=(const big_integer& other) {
	m_value += other.m_value;
	return *this;
}
big_integer& big_integer::operator*=(const big_integer& other) {
	m_value *= other.m_value;
	return *this;
}
bool big_integer::is_clamped() const { return false; }
const mpz_class& big_integer::value() const { return m_value; }

big_integer operator+(const big_integer& a, const big_integer& b) {
	big_integer result = a;
	result += b;
	return result;
}

big_integer operator*(const big_integer& a, const big_integer& b) {
	big_integer result = a;
	result *= b;
	return result;
}

bool operator==(const big_integer& a, const big_integer& b) { return a.value() == b.value(); }

bool operator!=(const big_integer& a, const big_integer& b) { return !(a == b); }

std::ostream& operator<<(std::ostream& stream, const big_integer& val) {
	return stream << val.value();
}

} // namespace terraces
#endif // USE_GMP