Hyper API for C++ 0.0.18825
Hyper client library for C++ applications
Loading...
Searching...
No Matches
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.
 
 Numeric (unsigned short value)
 Creates a numeric value from an integer.
 
 Numeric (int value)
 Creates a numeric value from an integer.
 
 Numeric (unsigned value)
 Creates a numeric value from an integer.
 
 Numeric (long value)
 Creates a numeric value from an integer.
 
 Numeric (unsigned long value)
 Creates a numeric value from an integer.
 
 Numeric (long long value)
 Creates a numeric value from an integer.
 
 Numeric (unsigned long long value)
 Creates a numeric value from an integer.
 
 Numeric (float value)
 Creates a numeric value from a double; may lose accuracy.
 
 Numeric (double value)
 Creates a numeric value from a double; may lose accuracy.
 
 Numeric (long double value)
 Creates a numeric value from a double; may lose accuracy.
 
template<unsigned otherPrecision, unsigned otherScale>
 Numeric (hyperapi::Numeric< otherPrecision, otherScale > other)
 Creates a numeric value from another numeric value with different precision and scale.
 
 Numeric (hyperapi::string_view value)
 Creates a numeric value from a string representation.
 
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.
 
 operator int64_t () const
 Explicit conversion to int64_t.
 
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.
 

Static Public Attributes

static constexpr unsigned precision = precision_value
 
static constexpr unsigned scale = scale_value
 

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 47 of file Numeric.hpp.

Member Typedef Documentation

◆ data_t

template<unsigned precision_value, unsigned scale_value>
using hyperapi::Numeric< precision_value, scale_value >::data_t = typename std::conditional<precision <= 18, int64_t, hyper_data128_t>::type

Definition at line 54 of file Numeric.hpp.

Constructor & Destructor Documentation

◆ Numeric() [1/14]

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

Default constructor.

Definition at line 59 of file Numeric.hpp.

◆ Numeric() [2/14]

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() [3/14]

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() [4/14]

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() [5/14]

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() [6/14]

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() [7/14]

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() [8/14]

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() [9/14]

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() [10/14]

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() [11/14]

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() [12/14]

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() [13/14]

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() [14/14]

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 double()

template<unsigned precision_value, unsigned scale_value>
hyperapi::Numeric< precision_value, scale_value >::operator double ( ) const
inlinenoexcept

Explicit conversion to double.

Definition at line 154 of file Numeric.hpp.

◆ 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 145 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.

Member Data Documentation

◆ precision

template<unsigned precision_value, unsigned scale_value>
constexpr unsigned hyperapi::Numeric< precision_value, scale_value >::precision = precision_value
staticconstexpr

Definition at line 49 of file Numeric.hpp.

◆ scale

template<unsigned precision_value, unsigned scale_value>
constexpr unsigned hyperapi::Numeric< precision_value, scale_value >::scale = scale_value
staticconstexpr

Definition at line 50 of file Numeric.hpp.


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