22#include "OnixS/CME/DropCopy/Export.h"
85 operator Int32()
const;
95 operator Int64()
const;
178 : mantissa_(other.mantissa_)
179 , exponent_(other.exponent_)
205 mantissa_ = other.mantissa_;
206 exponent_ = other.exponent_;
211inline Decimal::operator
Int32()
const
220 throw std::domain_error(
"Cannot cast value to target type. ");
232 throw std::domain_error(
"Cannot cast value to target type. ");
235inline Decimal::operator
Int64()
const
244 throw std::domain_error(
"Cannot cast value to target type. ");
256 throw std::domain_error(
"Cannot cast value to target type. ");
268 throw std::domain_error(
"Cannot cast value to target type. ");
273 std::string presentation;
279static const int maxAbsPower10 = 20;
280static const int powers10Size = maxAbsPower10 * 2 + 1;
282static const double powers10[] = {1E-20, 1E-19, 1E-18, 1E-17, 1E-16, 1E-15, 1E-14, 1E-13, 1E-12,
283 1E-11, 1E-10, 1E-9, 1E-8, 1E-7, 1E-6, 1E-5, 1E-4, 1E-3,
284 1E-2, 1E-1, 1E0, 1E1, 1E2, 1E3, 1E4, 1E5, 1E6,
285 1E7, 1E8, 1E9, 1E10, 1E11, 1E12, 1E13, 1E14, 1E15,
286 1E16, 1E17, 1E18, 1E19, 1E20};
290 const int offset = power + maxAbsPower10;
291 if (offset >= 0 && offset < powers10Size)
293 return powers10[offset];
296 throw std::invalid_argument(
"Invalid power argument, must be in range [-20, 20]");
303 return mantissa_ * fastPower10(exponent_);
312 if (fabs(modf(value, &dummy)) != 0.0)
317 const Double rounding = 0.5 * fastPower10(-exp);
318 value += (value > 0) ? rounding : -rounding;
320 value *= fastPower10(exp);
321 convertedExponent = -exp;
448ONIXS_CME_DROP_COPY_EXPORT std::ostream&
Decimal type for better precision.
Decimal(DecimalMantissa mantissa=0, DecimalExponent exponent=0)
Initializes instance from compound components.
bool toNumber(Int32 &) const
Decimal & operator=(const Decimal &other)
Reinitializes instance from another one.
std::string toString() const
Returns text presentation of decimal.
static Decimal parse(const char *buffer, size_t bufferSize)
bool toNumber(Int64 &) const
DecimalExponent exponent() const
Returns exponent part of decimal.
static bool tryParse(const char *buffer, size_t bufferSize, Decimal &)
bool operator!=(const Decimal &) const
Compares two numbers.
bool toNumber(Double &) const
Decimal(Double value, size_t precision)
void toString(std::string &) const
Appends text presentation to given string.
bool toNumber(UInt64 &) const
bool operator==(const Decimal &) const
Compares two numbers.
bool toNumber(UInt32 &) const
DecimalMantissa mantissa() const
Returns mantissa part of decimal.
static Decimal fromDoubleUnchecked(Double value, size_t precision)
Double toDoubleUnchecked() const
bool operator<(const Decimal &) const
Establishes order between two values.
bool operator>(const Decimal &) const
Establishes order between two values.
Helper functions for CME fixed point decimal case.
const DecimalComparator Comparator
bool nonEqual(const Decimal &lhs, const Decimal &rhs)
bool less(const Decimal &lhs, const Decimal &rhs)
bool greater(const Decimal &lhs, const Decimal &rhs)
bool equal(const Decimal &lhs, const Decimal &rhs)
Helper functions for generic decimal case.
const DecimalComparator Comparator
bool nonEqual(const Decimal &lhs, const Decimal &rhs)
bool less(const Decimal &lhs, const Decimal &rhs)
bool greater(const Decimal &lhs, const Decimal &rhs)
bool equal(const Decimal &lhs, const Decimal &rhs)
OnixS::CME::DropCopy::Double fastPower10(int power)
unsigned long long UInt64
std::ostream & operator<<(std::ostream &, const OnixS::CME::DropCopy::Error &)
const CompareFunction equal
Comparing functions.
DecimalComparator & operator=(const DecimalComparator &)
bool(* CompareFunction)(const Decimal &, const Decimal &)
Comparing function signature.
const CompareFunction greater
bool fixedPoint() const
Returns true if this instance is fixed point decimal comparator.
DecimalComparator(const CompareFunction equalFunc, const CompareFunction nonEqualFunc, const CompareFunction lessFunc, const CompareFunction greaterFunc)
Constructor.
bool genericDecimal() const
Returns true if this instance is generic decimal comparator.
const CompareFunction nonEqual
const CompareFunction less
Helper class for conversion from string to number.
static bool tryParse(const char *buffer, size_t bufferSize, Int32 &number)
static bool tryParse(const char *buffer, size_t bufferSize, UInt32 &number)
static bool tryParse(const char *buffer, size_t bufferSize, UInt64 &number)
static bool tryParse(const char *buffer, size_t bufferSize, Decimal &number)
static bool tryParse(const char *buffer, size_t bufferSize, Double &number)
static bool tryParse(const char *buffer, size_t bufferSize, Int64 &number)