slow boob

This commit is contained in:
malloc 2018-03-22 22:27:13 -05:00
parent bebd2def31
commit e0f604bb04
3 changed files with 37 additions and 24 deletions

View file

@ -50,14 +50,29 @@ int main(int argc, char **argv) {
sosc::BigUInt a, b;
a.Parse("ff0000");
b.Parse("fff");
a.Parse("368BEADA711E83274DAF974D1A1A10EB915023D016CFC8BFAB58E5D848CF8D45");
//assert(a - b == sosc::BigUInt("feff01"));
//a += b;
a *= b;
//auto d = sosc::BigUInt::DivideWithRemainder(a, b);
std::cout << a.ToString() << std::endl;
/*for(int i = a.ByteCount() * 8 - 1; i >= 0; --i) {
std::cout << a.GetBit(i);
b.SetBit(i, a.GetBit(i));
}*/
//std::cout << sosc::BigUInt::GenerateRandomPrime(64).ToString();
//std::cout << a.IsProbablePrime();
for(int i = 0; i < 250; ++i)
a*a;
//std::cout << a.ToString();
/*std::cout << std::endl << std::endl
<< d.result.ToString()
<< std::endl
<< d.remainder.ToString();*/
return 0;
}

View file

@ -179,13 +179,17 @@ sosc::BigUInt sosc::BigUInt::ModPow
BigUInt x = exp;
BigUInt bpow = base;
uint64_t iterations = 0;
while(!x.IsZero()) {
++iterations;
if(!x.IsEven())
accum = (accum * bpow) % mod;
x = x >> 1;
bpow = (bpow * bpow) % mod;
}
std::cout << std::endl << iterations << std::endl;
return accum;
}
@ -323,14 +327,9 @@ bool sosc::BigUInt::operator == (const BigUInt& rhs) const {
if(this->UsedByteCount() != rhs.UsedByteCount())
return false;
size_t cmp_range = std::max(this->ByteCount(), rhs.ByteCount());
for(size_t i = 0; i < cmp_range; ++i) {
uint8_t a = i < this->ByteCount() ? this->value[i] : 0;
uint8_t b = i < rhs.ByteCount() ? rhs.value[i] : 0;
if(a != b)
for(size_t i = 0; i < this->UsedByteCount(); ++i)
if(this->value[i] != rhs.value[i])
return false;
}
return true;
}
@ -342,20 +341,17 @@ bool sosc::BigUInt::operator != (const BigUInt& rhs) const {
bool sosc::BigUInt::operator > (const BigUInt& rhs) const {
if(this->UsedByteCount() < rhs.UsedByteCount())
return false;
if(this->UsedByteCount() > rhs.UsedByteCount())
return true;
size_t cmp_range = std::max(this->ByteCount(), rhs.ByteCount());
size_t msb = this->UsedByteCount() - 1;
for(size_t i = msb;; --i) {
if(this->value[i] != rhs.value[i])
return this->value[i] > rhs.value[i];
for(size_t i = cmp_range - 1;; --i) {
uint8_t a = i < this->ByteCount() ? this->value[i] : 0;
uint8_t b = i < rhs.ByteCount() ? rhs.value[i] : 0;
if(a > b)
return true;
if(i == 0)
break;
return false;
}
return false;
}
bool sosc::BigUInt::operator >= (const BigUInt& rhs) const {
@ -419,7 +415,7 @@ sosc::BigUInt sosc::BigUInt::operator << (const uint64_t& rhs) const {
}
if(carry != 0)
this_v.push_back(carry);
buffer.push_back(carry);
}
sosc::BigUInt shifted;

View file

@ -1,6 +1,8 @@
#ifndef SOSC_UTIL_BIGINT_H
#define SOSC_UTIL_BIGINT_H
#include <iostream>
#include <cassert>
#include <tuple>
#include <string>