高精度整数
更多...
#include <templates.h>
高精度整数
在文件 templates.h 第 23 行定义.
◆ BigInt() [1/13]
BigInt::BigInt |
( |
const vector< unsigned short > & |
vec, |
|
|
bool |
positive |
|
) |
| |
|
private |
在文件 templates.cpp 第 31 行定义.
33 int end_i =
vec.size() - 1;
34 while(end_i >= 0 &&
vec[end_i] == 0) {
37 this->
vec = vector<unsigned short>();
38 for(
int i = 0; i <= end_i; i++) {
39 this->
vec.push_back(
vec[i]);
41 if(this->
vec.empty()) {
42 this->
vec.push_back(0);
vector< unsigned short > vec
引用了 vec.
◆ BigInt() [2/13]
BigInt::BigInt |
( |
short |
n | ) |
|
◆ BigInt() [3/13]
◆ BigInt() [4/13]
◆ BigInt() [5/13]
BigInt::BigInt |
( |
long long |
n | ) |
|
◆ BigInt() [6/13]
BigInt::BigInt |
( |
unsigned short |
n | ) |
|
◆ BigInt() [7/13]
BigInt::BigInt |
( |
unsigned int |
n | ) |
|
◆ BigInt() [8/13]
BigInt::BigInt |
( |
unsigned long |
n | ) |
|
◆ BigInt() [9/13]
BigInt::BigInt |
( |
unsigned long long |
n | ) |
|
◆ BigInt() [10/13]
BigInt::BigInt |
( |
const string & |
str | ) |
|
在文件 templates.cpp 第 132 行定义.
133 int start_i = str.length() - 1;
134 while(start_i >= 0 && isdigit(str[start_i]) != 0) {
135 vec.push_back(str[start_i] -
'0');
引用了 positive , 以及 vec.
◆ BigInt() [11/13]
BigInt::BigInt |
( |
const char * |
str | ) |
|
在文件 templates.cpp 第 143 行定义.
144 int start_i = strlen(str) - 1;
145 while(start_i >= 0 && isdigit(str[start_i]) != 0) {
146 vec.push_back(str[start_i] -
'0');
引用了 positive , 以及 vec.
◆ BigInt() [12/13]
BigInt::BigInt |
( |
const BigInt & |
bi | ) |
|
在文件 templates.cpp 第 154 行定义.
155 int end_i = bi.
vec.size() - 1;
156 while(end_i >= 0 && bi.
vec[end_i] == 0) {
159 this->
vec = vector<unsigned short>();
160 for(
int i = 0; i <= end_i; i++) {
161 this->
vec.push_back(bi.
vec[i]);
163 if(this->
vec.empty()) {
164 this->
vec.push_back(0);
引用了 positive , 以及 vec.
◆ BigInt() [13/13]
◆ get_size()
unsigned long BigInt::get_size |
( |
| ) |
const |
|
private |
◆ operator!=()
bool BigInt::operator!= |
( |
const BigInt & |
bi | ) |
const |
◆ operator%()
◆ operator%=()
◆ operator*() [1/2]
在文件 templates.cpp 第 235 行定义.
236 unsigned max_len = 0;
237 vector<vector<unsigned short>> vecs(bi.
vec.size());
238 for(
int i = 0; i < bi.
vec.size(); i++) {
239 vector<unsigned short> vi(i, 0);
240 vector<unsigned short> ai = *
this * bi.
vec[i];
241 vi.insert(vi.end(), ai.begin(), ai.end());
243 max_len = max(max_len,
static_cast<unsigned>(vi.size()));
245 vector<unsigned short> ans;
246 unsigned short c = 0;
247 for(
int i = 0; i < max_len; i++) {
249 for(
int j = 0; j < vecs.size(); j++) {
250 v += i < vecs[j].size() ? vecs[j][i] : 0;
258 ans.emplace_back(c % 10);
引用了 BigInt(), positive , 以及 vec.
◆ operator*() [2/2]
vector< unsigned short > BigInt::operator* |
( |
unsigned short |
n | ) |
const |
|
private |
在文件 templates.cpp 第 219 行定义.
220 vector<unsigned short> res;
221 unsigned short c = 0;
222 for(
const auto v: this->
vec) {
223 unsigned short num = n * v + c;
226 res.emplace_back(num);
229 res.emplace_back(c % 10);
引用了 vec.
◆ operator*=()
◆ operator+()
在文件 templates.cpp 第 169 行定义.
176 vector<unsigned short> v;
177 unsigned short carry = 0;
178 for(
long long i = 0; i < max(this->
get_size(), bi.
get_size()) || carry != 0; i++) {
179 const unsigned short this_num = i < this->
get_size() ? (*this)[i] : 0;
180 const unsigned short bi_num = i < bi.
get_size() ? bi[i] : 0;
181 unsigned short sum = this_num + bi_num;
unsigned long get_size() const
引用了 BigInt(), get_size() , 以及 positive.
◆ operator++() [1/2]
BigInt & BigInt::operator++ |
( |
| ) |
|
◆ operator++() [2/2]
BigInt BigInt::operator++ |
( |
int |
| ) |
|
◆ operator+=()
◆ operator-() [1/2]
BigInt BigInt::operator- |
( |
| ) |
const |
◆ operator-() [2/2]
在文件 templates.cpp 第 191 行定义.
199 return -(bi - *
this);
201 vector<unsigned short> v;
202 unsigned short borrow = 0;
204 short this_num = i < this->
get_size() ? (*this)[i] : 0;
205 const short bi_num = i < bi.
get_size() ? bi[i] : 0;
207 short diff = this_num - bi_num;
215 auto ret =
BigInt(v,
true);
引用了 BigInt(), get_size() , 以及 positive.
◆ operator--() [1/2]
BigInt & BigInt::operator-- |
( |
| ) |
|
◆ operator--() [2/2]
BigInt BigInt::operator-- |
( |
int |
| ) |
|
◆ operator-=()
◆ operator/()
◆ operator/=()
◆ operator<()
bool BigInt::operator< |
( |
const BigInt & |
bi | ) |
const |
◆ operator<=()
bool BigInt::operator<= |
( |
const BigInt & |
bi | ) |
const |
◆ operator==()
bool BigInt::operator== |
( |
const BigInt & |
bi | ) |
const |
◆ operator>()
bool BigInt::operator> |
( |
const BigInt & |
bi | ) |
const |
◆ operator>=()
bool BigInt::operator>= |
( |
const BigInt & |
bi | ) |
const |
◆ operator[]()
unsigned short BigInt::operator[] |
( |
unsigned long |
i | ) |
const |
|
private |
◆ operator<<
ostream & operator<< |
( |
ostream & |
os, |
|
|
const BigInt & |
bi |
|
) |
| |
|
friend |
◆ operator>>
istream & operator>> |
( |
istream & |
is, |
|
|
const BigInt & |
|
|
) |
| |
|
friend |
◆ positive
bool BigInt::positive = true |
|
private |
◆ vec
vector<unsigned short> BigInt::vec = {} |
|
private |
该类的文档由以下文件生成: