Hyper API for C++
0.0.16638
Hyper client library for C++ applications
|
A fixed-point numeric data value with scale
fraction digits and precision
digits overall.
More...
#include <Numeric.hpp>
Public Types | |
using | data_t = typename std::conditional< precision<=18, int64_t, hyper_data128_t >::type |
Public Member Functions | |
Numeric () noexcept | |
Default constructor. | |
Numeric (short value) | |
Creates a numeric value from an integer. More... | |
Numeric (unsigned short value) | |
Creates a numeric value from an integer. More... | |
Numeric (int value) | |
Creates a numeric value from an integer. More... | |
Numeric (unsigned value) | |
Creates a numeric value from an integer. More... | |
Numeric (long value) | |
Creates a numeric value from an integer. More... | |
Numeric (unsigned long value) | |
Creates a numeric value from an integer. More... | |
Numeric (long long value) | |
Creates a numeric value from an integer. More... | |
Numeric (unsigned long long value) | |
Creates a numeric value from an integer. More... | |
Numeric (float value) | |
Creates a numeric value from a double; may lose accuracy. More... | |
Numeric (double value) | |
Creates a numeric value from a double; may lose accuracy. More... | |
Numeric (long double value) | |
Creates a numeric value from a double; may lose accuracy. More... | |
template<unsigned otherPrecision, unsigned otherScale> | |
Numeric (hyperapi::Numeric< otherPrecision, otherScale > other) | |
Creates a numeric value from another numeric value with different precision and scale. More... | |
Numeric (hyperapi::string_view value) | |
Creates a numeric value from a string representation. More... | |
std::string | stringValue () const |
Gets an exact string representation, which is round-trip compatible with the constructor, i.e., n == Numeric(n.stringValue()) | |
int64_t | intValue () const |
Gets an integer representation of this value; if the value has fraction digits, these will be truncated. More... | |
operator int64_t () const | |
Explicit conversion to int64_t. More... | |
double | doubleValue () const noexcept |
Gets a double representation of this value; may lose accuracy. | |
operator double () const noexcept | |
Explicit conversion to double. | |
std::string | toString () const |
Gets a string representation for debugging. More... | |
Static Public Attributes | |
static constexpr unsigned | precision = precision_value |
static constexpr unsigned | scale = scale_value |
Friends | |
bool | operator== (const Numeric &a, const Numeric &b) noexcept |
Equality operator. | |
bool | operator> (const Numeric &a, const Numeric &b) noexcept |
Greater operator. | |
bool | operator!= (const Numeric &a, const Numeric &b) noexcept |
Not equal operator. | |
bool | operator< (const Numeric &a, const Numeric &b) noexcept |
Less than operator. | |
bool | operator<= (const Numeric &a, const Numeric &b) noexcept |
Less than or equal operator. | |
bool | operator>= (const Numeric &a, const Numeric &b) noexcept |
Greater or equal operator. | |
std::ostream & | operator<< (std::ostream &os, const Numeric &obj) |
Stream output operator. | |
A fixed-point numeric data value with scale
fraction digits and precision
digits overall.
Definition at line 43 of file Numeric.hpp.
hyperapi::Numeric< precision_value, scale_value >::Numeric | ( | short | value | ) |
Creates a numeric value from an integer.
HyperException | if the value cannot be represented with the specified precision and scale. |
hyperapi::Numeric< precision_value, scale_value >::Numeric | ( | unsigned short | value | ) |
Creates a numeric value from an integer.
HyperException | if the value cannot be represented with the specified precision and scale. |
hyperapi::Numeric< precision_value, scale_value >::Numeric | ( | int | value | ) |
Creates a numeric value from an integer.
HyperException | if the value cannot be represented with the specified precision and scale. |
hyperapi::Numeric< precision_value, scale_value >::Numeric | ( | unsigned | value | ) |
Creates a numeric value from an integer.
HyperException | if the value cannot be represented with the specified precision and scale. |
hyperapi::Numeric< precision_value, scale_value >::Numeric | ( | long | value | ) |
Creates a numeric value from an integer.
HyperException | if the value cannot be represented with the specified precision and scale. |
hyperapi::Numeric< precision_value, scale_value >::Numeric | ( | unsigned long | value | ) |
Creates a numeric value from an integer.
HyperException | if the value cannot be represented with the specified precision and scale. |
hyperapi::Numeric< precision_value, scale_value >::Numeric | ( | long long | value | ) |
Creates a numeric value from an integer.
HyperException | if the value cannot be represented with the specified precision and scale. |
hyperapi::Numeric< precision_value, scale_value >::Numeric | ( | unsigned long long | value | ) |
Creates a numeric value from an integer.
HyperException | if the value cannot be represented with the specified precision and scale. |
hyperapi::Numeric< precision_value, scale_value >::Numeric | ( | float | value | ) |
Creates a numeric value from a double; may lose accuracy.
HyperException | if the value cannot be represented with the specified precision and scale. |
hyperapi::Numeric< precision_value, scale_value >::Numeric | ( | double | value | ) |
Creates a numeric value from a double; may lose accuracy.
HyperException | if the value cannot be represented with the specified precision and scale. |
hyperapi::Numeric< precision_value, scale_value >::Numeric | ( | long double | value | ) |
Creates a numeric value from a double; may lose accuracy.
HyperException | if the value cannot be represented with the specified precision and scale. |
|
explicit |
Creates a numeric value from another numeric value with different precision and scale.
HyperException | if the value cannot be represented with the specified precision and scale. |
|
explicit |
Creates a numeric value from a string representation.
HyperException | if value is not a valid numeric representation or overflows. |
int64_t hyperapi::Numeric< precision_value, scale_value >::intValue | ( | ) | const |
Gets an integer representation of this value; if the value has fraction digits, these will be truncated.
HyperException | if the value cannot be represented in 64-bit. |
|
inline |
Explicit conversion to int64_t.
HyperException | if the value cannot be represented in 64-bit. |
Definition at line 140 of file Numeric.hpp.
std::string hyperapi::Numeric< precision_value, scale_value >::toString | ( | ) | const |
Gets a string representation for debugging.
Currently, the result is equivalent to calling stringValue(), but this is not guaranteed; it might change in future versions.