forked from QuasarApp/QtBigInt
added size functions
This commit is contained in:
parent
5c3d2b5d40
commit
8d9881508b
@ -8,6 +8,7 @@
|
||||
#include "bigint.h"
|
||||
#include <limits>
|
||||
#include <cstring>
|
||||
#include <cmath>
|
||||
|
||||
// constructors
|
||||
BigInt::BigInt() {
|
||||
@ -70,6 +71,14 @@ int BigInt::sizeBytes() const {
|
||||
return static_cast<int>(mpz_size(data) * sizeof ((*data->_mp_d)));
|
||||
}
|
||||
|
||||
int BigInt::longBits() const {
|
||||
return static_cast<int>(getString(2).size());
|
||||
}
|
||||
|
||||
int BigInt::longBytes() const {
|
||||
return static_cast<int>(std::ceil(static_cast<double>(longBits()) / 8));
|
||||
}
|
||||
|
||||
#define GMP_ABS(x) ((x) >= 0 ? (x) : -(x))
|
||||
int BigInt::sizeType() const {
|
||||
return static_cast<int>(static_cast<size_t>(GMP_ABS( data->_mp_alloc)) *
|
||||
|
14
src/bigint.h
14
src/bigint.h
@ -24,7 +24,6 @@ public:
|
||||
BigInt();
|
||||
BigInt(const BigInt& val, int bitCount = -1);
|
||||
BigInt(const std::string &imput, int base = 10);
|
||||
// BigInt(const char * str, int base = 10);
|
||||
BigInt(long val);
|
||||
BigInt(char item, unsigned int size, int base);
|
||||
|
||||
@ -35,8 +34,21 @@ public:
|
||||
static BigInt powm(BigInt val, const BigInt & pow, const BigInt &mod);
|
||||
|
||||
BigInt& pow(unsigned long pow);
|
||||
BigInt& log(int base);
|
||||
/**
|
||||
* @brief sizeBits
|
||||
* @return size of bits in memory
|
||||
*/
|
||||
int sizeBits() const;
|
||||
int sizeBytes() const;
|
||||
|
||||
/**
|
||||
* @brief longBits
|
||||
* @return current long in Bits of number
|
||||
*/
|
||||
int longBits() const;
|
||||
int longBytes() const;
|
||||
|
||||
int sizeType() const;
|
||||
bool isPrime(bool absalut = false) const;
|
||||
BigInt& gcd(const BigInt &a, const BigInt &b);
|
||||
|
Loading…
x
Reference in New Issue
Block a user