3#ifndef _aspose_system_decimal_h_
4#define _aspose_system_decimal_h_
6#include <system/object.h>
7#include <system/string.h>
8#include <system/midpoint_rounding.h>
9#include <system/globalization/number_styles.h>
10#include <system/globalization/culture_info.h>
11#include <system/boxable_traits.h>
12#include <system/type_code.h>
21#ifdef ASPOSECPPLIB_BEING_BUILT
22#include <boost/multiprecision/cpp_dec_float.hpp>
26namespace boost {
namespace multiprecision {
29 template <
unsigned,
class,
class>
class cpp_dec_float;
31 using backends::cpp_dec_float;
33 ASPOSECPP_3RD_PARTY_ENUM(expression_template_option);
35 template <
class, expression_
template_option>
class number;
41#ifndef ASPOSE_CPP_DECIMAL_DIGITS
43 #define ASPOSE_CPP_DECIMAL_DIGITS 28
47#define DECIMAL_FROM_DOUBLE_SIGNIFICANT_DIGITS 15
50#define DECIMAL_FROM_FLOAT_SIGNIFICANT_DIGITS 7
55 template <
typename I>
class DecimalConverter;
58 typedef boost::multiprecision::number<boost::multiprecision::cpp_dec_float<ASPOSE_CPP_DECIMAL_DIGITS + 1, std::int32_t, void>, (boost::multiprecision::expression_template_option)1> decimal_number_type;
60 struct decimal_size_equivalent {
62 std::array<std::uint32_t, (ASPOSE_CPP_DECIMAL_DIGITS + 8) / 8 + 3> m_data;
64 std::int32_t m_exponent;
68 enum { e1, e2, e3 } m_class;
70 std::int32_t m_precision;
74 ASPOSECPP_3RD_PARTY_TYPE_HOLDER(decimal_number_type, number,
sizeof(decimal_size_equivalent), std::uint32_t, DecimalHolder);
77struct DecimalDotNetImpl;
109 template<
typename I>
friend class Detail::DecimalConverter;
145 ASPOSECPP_SHARED_API
Decimal(std::uint16_t i);
148 ASPOSECPP_SHARED_API
Decimal(std::uint32_t i);
151 ASPOSECPP_SHARED_API
Decimal(std::uint64_t i);
161 ASPOSECPP_SHARED_API
explicit Decimal(
const std::string& str);
168 ASPOSECPP_SHARED_API
Decimal(int32_t lo, int32_t mid, int32_t hi,
bool isNegative, uint8_t scale);
176 ASPOSECPP_SHARED_API
Decimal(std::nullptr_t bits);
187 ASPOSECPP_SHARED_API
explicit operator std::int8_t()
const;
189 ASPOSECPP_SHARED_API
explicit operator std::int16_t()
const;
191 ASPOSECPP_SHARED_API
explicit operator std::int32_t()
const;
193 ASPOSECPP_SHARED_API
explicit operator std::int64_t()
const;
195 ASPOSECPP_SHARED_API
explicit operator std::uint8_t()
const;
197 ASPOSECPP_SHARED_API
explicit operator std::uint16_t()
const;
199 ASPOSECPP_SHARED_API
explicit operator std::uint32_t()
const;
201 ASPOSECPP_SHARED_API
explicit operator std::uint64_t()
const;
203 ASPOSECPP_SHARED_API
explicit operator float()
const;
205 ASPOSECPP_SHARED_API
explicit operator double()
const;
209 ASPOSECPP_SHARED_API
explicit operator bool()
const;
294 ASPOSECPP_SHARED_API
friend std::ostream& operator<<(std::ostream& os,
const Decimal& d);
295 ASPOSECPP_SHARED_API
friend std::wostream& operator<<(std::wostream& os,
const Decimal& d);
411 return *static_holder<ThisTypeInfo>();
466 static uint8_t
ToByte(
Decimal value) {
return static_cast<uint8_t
>(value); }
519 inline void EliminateRoundError()
523 typedef std::numeric_limits<T> limits;
524 if (limits::is_integer)
527 CutErroneousDigits(limits::digits10);
531 void CutErroneousDigits(
int digits);
534 void DecimalInternal(int32_t lo, int32_t mid, int32_t hi,
bool isNegative, uint8_t scale);
541template <typename T, typename _ = typename std::enable_if<std::is_arithmetic<T>::value>::type>
548template <typename T, typename _ = typename std::enable_if<std::is_arithmetic<T>::value>::type>
555template <typename T, typename _ = typename std::enable_if<std::is_arithmetic<T>::value>::type>
562template <typename T, typename _ = typename std::enable_if<std::is_arithmetic<T>::value>::type>
574ASPOSECPP_SHARED_API std::ostream& operator<<(std::ostream& stream,
const Decimal& decimal);
580ASPOSECPP_SHARED_API std::wostream& operator<<(std::wostream& stream,
const Decimal& decimal);
599 return static_cast<std::size_t
>(val.
GetHashCode());
Represents a decimal number. This type should be allocated on stack and passed to functions by value ...
Definition: decimal.h:107
static int16_t ToInt16(Decimal value)
Converts the Decimal value to signed 16-bit integer value.
Definition: decimal.h:472
Decimal(std::int32_t i)
Constructs an instance that represents the specified value.
String ToString(const String &format, std::nullptr_t=nullptr) const
static Decimal Parse(const String &s, Globalization::NumberStyles styles)
Converts the string representation of a decimal number into an equivalent instance of Decimal class u...
static const Decimal MinusOne
Represents number -1.
Definition: decimal.h:119
Decimal(int32_t lo, int32_t mid, int32_t hi, bool isNegative, uint8_t scale)
Constructs a Decimal object from the specified from the specified components.
Decimal(std::uint16_t i)
Constructs an instance that represents the specified value.
Decimal operator*(const Decimal &d) const
Returns a new instance of Decimal class that represents a value that is a result of multiplication of...
static const Decimal MaxValue
Represents the largest number that can be represented by Decimal class.
Definition: decimal.h:115
bool operator<(const Decimal &d) const
Determines if the value represented by the current object is less than the value represented by the s...
std::string ToStdString() const
Returns an instance of std::string that contains the string representation of the value represented b...
static void DecimalToDotNetImpl(const Decimal &value, DecimalDotNetImpl *impl)
Converts Decimal value to equivalent C#-styled representation.
static Decimal Floor(const Decimal &d)
Returns the largest integral value that is less than or equal to the specified value.
bool operator==(std::nullptr_t) const
Determines if the value represented by the current object is 0.
static bool TryParse(const String &value, Globalization::NumberStyles styles, const SharedPtr< IFormatProvider > &provider, Decimal &result)
Converts the specified string containing the string representation of a number to the equivalent Deci...
Decimal(const Decimal &d)
Constructs an instance of Decimal class that represents the same number as the specified Decimal obje...
Decimal operator+(const Decimal &d) const
Returns a new instance of Decimal class that represents a value that is a sum of values represented b...
Decimal(std::uint8_t i)
Constructs an instance that represents the specified value.
String ToString(const Decimal &value, std::nullptr_t) const
Definition: decimal.h:323
bool operator>(const Decimal &d) const
Determines if the value represented by the current object is greater than the value represented by th...
static Decimal Ceiling(const Decimal &d)
Returns the smallest integral value that is greater than or equal to the specified value.
static uint32_t ToUInt32(Decimal value)
Converts the Decimal value to unsigned 32-bit integer value.
Definition: decimal.h:474
String ToString(const String &format, const SharedPtr< IFormatProvider > &provider) const
Converts current object to its string representation using the specified string format and culture-sp...
Detail::decimal_number_type number_type
An alias for Detail::decimal_number_type.
Definition: decimal.h:112
Detail::DecimalHolder m_value
The value represented by the current object.
Definition: decimal.h:495
String ToString(const SharedPtr< Globalization::CultureInfo > &culture) const
static Decimal Round(const Decimal &d, MidpointRounding mode=MidpointRounding::ToEven)
Rounds the specified value to the nearest integral number. A parameter specifies the function's behav...
static Decimal Parse(const String &s)
Converts the string representation of a decimal number into an equivalent instance of Decimal class.
static Decimal Remainder(const Decimal &d1, const Decimal &d2)
Computes the remainder after dividing two Decimal values.
Definition: decimal.h:456
Decimal operator%(const Decimal &d) const
Returns a new instance of Decimal class that represents a value that is a result of modulo operation ...
bool operator<=(const Decimal &d) const
Determines if the value represented by the current object is less than or equal to the value represen...
Decimal & operator--()
Decrements the value represented by the current object.
static uint16_t ToUInt16(Decimal value)
Converts the Decimal value to unsigned 16-bit integer value.
Definition: decimal.h:470
static int32_t ToInt32(Decimal value)
Converts the Decimal value to signed 32-bit integer value.
Definition: decimal.h:476
bool operator!=(std::nullptr_t) const
Determines if the value represented by the current object is different from 0.
bool Equals(const SharedPtr< Object > &obj) const
Determines if the values represented by the current object and the specified object are equal.
static Decimal Add(const Decimal &d1, const Decimal &d2)
Adds two specified Decimal values.
Definition: decimal.h:441
Decimal & operator/=(const Decimal &d)
Assigns to the current object a new value that is the result of division of the value represented by ...
Decimal(float f)
Constructs an instance that represents the specified value.
static Decimal Divide(const Decimal &d1, const Decimal &d2)
Divides two specified Decimal values.
Definition: decimal.h:451
Decimal(const number_type &value)
Constructs an instance of Decimal class representing the specified value.
Decimal(std::uint64_t i)
Constructs an instance that represents the specified value.
static bool TryParse(const String &value, Decimal &result)
Converts the specified string containing the string representation of a number to the equivalent Deci...
static float ToSingle(Decimal value)
Converts the Decimal value to single precision floating-point number.
Definition: decimal.h:482
static void GetBytes(const Decimal &value, const System::ArrayPtr< uint8_t > &buffer)
Convert the specified Decimal value to an array of bytes.
String ToString(const SharedPtr< IFormatProvider > &provider) const
Converts current object to string using the culture-specific format information.
Decimal()
Constructs an instance that represents 0.
Decimal operator-(const Decimal &d) const
Returns a new instance of Decimal class that represents a value that is the result of subtraction of ...
static Decimal Parse(const String &s, Globalization::NumberStyles styles, const SharedPtr< IFormatProvider > &provider)
Converts the string representation of a decimal number into an equivalent instance of Decimal class u...
static uint8_t ToByte(Decimal value)
Converts the Decimal value to unsigned 8-bit integer value.
Definition: decimal.h:466
int GetHashCode() const
Returns a hash code for the current object.
Decimal & operator*=(const Decimal &d)
Assigns to the current object a new value that is the result of multiplication of values represented ...
TypeCode GetTypeCode() const
Gets object type code.
Definition: decimal.h:435
static Decimal Parse(const String &s, const SharedPtr< IFormatProvider > &provider)
Converts the string representation of a decimal number into an equivalent instance of Decimal class u...
Decimal(std::int64_t i)
Constructs an instance that represents the specified value.
static const Decimal One
Represents number 1.
Definition: decimal.h:121
String ToString() const
Returns the string representation of the value represented by the object.
Decimal & operator%=(const Decimal &d)
Assigns to the current object a new value that is the result of modulo operation with the values repr...
static Decimal Truncate(const Decimal &d)
Returns the Decimal object representing a value that has integral part equal to that of the value rep...
static int Compare(const Decimal &d1, const Decimal &d2)
Determines if the value represented by the first Decimal object is less than, equal to or greater tha...
Definition: decimal.h:374
int CompareTo(const Decimal &d) const
Determines if the value represented by the current object is less than, equal to or greater than the ...
String ToString(const String &format, const SharedPtr< Globalization::NumberFormatInfo > &nfi) const
Decimal(std::int8_t i)
Constructs an instance that represents the specified value.
bool Equals(const Decimal &d) const
Determines if the values represented by the current object and the specified object are equal.
static int64_t ToInt64(Decimal value)
Converts the Decimal value to signed 64-bit integer value.
Definition: decimal.h:480
String ToString(const SharedPtr< Globalization::NumberFormatInfo > &nfi) const
static Decimal FromOACurrency(int64_t currency)
Convert the specified OLE currency value to the equivalent Decimal value. NOT IMPLEMENTED.
Decimal(const std::string &str)
Constructs an instance that represents a value whose string representation is specified as an instanc...
static bool Equals(const Decimal &d1, const Decimal &d2)
Determines if the values represented by the specified objects are equal.
Definition: decimal.h:369
static Decimal Subtract(const Decimal &d1, const Decimal &d2)
Subtracts one specified Decimal value from another.
Definition: decimal.h:446
Decimal & operator+=(const Decimal &d)
Assigns to the current object a new value that is a sum of values represented by the current and spec...
Decimal(const ArrayPtr< int32_t > &bits)
Constructs an instance of Decimal class from integer array containing a binary representation.
String ToStringInternal() const
Returns the string representation of the value represented by the object. For internal use.
static int64_t ToOACurrency(const Decimal &value)
Convert the specified Decimal value to the equivalent OLE currency value. NOT IMPLEMENTED.
Decimal(double d)
Constructs an instance that represents the specified value.
Decimal & operator-=(const Decimal &d)
Assigns to the current object a new value that is the result of subtraction of the value represented ...
static Decimal Multiply(const Decimal &d1, const Decimal &d2)
Multiplies two specified Decimal values.
Definition: decimal.h:461
Decimal & operator++()
Increments the value represented by the current object.
static double ToDouble(Decimal value)
Converts the Decimal value to double precision floating-point number.
Definition: decimal.h:484
Decimal(std::int16_t i)
Constructs an instance that represents the specified value.
static uint64_t ToUInt64(Decimal value)
Converts the Decimal value to unsigned 64-bit integer value.
Definition: decimal.h:478
static Decimal Round(const Decimal &d, int digits, MidpointRounding mode=MidpointRounding::ToEven)
Rounds the specified value to the nearest value with the specified number of fractional digits....
static const Decimal Zero
Represents number 0.
Definition: decimal.h:123
static System::ArrayPtr< int > GetBits(const Decimal &d)
Converts the specified Decimal object into the binary representation of the value it represents.
Decimal(std::nullptr_t bits)
Always throws ArgumentNullException.
static const TypeInfo & Type()
Returns a reference to the TypeInfo object representing the Decimal class' type information.
Definition: decimal.h:409
Decimal(std::uint32_t i)
Constructs an instance that represents the specified value.
static int8_t ToSByte(Decimal value)
Converts the Decimal value to signed 8-bit integer value.
Definition: decimal.h:468
bool operator!=(const Decimal &d) const
Determines if the values represented by the current object and the specified object are not equal.
static Decimal Negate(const Decimal &d)
Returns a new instance of Decimal class that represents a value that results from negation of the val...
Definition: decimal.h:463
bool operator>=(const Decimal &d) const
Determines if the value represented by the current object is greater than or equal to the value repre...
Decimal operator/(const Decimal &d) const
Returns a new instance of Decimal class that represents a value that is a result of division of the v...
static const Decimal MinValue
Represents the smallest number that can be represented by Decimal class.
Definition: decimal.h:117
Decimal operator-() const
Returns a new instance of Decimal class that represents a value that results from negation of the val...
bool operator==(const Decimal &d) const
Determines if the values represented by the current object and the specified object are equal.
String ToString(const String &format, const SharedPtr< Globalization::CultureInfo > &culture) const
Pointer class to wrap types being allocated on heap. Use it to manage memory for classes inheriting O...
Definition: smart_ptr.h:180
String class used across the library. Is a substitute for C# System.String when translating code....
Definition: string.h:122
Represents a particular type and provides information about it.
Definition: type_info.h:109
NumberStyles
Number style allowed when parsing.
Definition: number_styles.h:12
Definition: db_command.h:9
void PrintTo(DateTime value, std::ostream *stream)
Prints value to ostream. Mostly used for debug.
Decimal operator/(const T &x, const Decimal &d)
Returns a new instance of Decimal class that represents a value that is a result of division of the s...
Definition: decimal.h:563
TypeCode
Represents the type of an object.
Definition: type_code.h:19
@ Decimal
A simple type representing values ranging from 1.0 x 10 -28 to approximately 7.9 x 10 28 with 28-29 s...
MidpointRounding
Specifies the behavior of rounding functions.
Definition: midpoint_rounding.h:10
Decimal operator*(const T &x, const Decimal &d)
Returns a new instance of Decimal class that represents a value that is a result of multiplication of...
Definition: decimal.h:556
auto operator-(DayOfWeek a, DayOfWeek b)
Calculates the number of days between two days of week.
Definition: day_of_week.h:25
Template predicate that checks if boxing of the specified type is supported.
Definition: boxable_traits.h:16
Wrapper for a pointer to an instance of TypeInfo class. This type should be allocated on stack and pa...
Definition: type_info.h:72