knowL: Knowledge Libraries
Loading...
Searching...
No Matches
knowCore::BigNumber Class Reference

Class that can contains large numeric value. More...

#include <BigNumber.h>

Public Types

enum class  Sign {
  Positive , Negative , NaN , PositiveInfinite ,
  NegativeInfinite
}
 

Public Member Functions

 BigNumber (const BigNumber &_rhs)
 
 BigNumber (BigNumber &&_rhs)
 
BigNumberoperator= (const BigNumber &_rhs)
 
 BigNumber (qint16 weight, Sign sign, qint16 dscale, const QList< quint16 > &digits)
 
 BigNumber (std::intmax_t _value)
 
 BigNumber (std::uintmax_t _value)
 
template<typename _T_ >
requires (std::is_integral_v<_T_> and std::is_unsigned_v<_T_>)
 BigNumber (_T_ _value)
 
template<typename _T_ >
requires (std::is_integral_v<_T_> and std::is_signed_v<_T_>)
 BigNumber (_T_ _value)
 
 BigNumber (double _value)
 
bool isNaN () const
 
bool isFinite () const
 
bool isInfinite () const
 
bool isFloating () const
 
QString toString () const
 
QVariant toVariant () const
 return an optimal variant representation This function try to return a variant with an optimal representation:
 
knowCore::Value toValue () const
 return an optimal value representation This function try to return a variant with an optimal representation:
 
double toDouble () const
 
cres_qresult< qint64 > toInt64 (bool _truncate=false) const
 
cres_qresult< quint64 > toUInt64 (bool _truncate=false) const
 
bool operator== (const BigNumber &_rhs) const
 
bool operator!= (const BigNumber &_rhs) const
 
QByteArray md5 () const
 
void hash (QCryptographicHash *_hash) const
 
BigNumber operator+ (const BigNumber &_rhs) const
 
BigNumber operator- (const BigNumber &_rhs) const
 
BigNumber operator* (const BigNumber &_rhs) const
 
BigNumber operator/ (const BigNumber &_rhs) const
 
BigNumber operator- () const
 
bool operator< (const BigNumber &_rhs) const
 
bool operator<= (const BigNumber &_rhs) const
 
bool operator> (const BigNumber &_rhs) const
 
bool operator>= (const BigNumber &_rhs) const
 
template<typename _T_ >
requires (std::is_arithmetic_v<_T_>)
BigNumber operator+ (const _T_ &_rhs) const
 
template<typename _T_ >
requires (std::is_arithmetic_v<_T_>)
BigNumber operator- (const _T_ &_rhs) const
 
template<typename _T_ >
requires (std::is_arithmetic_v<_T_>)
BigNumber operator* (const _T_ &_rhs) const
 
template<typename _T_ >
requires (std::is_arithmetic_v<_T_>)
BigNumber operator/ (const _T_ &_rhs) const
 
template<typename _T_ >
requires (std::is_arithmetic_v<_T_>)
bool operator< (const _T_ &_rhs) const
 
template<typename _T_ >
requires (std::is_arithmetic_v<_T_>)
bool operator<= (const _T_ &_rhs) const
 
template<typename _T_ >
requires (std::is_arithmetic_v<_T_>)
bool operator> (const _T_ &_rhs) const
 
template<typename _T_ >
requires (std::is_arithmetic_v<_T_>)
bool operator>= (const _T_ &_rhs) const
 
quint16 weight () const
 
Sign sign () const
 
quint16 dscale () const
 
QList< quint16 > digits () const
 

Static Public Member Functions

static cres_qresult< BigNumberfromString (const QString &_value)
 
static cres_qresult< BigNumberfromString (const char *_value)
 
static cres_qresult< BigNumberfromVariant (const QVariant &_value)
 
static cres_qresult< BigNumberfromValue (const knowCore::Value &_value)
 
static BigNumber zero ()
 
static BigNumber nan ()
 
static BigNumber positiveInfinite ()
 
static BigNumber negativeInfinite ()
 

Detailed Description

Class that can contains large numeric value.

The representation of number in this class is modeled after the one used by postgres (see postgres/src/backend/utils/adt/numeric.c source code for the "specification").

In BigNumber the number are stored in base-1000:

  • m_digits stores the significant digits, each element of the list is a quint16 between 0->9999
  • m_weight stores the 10000-exponent of the first number in m_digits
  • m_dscale stores the number of decimal values (10.02 has dscale of 2, 10 0f 0, 10.00005 of 5...). This number is purely for display purposes of the number of 0 after the ".".

The number is given by m_digits[0]*10000^m_weight + m_digits[1]*10000^(m_weight-1) + ....

Member Function Documentation

◆ hash()

void BigNumber::hash ( QCryptographicHash * _hash) const

Add the big number to a cryptographic hash calculation.

◆ isFloating()

bool BigNumber::isFloating ( ) const
Returns
true if is floating point number

◆ toInt64()

cres_qresult< qint64 > BigNumber::toInt64 ( bool _truncate = false) const

Attempt to convert to int64, in case of overflow, return an error.

_truncate if set to true truncate a floating point number, otherwise return an error if big number is a floating point

◆ toValue()

Value BigNumber::toValue ( ) const

return an optimal value representation This function try to return a variant with an optimal representation:

  • first try to store the number if a (u)int64 (depending on sign)
  • if it cannot be represented by (u)int64, then return a QVariant countaining a BigNumber

◆ toVariant()

QVariant BigNumber::toVariant ( ) const

return an optimal variant representation This function try to return a variant with an optimal representation:

  • first try to store the number if a (u)int64 (depending on sign)
  • if it cannot be represented by (u)int64, then return a QVariant countaining a BigNumber

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