Hyper API for C++  0.0.16638
Hyper client library for C++ applications
hyperapi::Numeric< precision_value, scale_value > Class Template Referencefinal

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.
 

Detailed Description

template<unsigned precision_value, unsigned scale_value>
class hyperapi::Numeric< precision_value, scale_value >

A fixed-point numeric data value with scale fraction digits and precision digits overall.

Definition at line 43 of file Numeric.hpp.

Constructor & Destructor Documentation

◆ Numeric() [1/13]

template<unsigned precision_value, unsigned scale_value>
hyperapi::Numeric< precision_value, scale_value >::Numeric ( short  value)

Creates a numeric value from an integer.

Exceptions
HyperExceptionif the value cannot be represented with the specified precision and scale.

◆ Numeric() [2/13]

template<unsigned precision_value, unsigned scale_value>
hyperapi::Numeric< precision_value, scale_value >::Numeric ( unsigned short  value)

Creates a numeric value from an integer.

Exceptions
HyperExceptionif the value cannot be represented with the specified precision and scale.

◆ Numeric() [3/13]

template<unsigned precision_value, unsigned scale_value>
hyperapi::Numeric< precision_value, scale_value >::Numeric ( int  value)

Creates a numeric value from an integer.

Exceptions
HyperExceptionif the value cannot be represented with the specified precision and scale.

◆ Numeric() [4/13]

template<unsigned precision_value, unsigned scale_value>
hyperapi::Numeric< precision_value, scale_value >::Numeric ( unsigned  value)

Creates a numeric value from an integer.

Exceptions
HyperExceptionif the value cannot be represented with the specified precision and scale.

◆ Numeric() [5/13]

template<unsigned precision_value, unsigned scale_value>
hyperapi::Numeric< precision_value, scale_value >::Numeric ( long  value)

Creates a numeric value from an integer.

Exceptions
HyperExceptionif the value cannot be represented with the specified precision and scale.

◆ Numeric() [6/13]

template<unsigned precision_value, unsigned scale_value>
hyperapi::Numeric< precision_value, scale_value >::Numeric ( unsigned long  value)

Creates a numeric value from an integer.

Exceptions
HyperExceptionif the value cannot be represented with the specified precision and scale.

◆ Numeric() [7/13]

template<unsigned precision_value, unsigned scale_value>
hyperapi::Numeric< precision_value, scale_value >::Numeric ( long long  value)

Creates a numeric value from an integer.

Exceptions
HyperExceptionif the value cannot be represented with the specified precision and scale.

◆ Numeric() [8/13]

template<unsigned precision_value, unsigned scale_value>
hyperapi::Numeric< precision_value, scale_value >::Numeric ( unsigned long long  value)

Creates a numeric value from an integer.

Exceptions
HyperExceptionif the value cannot be represented with the specified precision and scale.

◆ Numeric() [9/13]

template<unsigned precision_value, unsigned scale_value>
hyperapi::Numeric< precision_value, scale_value >::Numeric ( float  value)

Creates a numeric value from a double; may lose accuracy.

Exceptions
HyperExceptionif the value cannot be represented with the specified precision and scale.

◆ Numeric() [10/13]

template<unsigned precision_value, unsigned scale_value>
hyperapi::Numeric< precision_value, scale_value >::Numeric ( double  value)

Creates a numeric value from a double; may lose accuracy.

Exceptions
HyperExceptionif the value cannot be represented with the specified precision and scale.

◆ Numeric() [11/13]

template<unsigned precision_value, unsigned scale_value>
hyperapi::Numeric< precision_value, scale_value >::Numeric ( long double  value)

Creates a numeric value from a double; may lose accuracy.

Exceptions
HyperExceptionif the value cannot be represented with the specified precision and scale.

◆ Numeric() [12/13]

template<unsigned precision_value, unsigned scale_value>
template<unsigned otherPrecision, unsigned otherScale>
hyperapi::Numeric< precision_value, scale_value >::Numeric ( hyperapi::Numeric< otherPrecision, otherScale >  other)
explicit

Creates a numeric value from another numeric value with different precision and scale.

Exceptions
HyperExceptionif the value cannot be represented with the specified precision and scale.

◆ Numeric() [13/13]

template<unsigned precision_value, unsigned scale_value>
hyperapi::Numeric< precision_value, scale_value >::Numeric ( hyperapi::string_view  value)
explicit

Creates a numeric value from a string representation.

Exceptions
HyperExceptionif value is not a valid numeric representation or overflows.

Member Function Documentation

◆ intValue()

template<unsigned precision_value, unsigned scale_value>
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.

Exceptions
HyperExceptionif the value cannot be represented in 64-bit.

◆ operator int64_t()

template<unsigned precision_value, unsigned scale_value>
hyperapi::Numeric< precision_value, scale_value >::operator int64_t ( ) const
inline

Explicit conversion to int64_t.

Exceptions
HyperExceptionif the value cannot be represented in 64-bit.

Definition at line 140 of file Numeric.hpp.

◆ toString()

template<unsigned precision_value, unsigned scale_value>
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.


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