ledger-core
Public Member Functions | Static Public Member Functions | List of all members
ledger::core::api::BigInt Class Referenceabstract

#include <BigInt.hpp>

+ Inheritance diagram for ledger::core::api::BigInt:

Public Member Functions

virtual std::shared_ptr< BigIntadd (const std::shared_ptr< BigInt > &i)=0
 
virtual std::shared_ptr< BigIntsubtract (const std::shared_ptr< BigInt > &i)=0
 
virtual std::shared_ptr< BigIntmultiply (const std::shared_ptr< BigInt > &i)=0
 
virtual std::shared_ptr< BigIntdivide (const std::shared_ptr< BigInt > &i)=0
 
virtual std::vector< std::shared_ptr< BigInt > > divideAndRemainder (const std::shared_ptr< BigInt > &i)=0
 
virtual std::shared_ptr< BigIntpow (int32_t exponent)=0
 
virtual std::string toDecimalString (int32_t precision, const std::string &decimalSeparator, const std::string &thousandSeparator)=0
 
virtual std::string toString (int32_t radix)=0
 
virtual int32_t intValue ()=0
 
virtual int32_t compare (const std::shared_ptr< BigInt > &i)=0
 

Static Public Member Functions

static std::shared_ptr< BigIntfromDecimalString (const std::string &s, int32_t precision, const std::string &decimalSeparator)
 
static std::shared_ptr< BigIntfromIntegerString (const std::string &s, int32_t radix)
 
static std::shared_ptr< BigIntfromLong (int64_t l)
 

Detailed Description

Immutable class representing a potentially very long number.

Member Function Documentation

◆ add()

virtual std::shared_ptr<BigInt> ledger::core::api::BigInt::add ( const std::shared_ptr< BigInt > &  i)
pure virtual

Adds two BigInt and returns a new BigInt with the result. i Value to be added to this BigInt

Returns
The result of this + i

◆ compare()

virtual int32_t ledger::core::api::BigInt::compare ( const std::shared_ptr< BigInt > &  i)
pure virtual

Compares two BigInt together.

Parameters
iThe value to compare with this BigInt
Returns
a positive value if this > i. A negative value if this < i. 0 if the two BigInts are equal

◆ divide()

virtual std::shared_ptr<BigInt> ledger::core::api::BigInt::divide ( const std::shared_ptr< BigInt > &  i)
pure virtual

Divides two BigInt and returns a new BigInt with result. i Value by which this BigInt will be divided

Returns
The result of this / i

◆ divideAndRemainder()

virtual std::vector<std::shared_ptr<BigInt> > ledger::core::api::BigInt::divideAndRemainder ( const std::shared_ptr< BigInt > &  i)
pure virtual

Divides two BigInt and returns a new BigInt with result of the division and the remainder. i Value by which this BigInteger is to be divided, and the remainder computed

Returns
A tuple of [this / i, this % i]

◆ fromDecimalString()

std::shared_ptr< BigInt > ledger::core::api::BigInt::fromDecimalString ( const std::string &  s,
int32_t  precision,
const std::string &  decimalSeparator 
)
static

Creates a BigInt with a decimal string (e.g. "1.2000"). Note that every non numeric characters (except the decimal separator) are ignored (e.g. "1ledger000" will be equal to "1000").

Parameters
sThe string with the decimal representation of the BigInt
precisionThe power of ten by which your decimal number must be multiplied in order to get his integer representation decimalSeparator The decimal separator used by this string representation
Returns
The created BigInt

◆ fromIntegerString()

std::shared_ptr< BigInt > ledger::core::api::BigInt::fromIntegerString ( const std::string &  s,
int32_t  radix 
)
static

Creates a BigInt with an integer string expressed in hexadecimal or decimal radix.

Parameters
sThe string to parse
radixThe radix of the number representation (right now 10 or 16)
Returns
The created BigInt

◆ fromLong()

std::shared_ptr< BigInt > ledger::core::api::BigInt::fromLong ( int64_t  l)
static

Creates a BigInt from a int64 value.

Parameters
lThe value to convert
Returns
The created BigInt

◆ intValue()

virtual int32_t ledger::core::api::BigInt::intValue ( )
pure virtual

Returns the int representation of this BigInt. Note that if the BigInt is greater than 4 bytes the returned value will be meaningless.

Returns
The int representation of this BigInt

Implemented in ledger::core::api::BigIntImpl.

◆ multiply()

virtual std::shared_ptr<BigInt> ledger::core::api::BigInt::multiply ( const std::shared_ptr< BigInt > &  i)
pure virtual

Multiplies two BigInt and returns a new BigInt with result. i Value to be multiplied by this BigInt

Returns
The result of this * i

◆ pow()

virtual std::shared_ptr<BigInt> ledger::core::api::BigInt::pow ( int32_t  exponent)
pure virtual

Raises this BigInt with an interger value. i The exponent to which thi BigInt is raised

Returns
The result of this ^ exponent

Implemented in ledger::core::api::BigIntImpl.

◆ subtract()

virtual std::shared_ptr<BigInt> ledger::core::api::BigInt::subtract ( const std::shared_ptr< BigInt > &  i)
pure virtual

Subtracts two BigInt and returns a new BigInt with result. i Value to be subtracted to this BigInt

Returns
The result of this - i

◆ toDecimalString()

virtual std::string ledger::core::api::BigInt::toDecimalString ( int32_t  precision,
const std::string &  decimalSeparator,
const std::string &  thousandSeparator 
)
pure virtual

Formats this BigInt to a decimal string (e.g. BigInt("12345").toDecimalString(1, ".", ",") => "1,234.5"). precision The power of ten by wich this BigInt is divided decimalSeparator The separator to use between the integer part and the decimal part thousandSeparator The separator to use between each group of thousand units

Returns
The BigInt formatted as a decimal string

Implemented in ledger::core::api::BigIntImpl.

◆ toString()

virtual std::string ledger::core::api::BigInt::toString ( int32_t  radix)
pure virtual

Formats this BigInt to the interger representation of its internal value. radix The radix of the number representation in which to format (right now 10 or 16)

Implemented in ledger::core::api::BigIntImpl.


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