ledger-core
Public Types | Public Member Functions | Static Public Member Functions | Static Public Attributes | List of all members
ledger::core::BigInt Class Reference

#include <ledger/core/math/BigInt.h>

+ Collaboration diagram for ledger::core::BigInt:

Public Types

typedef unsigned int SimpleInt
 
typedef unsigned long DoubleInt
 

Public Member Functions

 BigInt (const BigInt &cpy)
 
 BigInt (BigInt &&mov)
 
 BigInt (const void *data, size_t length, bool negative)
 
 BigInt (const std::vector< uint8_t > &data, bool negative)
 
 BigInt (int value)
 
 BigInt (unsigned int value)
 
 BigInt (unsigned long long value)
 
 BigInt (int64_t value)
 
 BigInt (const std::string &str)
 
int toInt () const
 
unsigned toUnsignedInt () const
 
uint64_t toUint64 () const
 
int64_t toInt64 () const
 
std::string toString () const
 
std::string to_string () const
 
std::string toHexString () const
 
std::vector< uint8_t > toByteArray () const
 
BigInt operator+ (const BigInt &rhs) const
 
BigInt operator- (const BigInt &rhs) const
 
BigInt operator* (const BigInt &rhs) const
 
BigInt operator/ (const BigInt &rhs) const
 
BigInt operator% (const BigInt &rhs) const
 
BigIntoperator++ ()
 
BigInt operator++ (int)
 
BigIntoperator-- ()
 
BigInt operator-- (int)
 
BigIntoperator= (const BigInt &)
 
BigIntoperator= (BigInt &&a)
 
bool operator< (const BigInt &) const
 
bool operator<= (const BigInt &) const
 
bool operator== (const BigInt &) const
 
bool operator> (const BigInt &) const
 
bool operator>= (const BigInt &) const
 
int compare (const BigInt &) const
 
BigInt pow (unsigned short p) const
 
unsigned long getBitSize () const
 
bool isNegative () const
 
bool isPositive () const
 
bool isZero () const
 
BigInt negative () const
 
BigInt positive () const
 
BigIntassignI64 (int64_t value)
 
template<typename T >
BigIntassignScalar (T value)
 

Static Public Member Functions

static LIBCORE_EXPORT BigIntfrom_hex (const std::string &str)
 
static LIBCORE_EXPORT BigInt fromHex (const std::string &str)
 
static LIBCORE_EXPORT BigIntfrom_dec (const std::string &str)
 
static LIBCORE_EXPORT BigInt fromDecimal (const std::string &str)
 
static LIBCORE_EXPORT BigInt fromString (const std::string &str)
 
template<typename T >
static BigInt fromScalar (T value)
 

Static Public Attributes

static LIBCORE_EXPORT const BigInt ZERO = BigInt(0)
 
static LIBCORE_EXPORT const BigInt ONE = BigInt(1)
 
static LIBCORE_EXPORT const BigInt TEN = BigInt(10)
 
static LIBCORE_EXPORT const std::string DIGITS = std::string("0123456789abcdefghijklmnopqrstuvwxyz")
 
static LIBCORE_EXPORT const int MIN_RADIX = 2
 
static LIBCORE_EXPORT const int MAX_RADIX = 36
 

Detailed Description

Helper class used to deal with really big integers.

Constructor & Destructor Documentation

◆ BigInt() [1/3]

ledger::core::BigInt::BigInt ( const void *  data,
size_t  length,
bool  negative 
)

Initializes a new BigInt with the given big endian data.

Parameters
dataThe big integer data formatted in big endian
lengthThe length of the data
negativetrue if the number is negative false otherwise

◆ BigInt() [2/3]

ledger::core::BigInt::BigInt ( int  value)
explicit

Initializes a new BigInt with the runtime int.

Parameters
value
bits
Returns

◆ BigInt() [3/3]

ledger::core::BigInt::BigInt ( const std::string &  str)

Initializes a new BigInt with the given string representation.

Parameters
str
Returns

Member Function Documentation

◆ from_dec()

BigInt * ledger::core::BigInt::from_dec ( const std::string &  str)
static

Creates a new BigInt from the given decimal encoded string.

Parameters
strThe number encoded in decimal (e.g. "125")
Returns

◆ from_hex()

BigInt * ledger::core::BigInt::from_hex ( const std::string &  str)
static

Creates a new BigInt from the given hexadecimal encoded string.

Parameters
strThe number encoded in hexadecimal (e.g. "E0A1B3")
Returns
An instance of BigInt

◆ fromDecimal()

BigInt ledger::core::BigInt::fromDecimal ( const std::string &  str)
static

Creates a new BigInt from the given decimal encoded string.

Parameters
strThe number encoded in decimal (e.g. "125")
Returns

◆ fromHex()

BigInt ledger::core::BigInt::fromHex ( const std::string &  str)
static

Creates a new BigInt from the given hexadecimal encoded string.

Parameters
strThe number encoded in hexadecimal (e.g. "E0A1B3")

◆ toByteArray()

std::vector< uint8_t > ledger::core::BigInt::toByteArray ( ) const

Serializes the BigInt into a Big Endian byte array.

Returns

◆ toHexString()

std::string ledger::core::BigInt::toHexString ( ) const

Serializes the BigInt into a hexadecimal std::string.

Returns

◆ toInt()

int ledger::core::BigInt::toInt ( ) const

Converts the BigInt to int

Returns

◆ toString()

std::string ledger::core::BigInt::toString ( ) const

Serializes the BigInt into a decimal std::string.

Parameters
str
radix
Returns

◆ toUnsignedInt()

unsigned int ledger::core::BigInt::toUnsignedInt ( ) const

Converts the BigInt to unsigned int

Returns

Member Data Documentation

◆ DIGITS

const std::string ledger::core::BigInt::DIGITS = std::string("0123456789abcdefghijklmnopqrstuvwxyz")
static

Available digits for conversion to and from strings.

◆ MAX_RADIX

const int ledger::core::BigInt::MAX_RADIX = 36
static

The minimum radix available for conversion to and from strings.

◆ MIN_RADIX

const int ledger::core::BigInt::MIN_RADIX = 2
static

The maximum radix available for conversion to and from strings.


The documentation for this class was generated from the following files: