LongPort OpenAPI C++ SDK
Public Member Functions | List of all members
longport::Decimal Class Reference

#include <decimal.hpp>

Public Member Functions

 Decimal (const lb_decimal_t *other)
 
 Decimal (const Decimal &other)
 
 Decimal (const char *str)
 Constructs a new Decimal number from string. More...
 
 Decimal (const std::string &str)
 Constructs a new Decimal number from string. More...
 
 Decimal (double other)
 Constructs a new Decimal number from double. More...
 
 Decimal (double other, uint32_t dp)
 
 ~Decimal ()
 
 operator const lb_decimal_t * () const
 
 operator lb_decimal_t * ()
 
 operator double () const
 
Decimal operator+ (const Decimal &other) const
 
Decimaloperator+= (const Decimal &other)
 
Decimal operator- (const Decimal &other) const
 
Decimaloperator-= (const Decimal &other)
 
Decimal operator* (const Decimal &other) const
 
Decimaloperator*= (const Decimal &other)
 
Decimal operator/ (const Decimal &other) const
 
Decimaloperator/= (const Decimal &other)
 
Decimal operator% (const Decimal &other) const
 
Decimaloperator%= (const Decimal &other)
 
Decimal operator- () const
 
bool operator> (const Decimal &other) const
 
bool operator>= (const Decimal &other) const
 
bool operator== (const Decimal &other) const
 
bool operator< (const Decimal &other) const
 
bool operator<= (const Decimal &other) const
 
double to_double () const
 
void abs ()
 Computes the absolute value. More...
 
void ceil ()
 Returns the smallest integer greater than or equal to a number. More...
 
void floor ()
 Returns the largest integer less than or equal to a number. More...
 
void fract ()
 Returns a new Decimal representing the fractional portion of the number. More...
 
bool is_negative () const
 Returns true if the decimal is negative. More...
 
bool is_positive () const
 Returns true if the decimal is positive. More...
 
bool is_zero () const
 Returns true if this Decimal number is equivalent to zero. More...
 
Decimal max (const Decimal &other) const
 Returns the maximum of the two numbers. More...
 
Decimal min (const Decimal &other) const
 Returns the minimum of the two numbers. More...
 
void normalize ()
 Strips any trailing zero’s from a Decimal and converts -0 to 0. More...
 
void round ()
 
void round (uint32_t dp)
 
void trunc ()
 
void sin ()
 Computes the sine of a number (in radians) More...
 
void cos ()
 Computes the cosine of a number (in radians) More...
 
void tan ()
 
void sqrt ()
 The square root of a Decimal. Uses a standard Babylonian method. More...
 
void pow (const Decimal &exp)
 
void ln ()
 
void log10 ()
 Calculates the base 10 logarithm of a specified Decimal number. More...
 
void exp ()
 
void exp_with_tolerance (const Decimal &tolerance)
 
void erf ()
 
void norm_pdf ()
 The Probability density function for a Normal distribution. More...
 
std::string to_string () const
 

Constructor & Destructor Documentation

◆ Decimal() [1/6]

longport::Decimal::Decimal ( const lb_decimal_t other)

◆ Decimal() [2/6]

longport::Decimal::Decimal ( const Decimal other)

◆ Decimal() [3/6]

longport::Decimal::Decimal ( const char *  str)

Constructs a new Decimal number from string.

◆ Decimal() [4/6]

longport::Decimal::Decimal ( const std::string &  str)

Constructs a new Decimal number from string.

◆ Decimal() [5/6]

longport::Decimal::Decimal ( double  other)

Constructs a new Decimal number from double.

◆ Decimal() [6/6]

longport::Decimal::Decimal ( double  other,
uint32_t  dp 
)

Constructs a new Decimal number with the specified number of decimal points for fractional portion. Rounding currently follows “Bankers Rounding” rules. e.g. 6.5 -> 6, 7.5 -> 8

◆ ~Decimal()

longport::Decimal::~Decimal ( )

Member Function Documentation

◆ abs()

void longport::Decimal::abs ( )

Computes the absolute value.

◆ ceil()

void longport::Decimal::ceil ( )

Returns the smallest integer greater than or equal to a number.

◆ cos()

void longport::Decimal::cos ( )

Computes the cosine of a number (in radians)

◆ erf()

void longport::Decimal::erf ( )

Abramowitz Approximation of Error Function from wikipedia

◆ exp()

void longport::Decimal::exp ( )

The estimated exponential function, ex. Stops calculating when it is within tolerance of roughly 0.0000002.

◆ exp_with_tolerance()

void longport::Decimal::exp_with_tolerance ( const Decimal tolerance)

The estimated exponential function, ex using the tolerance provided as a hint as to when to stop calculating. A larger tolerance will cause the number to stop calculating sooner at the potential cost of a slightly less accurate result.

◆ floor()

void longport::Decimal::floor ( )

Returns the largest integer less than or equal to a number.

◆ fract()

void longport::Decimal::fract ( )

Returns a new Decimal representing the fractional portion of the number.

◆ is_negative()

bool longport::Decimal::is_negative ( ) const

Returns true if the decimal is negative.

◆ is_positive()

bool longport::Decimal::is_positive ( ) const

Returns true if the decimal is positive.

◆ is_zero()

bool longport::Decimal::is_zero ( ) const

Returns true if this Decimal number is equivalent to zero.

◆ ln()

void longport::Decimal::ln ( )

Calculates the natural logarithm for a Decimal calculated using Taylor’s series.

◆ log10()

void longport::Decimal::log10 ( )

Calculates the base 10 logarithm of a specified Decimal number.

◆ max()

Decimal longport::Decimal::max ( const Decimal other) const

Returns the maximum of the two numbers.

◆ min()

Decimal longport::Decimal::min ( const Decimal other) const

Returns the minimum of the two numbers.

◆ norm_pdf()

void longport::Decimal::norm_pdf ( )

The Probability density function for a Normal distribution.

◆ normalize()

void longport::Decimal::normalize ( )

Strips any trailing zero’s from a Decimal and converts -0 to 0.

◆ operator const lb_decimal_t *()

longport::Decimal::operator const lb_decimal_t * ( ) const

◆ operator double()

longport::Decimal::operator double ( ) const

◆ operator lb_decimal_t *()

longport::Decimal::operator lb_decimal_t * ( )

◆ operator%()

Decimal longport::Decimal::operator% ( const Decimal other) const

◆ operator%=()

Decimal& longport::Decimal::operator%= ( const Decimal other)

◆ operator*()

Decimal longport::Decimal::operator* ( const Decimal other) const

◆ operator*=()

Decimal& longport::Decimal::operator*= ( const Decimal other)

◆ operator+()

Decimal longport::Decimal::operator+ ( const Decimal other) const

◆ operator+=()

Decimal& longport::Decimal::operator+= ( const Decimal other)

◆ operator-() [1/2]

Decimal longport::Decimal::operator- ( ) const

◆ operator-() [2/2]

Decimal longport::Decimal::operator- ( const Decimal other) const

◆ operator-=()

Decimal& longport::Decimal::operator-= ( const Decimal other)

◆ operator/()

Decimal longport::Decimal::operator/ ( const Decimal other) const

◆ operator/=()

Decimal& longport::Decimal::operator/= ( const Decimal other)

◆ operator<()

bool longport::Decimal::operator< ( const Decimal other) const

◆ operator<=()

bool longport::Decimal::operator<= ( const Decimal other) const

◆ operator==()

bool longport::Decimal::operator== ( const Decimal other) const

◆ operator>()

bool longport::Decimal::operator> ( const Decimal other) const

◆ operator>=()

bool longport::Decimal::operator>= ( const Decimal other) const

◆ pow()

void longport::Decimal::pow ( const Decimal exp)

Raise self to the given Decimal exponent: xy. If exp is not whole then the approximation ey*ln(x) is used.

◆ round() [1/2]

void longport::Decimal::round ( )

Returns a new Decimal number with no fractional portion (i.e. an integer). Rounding currently follows “Bankers Rounding” rules. e.g. 6.5 -> 6, 7.5 -> 8

◆ round() [2/2]

void longport::Decimal::round ( uint32_t  dp)

Returns a new Decimal number with the specified number of decimal points for fractional portion. Rounding currently follows “Bankers Rounding” rules. e.g. 6.5 -> 6, 7.5 -> 8

◆ sin()

void longport::Decimal::sin ( )

Computes the sine of a number (in radians)

◆ sqrt()

void longport::Decimal::sqrt ( )

The square root of a Decimal. Uses a standard Babylonian method.

◆ tan()

void longport::Decimal::tan ( )

Computes the tangent of a number (in radians). Panics upon overflow or upon approaching a limit.

◆ to_double()

double longport::Decimal::to_double ( ) const

◆ to_string()

std::string longport::Decimal::to_string ( ) const

◆ trunc()

void longport::Decimal::trunc ( )

Returns a new Decimal integral with no fractional portion. This is a true truncation whereby no rounding is performed.


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