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

#include <big_decimal.h>

Public Member Functions

 big_decimal (const std::int8_t *mag, std::int32_t len, std::int16_t scale, std::int8_t sign, bool big_endian=true)
 big_decimal (const std::byte *data, std::size_t size)
 big_decimal (int64_t val)
 big_decimal (int64_t val, int16_t scale)
 big_decimal (const big_integer &val, int16_t scale)
 big_decimal (big_integer &&val, int16_t scale)
 big_decimal (const char *val, int32_t len)
 big_decimal (const std::string &val)
std::size_t byte_size () const noexcept
void store_bytes (std::byte *data) const
std::vector< std::byte > to_bytes () const
 operator double () const
 operator int64_t () const
double to_double () const
int64_t to_int64 () const
std::int16_t get_scale () const noexcept
void set_scale (std::int16_t new_scale, big_decimal &res) const
std::int32_t get_precision () const noexcept
const big_integerget_unscaled_value () const noexcept
void assign_string (const std::string &val)
void assign_string (const char *val, int32_t len)
void assign_int64 (int64_t val)
void assign_double (double val)
void assign_uint64 (uint64_t val)
void add (const big_decimal &other, big_decimal &res) const
void subtract (const big_decimal &other, big_decimal &res) const
void multiply (const big_decimal &other, big_decimal &res) const
void divide (const big_decimal &other, big_decimal &res) const
void negate ()
int compare (const big_decimal &other) const
bool is_negative () const noexcept
bool is_zero () const noexcept
bool is_positive () const noexcept

Static Public Member Functions

static big_decimal from_double (double val)

Friends

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

Detailed Description

Big decimal number implementation.

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

Constructor & Destructor Documentation

◆ big_decimal() [1/8]

ignite::big_decimal::big_decimal ( const std::int8_t * mag,
std::int32_t len,
std::int16_t scale,
std::int8_t sign,
bool big_endian = true )
inline

Constructor.

Parameters
magBytes of the magnitude. Should be positive, sign is passed using separate argument.
lenMagnitude length in bytes.
scaleScale.
signSign of the decimal. Should be -1 for negative numbers and 1 otherwise.
bigEndianIf true then magnitude is in big-endian. Otherwise the byte order of the magnitude considered to be little-endian.

◆ big_decimal() [2/8]

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

Constructs a big decimal from the byte array.

Parameters
dataBytes of the decimal. Scale in little byte order, magnitude as a big_integer.
sizeThe number of bytes.

◆ big_decimal() [3/8]

ignite::big_decimal::big_decimal ( int64_t val)
inlineexplicit

Integer constructor.

Parameters
valInteger value.

◆ big_decimal() [4/8]

ignite::big_decimal::big_decimal ( int64_t val,
int16_t scale )
inline

Integer constructor with scale.

Parameters
valInteger value.
scaleScale.

◆ big_decimal() [5/8]

ignite::big_decimal::big_decimal ( const big_integer & val,
int16_t scale )
inline

big_integer constructor with scale.

Parameters
valbig_integer value.
scaleScale.

◆ big_decimal() [6/8]

ignite::big_decimal::big_decimal ( big_integer && val,
int16_t scale )
inline

big_integer constructor with scale.

Parameters
valbig_integer value.
scaleScale.

◆ big_decimal() [7/8]

ignite::big_decimal::big_decimal ( const char * val,
int32_t len )
inlineexplicit

String constructor.

Parameters
valString to assign.
lenString length.

◆ big_decimal() [8/8]

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

String constructor.

Parameters
valString to assign.

Member Function Documentation

◆ add()

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

Add another big decimal to this.

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

◆ assign_double()

void ignite::big_decimal::assign_double ( double val)
inline

Assign specified value to this Decimal.

Parameters
valValue to assign.

◆ assign_int64()

void ignite::big_decimal::assign_int64 ( int64_t val)
inline

Assign specified value to this Decimal.

Parameters
valValue to assign.

◆ assign_string() [1/2]

void ignite::big_decimal::assign_string ( const char * val,
int32_t len )
inline

Assign specified value to this Decimal.

Parameters
valString to assign.
lenString length.

◆ assign_string() [2/2]

void ignite::big_decimal::assign_string ( const std::string & val)
inline

Assign specified value to this Decimal.

Parameters
valString to assign.

◆ assign_uint64()

void ignite::big_decimal::assign_uint64 ( uint64_t val)
inline

Assign specified value to this Decimal.

Parameters
valValue to assign.

◆ byte_size()

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

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

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

◆ compare()

int ignite::big_decimal::compare ( const big_decimal & other) const
nodiscard

compare this instance to another.

Parameters
otherAnother instance.
Returns
Comparasion result - 0 if equal, 1 if this is greater, -1 if this is less.

◆ divide()

void ignite::big_decimal::divide ( const big_decimal & other,
big_decimal & res ) const

Divide this to another big decimal.

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

◆ from_double()

big_decimal ignite::big_decimal::from_double ( double val)
inlinestatic

From double.

Parameters
valDouble value.
Returns
An instance of big_decimal from double.

◆ get_precision()

std::int32_t ignite::big_decimal::get_precision ( ) const
inlinenodiscardnoexcept

Get precision of the Decimal.

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

◆ get_scale()

std::int16_t ignite::big_decimal::get_scale ( ) const
inlinenodiscardnoexcept

Get scale.

Returns
Scale.

◆ get_unscaled_value()

const big_integer & ignite::big_decimal::get_unscaled_value ( ) const
inlinenodiscardnoexcept

Get unscaled value.

Returns
Unscaled value.

◆ is_negative()

bool ignite::big_decimal::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_decimal::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_decimal::is_zero ( ) const
inlinenodiscardnoexcept

Check whether this value is zero.

Returns
True if this value is negative and false otherwise.

◆ multiply()

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

Muitiply this to another big decimal.

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

◆ negate()

void ignite::big_decimal::negate ( )
inline

Reverses sign of this value.

◆ operator double()

ignite::big_decimal::operator double ( ) const
inlineexplicit

Convert to double.

◆ operator int64_t()

ignite::big_decimal::operator int64_t ( ) const
inlineexplicit

Convert to int64_t.

◆ set_scale()

void ignite::big_decimal::set_scale ( std::int16_t new_scale,
big_decimal & res ) const

Set scale.

Parameters
scaleScale to set.
resResult is placed here. Can be *this.

◆ store_bytes()

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

Store this decimal 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_decimal::subtract ( const big_decimal & other,
big_decimal & res ) const

Subtract another big decimal from this.

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

◆ to_bytes()

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

Convert value to bytes.

Returns
Vector of bytes.

◆ to_double()

double ignite::big_decimal::to_double ( ) const
inlinenodiscard

Convert to double.

Returns
Double value.

◆ to_int64()

int64_t ignite::big_decimal::to_int64 ( ) const
inlinenodiscard

Convert to int64_t.

Returns
int64_t value.

◆ operator<<

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

Output operator.

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

◆ operator>>

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

Input operator.

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

◆ swap

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

Swap function for the Decimal type.

Parameters
otherOther instance.

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