B2BITS FIX Antenna C++  2.31.0
Public Member Functions | Static Public Member Functions | Static Public Attributes | List of all members
Engine::Decimal Class Reference

Encapsulates float type. More...

#include <B2BITS_Decimal.h>

Public Member Functions

Decimal changeExponent (System::i32 newExponent) const throw ()
 Returns new Decimal value with required exponent. More...
 
 Decimal () throw ()
 Default contructor. More...
 
 Decimal (System::i64 m, System::i32 e) throw ()
 Contructor Constructs object from mantissa and exponent. More...
 
 Decimal (double v) throw ()
 Contructor Constructs object from double. More...
 
 Decimal (System::i64 x) throw ()
 Contructor Constructs object from 64-bit integer. More...
 
bool equals (const Decimal &rv) const throw ()
 Compares two Decimals. More...
 
System::i32 exponent () const throw ()
 Returns exponent part of the value. More...
 
System::i32 getExponent () const throw ()
 Returns exponent part of the value. More...
 
System::i64 getMantissa () const throw ()
 Returns mantissa part of the value. More...
 
System::i64 mantissa () const throw ()
 Returns mantissa part of the value. More...
 
bool operator!= (Engine::Decimal const &val) const throw ()
 Compares two decimals. More...
 
Decimal operator* (Engine::Decimal const &val) const throw ()
 Multiplication operator. More...
 
Decimaloperator*= (Engine::Decimal const &val) throw ()
 Multiplication assignment. More...
 
Decimal operator+ (Engine::Decimal const &val) const throw ()
 Addition operator. More...
 
Decimaloperator++ () throw ()
 Prefix increment. More...
 
Decimal operator++ (int) throw ()
 Postfix increment. More...
 
Decimaloperator+= (Engine::Decimal const &val) throw ()
 Addition assignment. More...
 
Decimal operator- (Engine::Decimal const &val) const throw ()
 Substraction operator. More...
 
Decimaloperator-- () throw ()
 Prefix decrement. More...
 
Decimal operator-- (int) throw ()
 Postfix decrement. More...
 
Decimaloperator-= (Engine::Decimal const &val) throw ()
 Subtraction assignment. More...
 
bool operator< (Engine::Decimal const &val) const throw ()
 Compares two decimals. More...
 
bool operator<= (Engine::Decimal const &val) const throw ()
 Compares two decimals. More...
 
bool operator== (Engine::Decimal const &val) const throw ()
 Compares two decimals. More...
 
bool operator> (Engine::Decimal const &val) const throw ()
 Compares two decimals. More...
 
bool operator>= (Engine::Decimal const &val) const throw ()
 Compares two decimals. More...
 
double toDouble () const throw ()
 Converts stored value to double. More...
 
float toFloat () const throw ()
 Converts stored value to float. More...
 
std::string toStdString () const
 Converts decimal to FIX string. More...
 
char * toString (char *buf) const throw ()
 Converts decimal to FIX string. More...
 
char * toString (char *buf, std::size_t size) const throw ()
 If result string is less than passed buffer, remain chars will be filled with zeros according to FIX protocol. More...
 

Static Public Member Functions

static Decimal fromDouble (double v, int precision) throw ()
 Contructor Constructs object from double. More...
 
static Decimal fromDouble (double v) throw ()
 Contructor Constructs object from double. More...
 
static Decimal fromFixString (AsciiString str) throw ()
 Converts string to Decimal. More...
 
static Decimal fromString (AsciiString str) throw ()
 Converts string to Decimal. More...
 
static Decimal fromString (WideString str) throw ()
 Converts wide-string to Decimal. More...
 

Static Public Attributes

static unsigned int const ValueSize = 2 + 63 + sizeof( "18446744073709551616" )
 Maximum buffer size required to store value. More...
 

Detailed Description

Encapsulates float type.

Constructor & Destructor Documentation

◆ Decimal() [1/4]

Engine::Decimal::Decimal ( )
throw (
)

Default contructor.

◆ Decimal() [2/4]

Engine::Decimal::Decimal ( System::i64  m,
System::i32  e 
)
throw (
)

Contructor Constructs object from mantissa and exponent.

Parameters
mMantissa
eExponent

◆ Decimal() [3/4]

Engine::Decimal::Decimal ( double  v)
throw (
)

Contructor Constructs object from double.

Parameters
vValue of the double type

◆ Decimal() [4/4]

Engine::Decimal::Decimal ( System::i64  x)
throw (
)

Contructor Constructs object from 64-bit integer.

Parameters
xValue of the i64 type

Member Function Documentation

◆ changeExponent()

Decimal Engine::Decimal::changeExponent ( System::i32  newExponent) const
throw (
)

Returns new Decimal value with required exponent.

Parameters
newExponentRequired exponent. Must be in range [currentExponent-18 .. currentExponent+18]

◆ equals()

bool Engine::Decimal::equals ( const Decimal rv) const
throw (
)

Compares two Decimals.

Parameters
rvValue to compare with.
Returns
true if equals; false otherwise

◆ exponent()

System::i32 Engine::Decimal::exponent ( ) const
throw (
)
inline

Returns exponent part of the value.

Returns
exponent part of the value

◆ fromDouble() [1/2]

static Decimal Engine::Decimal::fromDouble ( double  v,
int  precision 
)
throw (
)
static

Contructor Constructs object from double.

