Apache Ignite C++ Client
Loading...
Searching...
No Matches
ignite::big_integer Class Reference

#include <big_integer.h>

Public Types

using mag_array_view = mpi_t::mag_view

Public Member Functions

 big_integer ()=default
 big_integer (const big_integer &other)=default
 big_integer (big_integer &&other) noexcept=default
 big_integer (std::int64_t val)
 big_integer (const std::string &val)
 big_integer (const char *val, std::int32_t len)
 big_integer (const std::int8_t *val, std::int32_t len, std::int8_t sign, bool big_endian=true)
 big_integer (const std::byte *data, std::size_t size)
big_integeroperator= (const big_integer &other)=default
big_integeroperator= (big_integer &&other) noexcept=default
big_integeroperator= (const mpi_t &other)
big_integeroperator= (mpi_t &&other) noexcept
void assign_int64 (std::int64_t val)
void assign_uint64 (std::uint64_t val)
void assign_string (const std::string &val)
void assign_string (const char *val, std::size_t len)
std::int8_t get_sign () const noexcept
mag_array_view get_magnitude () const noexcept
std::uint32_t bit_length () const noexcept
std::size_t byte_size () const noexcept
void store_bytes (std::byte *data) const
std::vector< std::byte > to_bytes () const
std::int32_t get_precision () const noexcept
void pow (std::int32_t exp)
void multiply (const big_integer &other, big_integer &res) const
void divide (const big_integer &divisor, big_integer &res) const
void divide (const big_integer &divisor, big_integer &res, big_integer &rem) const
void add (const big_integer &other, big_integer &res) const
void subtract (const big_integer &other, big_integer &res) const
void add (std::uint64_t x)
int compare (const big_integer &other, bool ignore_sign=false) const
std::int64_t to_int64 () const
bool is_negative () const noexcept
bool is_zero () const noexcept
bool is_positive () const noexcept
void negate ()
std::string to_string () const

Static Public Member Functions

static void get_power_of_ten (std::int32_t pow, big_integer &res)

Friends

class big_decimal
std::ostream & operator<< (std::ostream &os, const big_integer &val)
std::istream & operator>> (std::istream &is, big_integer &val)
void swap (big_integer &lhs, big_integer &rhs)

Detailed Description

Big integer number implementation.

TODO: Modernize this code to C++17 and update coding style

Constructor & Destructor Documentation

◆ big_integer() [1/8]

ignite::big_integer::big_integer ( )
default

Default constructor. Constructs zero-value big integer.

◆ big_integer() [2/8]

ignite::big_integer::big_integer ( const big_integer & other)
default

Copy constructor.

Parameters
otherOther value.

◆ big_integer() [3/8]

ignite::big_integer::big_integer ( big_integer && other)
defaultnoexcept

Move constructor.

Parameters
otherOther value.

◆ big_integer() [4/8]

ignite::big_integer::big_integer ( std::int64_t val)
inlineexplicit

Constructs big integer with the specified integer value.

Parameters
valValue.

◆ big_integer() [5/8]

ignite::big_integer::big_integer ( const std::string & val)
inlineexplicit

String constructor.

Parameters
valString to assign.

◆ big_integer() [6/8]

ignite::big_integer::big_integer ( const char * val,
std::int32_t len )
inline

String constructor.

Parameters
valString to assign.
lenString length.

◆ big_integer() [7/8]

ignite::big_integer::big_integer ( const std::int8_t * val,
std::int32_t len,
std::int8_t sign,
bool big_endian = true )

Constructs big integer from the byte array.

Parameters
valBytes of the integer. Byte order is big-endian.
lenArray length.
signSignum. Can be -1 (negative) or 1 (positive or zero).
bigEndianIf true then magnitude is in big-endian. Otherwise the byte order of the magnitude considered to be little-endian.

◆ big_integer() [8/8]

ignite::big_integer::big_integer ( const std::byte * data,
std::size_t size )

Constructs a big integer from the byte array.

Parameters
dataBytes of the integer. Byte order is big-endian. The representation is two's-complement.
sizeThe number of bytes.

Member Function Documentation

◆ add() [1/2]

void ignite::big_integer::add ( const big_integer & other,
big_integer & res ) const

Add another big integer to this.

Parameters
otherAddendum. Can be *this.
resResult placed there. Can be *this.

◆ add() [2/2]

void ignite::big_integer::add ( std::uint64_t x)

Add unsigned integer number to this big_integer.

Parameters
xNumber to add.

◆ assign_int64()

void ignite::big_integer::assign_int64 ( std::int64_t val)

Assign specified value to this big_integer.

Parameters
valValue to assign.

◆ assign_string() [1/2]

void ignite::big_integer::assign_string ( const char * val,
std::size_t len )

Assign specified value to this Decimal.

Parameters
valString to assign.
lenString length.

◆ assign_string() [2/2]

void ignite::big_integer::assign_string ( const std::string & val)

Assign specified value to this Decimal.

Parameters
valString to assign.

◆ assign_uint64()

void ignite::big_integer::assign_uint64 ( std::uint64_t val)

Assign specified value to this big_integer.

Parameters
valValue to assign.

◆ bit_length()

std::uint32_t ignite::big_integer::bit_length ( ) const
nodiscardnoexcept

Get length in bits of the two's-complement representation of this number, excluding a sign bit.

Returns
Length in bits of the two's-complement representation of this number, excluding a sign bit.

◆ byte_size()

std::size_t ignite::big_integer::byte_size ( ) const
nodiscardnoexcept

Get number of bytes required to store this number as byte array.

Returns
Number of bytes required to store this number as byte array.

◆ compare()

int ignite::big_integer::compare ( const big_integer & other,
bool ignore_sign = false ) const
nodiscard

compare this instance to another.

Parameters
otherAnother instance.
ignore_signIf set to true than only magnitudes are compared.
Returns
Comparasion result - 0 if equal, 1 if this is greater, -1 if this is less.

◆ divide() [1/2]

void ignite::big_integer::divide ( const big_integer & divisor,
big_integer & res ) const

Divide this to another big integer.

Parameters
divisorDivisor. Can be *this.
resResult placed there. Can be *this.

◆ divide() [2/2]

void ignite::big_integer::divide ( const big_integer & divisor,
big_integer & res,
big_integer & rem ) const

Divide this to another big integer.

Parameters
divisorDivisor. Can be *this.
resResult placed there. Can be *this.
remRemainder placed there. Can be *this.

◆ get_magnitude()

mag_array_view ignite::big_integer::get_magnitude ( ) const
inlinenodiscardnoexcept

Get magnitude array.

Returns
magnitude array.

◆ get_power_of_ten()

void ignite::big_integer::get_power_of_ten ( std::int32_t pow,
big_integer & res )
static

Get big_integer which value is the ten of the specified power.

Parameters
powTenth power.
resResult is placed here.

◆ get_precision()

int32_t ignite::big_integer::get_precision ( ) const
nodiscardnoexcept

Get precision of the BigInteger.

Returns
Number of the decimal digits in the decimal representation of the value.

◆ get_sign()

std::int8_t ignite::big_integer::get_sign ( ) const
inlinenodiscardnoexcept

Get number sign. Returns -1 if negative and 1 otherwise.

Returns
Sign of the number.

◆ is_negative()

bool ignite::big_integer::is_negative ( ) const
inlinenodiscardnoexcept

Check whether this value is negative.

Returns
True if this value is negative and false otherwise.

◆ is_positive()

bool ignite::big_integer::is_positive ( ) const
inlinenodiscardnoexcept

Check whether this value is positive.

Returns
True if this value is positive and false otherwise.

◆ is_zero()

bool ignite::big_integer::is_zero ( ) const
inlinenodiscardnoexcept

Check whether this value is zero.

Returns
True if this value is negative and false otherwise.

◆ multiply()

void ignite::big_integer::multiply ( const big_integer & other,
big_integer & res ) const

Muitiply this to another big integer.

Parameters
otherAnother instance. Can be *this.
resResult placed there. Can be *this.

◆ negate()

void ignite::big_integer::negate ( )
inline

Reverses sign of this value.

◆ operator=() [1/4]

big_integer & ignite::big_integer::operator= ( big_integer && other)
defaultnoexcept

Move-assigment operator.

Parameters
otherOther value.
Returns
*this.

◆ operator=() [2/4]

big_integer & ignite::big_integer::operator= ( const big_integer & other)
default

Copy-assigment operator.

Parameters
otherOther value.
Returns
*this.

◆ operator=() [3/4]

big_integer & ignite::big_integer::operator= ( const mpi_t & other)
inline

Copy-assigment operator.

Parameters
otherOther value.
Returns
*this.

◆ operator=() [4/4]

big_integer & ignite::big_integer::operator= ( mpi_t && other)
inlinenoexcept

Move-assigment operator.

Parameters
otherOther value.
Returns
*this.

◆ pow()

void ignite::big_integer::pow ( std::int32_t exp)

Mutates this BigInteger so its value becomes exp power of this.

Parameters
expExponent.

◆ store_bytes()

void ignite::big_integer::store_bytes ( std::byte * data) const

Store this number as a byte array.

Parameters
dataDestination byte array. Its size must be at least as large as the value returned by byte_size();

◆ subtract()

void ignite::big_integer::subtract ( const big_integer & other,
big_integer & res ) const

Subtract another big integer from this.

Parameters
otherSubtrahend. Can be *this.
resResult placed there. Can be *this.

◆ to_bytes()

std::vector< std::byte > ignite::big_integer::to_bytes ( ) const
inlinenodiscard

Convert value to bytes.

Returns
Vector of bytes.

◆ to_int64()

int64_t ignite::big_integer::to_int64 ( ) const
nodiscard

Convert to int64_t.

Returns
int64_t value.

◆ to_string()

std::string ignite::big_integer::to_string ( ) const
nodiscard

Converts value to string.

◆ operator<<

std::ostream & operator<< ( std::ostream & os,
const big_integer & val )
friend

Output operator.

Parameters
osOutput stream.
valValue to output.
Returns
Reference to the first param.

◆ operator>>

std::istream & operator>> ( std::istream & is,
big_integer & val )
friend

Input operator.

Parameters
isInput stream.
valValue to input.
Returns
Reference to the first param.

◆ swap

void swap ( big_integer & lhs,
big_integer & rhs )
friend

Swap function for the big_integer type.

Parameters
otherOther instance.

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