-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbigint.h
79 lines (54 loc) · 1.79 KB
/
bigint.h
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
#ifndef _BIGINT_H_
#define _BIGINT_H_
#include <iostream>
/* Two units will make up BigInt */
typedef unsigned long long int Unit;
constexpr Unit UNIT_NUMBER_OF_BITS = 64;
/* See divide by 2 for usage */
constexpr Unit UNIT_LARGEST_BIT = (Unit) 2 << (UNIT_NUMBER_OF_BITS - 1);
/**
* See multiplication by 3 for usage
* 3 - (2 ^ UNIT_NUMBER_OF_BITS) % 3
*/
constexpr Unit MINUS_UNIT_MOD_3 = 2;
/* 3 - (2 * 2 ^ UNIT_NUMBER_OF_BITS) % 3 */
constexpr Unit MINUS_2_UNIT_MOD_3 = 1;
class BigInt {
/* high is the high UNIT_NUMBER_OF_BITS bits
* low is the low UNIT_NUMBER_OF_BITS bits
* Basically the number will be high*2^UNIT_NUMBER_OF_BITS + low
*/
Unit high, low;
public:
/* Basic constructors */
BigInt();
BigInt(Unit);
BigInt(Unit high, Unit low);
BigInt(const BigInt &a);
/* This will be used only for multiplication by 3 */
BigInt &operator*=(Unit);
/* This will be used only for dividing by 2 */
BigInt &operator>>=(Unit);
/* Increments by 1 */
BigInt &operator++();
/* Used for calculating next assignment */
BigInt &operator+=(const BigInt &);
/* Used for getting parity */
Unit operator&(Unit);
/* Comparisons */
bool operator>=(const BigInt &);
bool operator==(const BigInt &);
bool operator<=(const BigInt &);
bool operator!=(const BigInt &);
bool operator>(const BigInt &);
bool operator<(const BigInt &);
friend std::ostream &operator<<(std::ostream &iostream, const BigInt &);
};
/**
* The (number's maximum value)/3-1 is always manageable
* This is because we cannot test overflow (without inline asm)
* fair estimate, less than 2^128/3-1
*/
const BigInt LARGEST_MANAGEABLE_NUMBER(UINT64_MAX / 3 - 1, 0);
std::ostream &operator<<(std::ostream &iostream, const BigInt &);
#endif