Warning
This method is lossy.
Parameters
vValue of the double type
precisionNumber of digits after point. Must be in range [0..17]

◆ fromDouble() [2/2]

static Decimal Engine::Decimal::fromDouble ( double  v)
throw (
)
static

Contructor Constructs object from double.

Warning
This method is lossy.
Parameters
vValue of the double type

◆ fromFixString()

static Decimal Engine::Decimal::fromFixString ( AsciiString  str)
throw (
)
inlinestatic

Converts string to Decimal.

◆ fromString() [1/2]

static Decimal Engine::Decimal::fromString ( AsciiString  str)
throw (
)
static

Converts string to Decimal.

◆ fromString() [2/2]

static Decimal Engine::Decimal::fromString ( WideString  str)
throw (
)
static

Converts wide-string to Decimal.

◆ getExponent()

System::i32 Engine::Decimal::getExponent ( ) const
throw (
)
inline

Returns exponent part of the value.

Returns
exponent part of the value

◆ getMantissa()

System::i64 Engine::Decimal::getMantissa ( ) const
throw (
)
inline

Returns mantissa part of the value.

Returns
mantissa part of the value

◆ mantissa()

System::i64 Engine::Decimal::mantissa ( ) const
throw (
)
inline

Returns mantissa part of the value.

Returns
mantissa part of the value

◆ operator!=()

bool Engine::Decimal::operator!= ( Engine::Decimal const &  val) const
throw (
)

Compares two decimals.

Returns
true if two decimals are NOT equal; false otherwise.

◆ operator*()

Decimal Engine::Decimal::operator* ( Engine::Decimal const &  val) const
throw (
)
inline

Multiplication operator.

◆ operator*=()

Decimal& Engine::Decimal::operator*= ( Engine::Decimal const &  val)
throw (
)
inline

Multiplication assignment.

◆ operator+()

Decimal Engine::Decimal::operator+ ( Engine::Decimal const &  val) const
throw (
)
inline

Addition operator.

Note
Please note this method works only if both decimal have same exponent

◆ operator++() [1/2]

Decimal& Engine::Decimal::operator++ ( )
throw (
)
inline

Prefix increment.

◆ operator++() [2/2]

Decimal Engine::Decimal::operator++ ( int  )
throw (
)
inline

Postfix increment.

◆ operator+=()

Decimal& Engine::Decimal::operator+= ( Engine::Decimal const &  val)
throw (
)
inline

Addition assignment.

Note
Please note this method works only if both decimal have same exponent

◆ operator-()

Decimal Engine::Decimal::operator- ( Engine::Decimal const &  val) const
throw (
)
inline

Substraction operator.

Note
Please note this method works only if both decimal have same exponent

◆ operator--() [1/2]

Decimal& Engine::Decimal::operator-- ( )
throw (
)
inline

Prefix decrement.

◆ operator--() [2/2]

Decimal Engine::Decimal::operator-- ( int  )
throw (
)
inline

Postfix decrement.

◆ operator-=()

Decimal& Engine::Decimal::operator-= ( Engine::Decimal const &  val)
throw (
)
inline

Subtraction assignment.

Note
Please note this method works only if both decimal have same exponent

◆ operator<()

bool Engine::Decimal::operator< ( Engine::Decimal const &  val) const
throw (
)

Compares two decimals.

Returns
true if left decimal is smaller than right; false otherwise.

◆ operator<=()

bool Engine::Decimal::operator<= ( Engine::Decimal const &  val) const
throw (
)

Compares two decimals.

Returns
true if left decimal is smaller or equal than right; false otherwise.
Note
Please note this method works only if both decimal have same exponent

◆ operator==()

bool Engine::Decimal::operator== ( Engine::Decimal const &  val) const
throw (
)

Compares two decimals.

Returns
true if two decimals are equal; false otherwise.

◆ operator>()

bool Engine::Decimal::operator> ( Engine::Decimal const &  val) const
throw (
)

Compares two decimals.

Returns
true if left decimal is larger than right; false otherwise.

◆ operator>=()

bool Engine::Decimal::operator>= ( Engine::Decimal const &  val) const
throw (
)

Compares two decimals.

Returns
true if left decimal is larger or equal than right; false otherwise.

◆ toDouble()

double Engine::Decimal::toDouble ( ) const
throw (
)

Converts stored value to double.

Returns
double representation of the value

◆ toFloat()

float Engine::Decimal::toFloat ( ) const
throw (
)

Converts stored value to float.

Returns
float representation of the value

◆ toStdString()

std::string Engine::Decimal::toStdString ( ) const

Converts decimal to FIX string.

Converts decimal to FIX string

Returns
FIX representation of the Decimal value

◆ toString() [1/2]

char* Engine::Decimal::toString ( char *  buf) const
throw (
)

Converts decimal to FIX string.

Parameters
[out]bufBuffer to convert to. Should be enough to store Engine::Decimal::ValueSize bytes.
Returns
Pointer to the first character of the value

◆ toString() [2/2]

char* Engine::Decimal::toString ( char *  buf,
std::size_t  size 
) const
throw (
)

If result string is less than passed buffer, remain chars will be filled with zeros according to FIX protocol.

Parameters
[out]bufBuffer to convert to.
[in]sizeSize of the buffer. Must be positive.

Member Data Documentation

◆ ValueSize

unsigned int const Engine::Decimal::ValueSize = 2 + 63 + sizeof( "18446744073709551616" )
static

Maximum buffer size required to store value.