Public Types | Public Member Functions | Friends | List of all members
numeric::fixed_point< Rep, Rad > Class Template Reference

A type for representing a number with a fixed amount of precision. More...

#include <fixed_point.hpp>

Public Types

using rep = Rep
 

Public Member Functions

template<typename T , typename cuda::std::enable_if_t< cuda::std::is_floating_point< T >() &&is_supported_representation_type< Rep >()> * = nullptr>
CUDA_HOST_DEVICE_CALLABLE fixed_point (T const &value, scale_type const &scale)
 Constructor that will perform shifting to store value appropriately (from floating point types) More...
 
template<typename T , typename cuda::std::enable_if_t< cuda::std::is_integral< T >() &&is_supported_representation_type< Rep >()> * = nullptr>
CUDA_HOST_DEVICE_CALLABLE fixed_point (T const &value, scale_type const &scale)
 Constructor that will perform shifting to store value appropriately (from integral types) More...
 
CUDA_HOST_DEVICE_CALLABLE fixed_point (scaled_integer< Rep > s)
 Constructor that will not perform shifting (assumes value already shifted) More...
 
template<typename T , typename cuda::std::enable_if_t< is_supported_construction_value_type< T >()> * = nullptr>
CUDA_HOST_DEVICE_CALLABLE fixed_point (T const &value)
 "Scale-less" constructor that constructs fixed_point number with a specified value and scale of zero
 
CUDA_HOST_DEVICE_CALLABLE fixed_point ()
 Default constructor that constructs fixed_point number with a value and scale of zero.
 
template<typename U , typename cuda::std::enable_if_t< cuda::std::is_floating_point< U >::value > * = nullptr>
constexpr operator U () const
 Explicit conversion operator for casting to floating point types. More...
 
template<typename U , typename cuda::std::enable_if_t< cuda::std::is_integral< U >::value > * = nullptr>
constexpr operator U () const
 Explicit conversion operator for casting to integral types. More...
 
CUDA_HOST_DEVICE_CALLABLE operator scaled_integer< Rep > () const
 
CUDA_HOST_DEVICE_CALLABLE rep value () const
 Method that returns the underlying value of the fixed_point number. More...
 
CUDA_HOST_DEVICE_CALLABLE scale_type scale () const
 Method that returns the scale of the fixed_point number. More...
 
constexpr CUDA_HOST_DEVICE_CALLABLE operator bool () const
 Explicit conversion operator to bool More...
 
template<typename Rep1 , Radix Rad1>
CUDA_HOST_DEVICE_CALLABLE fixed_point< Rep1, Rad1 > & operator+= (fixed_point< Rep1, Rad1 > const &rhs)
 operator += More...
 
template<typename Rep1 , Radix Rad1>
CUDA_HOST_DEVICE_CALLABLE fixed_point< Rep1, Rad1 > & operator*= (fixed_point< Rep1, Rad1 > const &rhs)
 operator *= More...
 
template<typename Rep1 , Radix Rad1>
CUDA_HOST_DEVICE_CALLABLE fixed_point< Rep1, Rad1 > & operator-= (fixed_point< Rep1, Rad1 > const &rhs)
 operator -= More...
 
template<typename Rep1 , Radix Rad1>
CUDA_HOST_DEVICE_CALLABLE fixed_point< Rep1, Rad1 > & operator/= (fixed_point< Rep1, Rad1 > const &rhs)
 operator /= More...
 
CUDA_HOST_DEVICE_CALLABLE fixed_point< Rep, Rad > & operator++ ()
 operator ++ (post-increment) More...
 
CUDA_HOST_DEVICE_CALLABLE fixed_point< Rep, Rad > rescaled (scale_type scale) const
 Method for creating a fixed_point number with a new scale More...
 
 operator std::string () const
 Returns a string representation of the fixed_point value.
 

Friends

template<typename Rep1 , Radix Rad1>
CUDA_HOST_DEVICE_CALLABLE friend fixed_point< Rep1, Rad1 > operator+ (fixed_point< Rep1, Rad1 > const &lhs, fixed_point< Rep1, Rad1 > const &rhs)
 operator + (for adding two fixed_point numbers) More...
 
template<typename Rep1 , Radix Rad1>
CUDA_HOST_DEVICE_CALLABLE friend fixed_point< Rep1, Rad1 > operator- (fixed_point< Rep1, Rad1 > const &lhs, fixed_point< Rep1, Rad1 > const &rhs)
 operator - (for subtracting two fixed_point numbers) More...
 
template<typename Rep1 , Radix Rad1>
CUDA_HOST_DEVICE_CALLABLE friend fixed_point< Rep1, Rad1 > operator* (fixed_point< Rep1, Rad1 > const &lhs, fixed_point< Rep1, Rad1 > const &rhs)
 operator * (for multiplying two fixed_point numbers) More...
 
template<typename Rep1 , Radix Rad1>
CUDA_HOST_DEVICE_CALLABLE friend fixed_point< Rep1, Rad1 > operator/ (fixed_point< Rep1, Rad1 > const &lhs, fixed_point< Rep1, Rad1 > const &rhs)
 operator / (for dividing two fixed_point numbers) More...
 
template<typename Rep1 , Radix Rad1>
CUDA_HOST_DEVICE_CALLABLE friend bool operator== (fixed_point< Rep1, Rad1 > const &lhs, fixed_point< Rep1, Rad1 > const &rhs)
 operator == (for comparing two fixed_point numbers) More...
 
template<typename Rep1 , Radix Rad1>
CUDA_HOST_DEVICE_CALLABLE friend bool operator!= (fixed_point< Rep1, Rad1 > const &lhs, fixed_point< Rep1, Rad1 > const &rhs)
 operator != (for comparing two fixed_point numbers) More...
 
template<typename Rep1 , Radix Rad1>
CUDA_HOST_DEVICE_CALLABLE friend bool operator<= (fixed_point< Rep1, Rad1 > const &lhs, fixed_point< Rep1, Rad1 > const &rhs)
 operator <= (for comparing two fixed_point numbers) More...
 
template<typename Rep1 , Radix Rad1>
CUDA_HOST_DEVICE_CALLABLE friend bool operator>= (fixed_point< Rep1, Rad1 > const &lhs, fixed_point< Rep1, Rad1 > const &rhs)
 operator >= (for comparing two fixed_point numbers) More...
 
template<typename Rep1 , Radix Rad1>
CUDA_HOST_DEVICE_CALLABLE friend bool operator< (fixed_point< Rep1, Rad1 > const &lhs, fixed_point< Rep1, Rad1 > const &rhs)
 operator < (for comparing two fixed_point numbers) More...
 
template<typename Rep1 , Radix Rad1>
CUDA_HOST_DEVICE_CALLABLE friend bool operator> (fixed_point< Rep1, Rad1 > const &lhs, fixed_point< Rep1, Rad1 > const &rhs)
 operator > (for comparing two fixed_point numbers) More...
 

Detailed Description

template<typename Rep, Radix Rad>
class numeric::fixed_point< Rep, Rad >

A type for representing a number with a fixed amount of precision.

Currently, only binary and decimal fixed_point numbers are supported. Binary operations can only be performed with other fixed_point numbers

Template Parameters
RepThe representation type (either int32_t or int64_t)
RadThe radix/base (either Radix::BASE_2 or Radix::BASE_10)

Definition at line 213 of file fixed_point.hpp.

Constructor & Destructor Documentation

◆ fixed_point() [1/3]

template<typename Rep , Radix Rad>
template<typename T , typename cuda::std::enable_if_t< cuda::std::is_floating_point< T >() &&is_supported_representation_type< Rep >()> * = nullptr>
CUDA_HOST_DEVICE_CALLABLE numeric::fixed_point< Rep, Rad >::fixed_point ( T const &  value,
scale_type const &  scale 
)
inlineexplicit

Constructor that will perform shifting to store value appropriately (from floating point types)

Template Parameters
TThe floating point type that you are constructing from
Parameters
valueThe value that will be constructed from
scaleThe exponent that is applied to Rad to perform shifting

Definition at line 231 of file fixed_point.hpp.

◆ fixed_point() [2/3]

template<typename Rep , Radix Rad>
template<typename T , typename cuda::std::enable_if_t< cuda::std::is_integral< T >() &&is_supported_representation_type< Rep >()> * = nullptr>
CUDA_HOST_DEVICE_CALLABLE numeric::fixed_point< Rep, Rad >::fixed_point ( T const &  value,
scale_type const &  scale 
)
inlineexplicit

Constructor that will perform shifting to store value appropriately (from integral types)

Template Parameters
TThe integral type that you are constructing from
Parameters
valueThe value that will be constructed from
scaleThe exponent that is applied to Rad to perform shifting

Definition at line 247 of file fixed_point.hpp.

◆ fixed_point() [3/3]

template<typename Rep , Radix Rad>
CUDA_HOST_DEVICE_CALLABLE numeric::fixed_point< Rep, Rad >::fixed_point ( scaled_integer< Rep >  s)
inlineexplicit

Constructor that will not perform shifting (assumes value already shifted)

Parameters
sscaled_integer that contains scale and already shifted value

Definition at line 260 of file fixed_point.hpp.

Member Function Documentation

◆ operator bool()

template<typename Rep , Radix Rad>
constexpr CUDA_HOST_DEVICE_CALLABLE numeric::fixed_point< Rep, Rad >::operator bool ( ) const
inlineexplicitconstexpr

Explicit conversion operator to bool

Returns
The fixed_point value as a boolean (zero is false, nonzero is true)

Definition at line 332 of file fixed_point.hpp.

◆ operator U() [1/2]

template<typename Rep , Radix Rad>
template<typename U , typename cuda::std::enable_if_t< cuda::std::is_floating_point< U >::value > * = nullptr>
constexpr numeric::fixed_point< Rep, Rad >::operator U ( ) const
inlineexplicitconstexpr

Explicit conversion operator for casting to floating point types.

Template Parameters
UThe floating point type that is being explicitly converted to
Returns
The fixed_point number in base 10 (aka human readable format)

Definition at line 288 of file fixed_point.hpp.

◆ operator U() [2/2]

template<typename Rep , Radix Rad>
template<typename U , typename cuda::std::enable_if_t< cuda::std::is_integral< U >::value > * = nullptr>
constexpr numeric::fixed_point< Rep, Rad >::operator U ( ) const
inlineexplicitconstexpr

Explicit conversion operator for casting to integral types.

Template Parameters
UThe integral type that is being explicitly converted to
Returns
The fixed_point number in base 10 (aka human readable format)

Definition at line 301 of file fixed_point.hpp.

◆ operator*=()

template<typename Rep , Radix Rad>
template<typename Rep1 , Radix Rad1>
CUDA_HOST_DEVICE_CALLABLE fixed_point<Rep1, Rad1>& numeric::fixed_point< Rep, Rad >::operator*= ( fixed_point< Rep1, Rad1 > const &  rhs)
inline

operator *=

Template Parameters
Rep1Representation type of number being added to this
Rad1Radix (base) type of number being added to this
Returns
The product

Definition at line 359 of file fixed_point.hpp.

◆ operator++()

template<typename Rep , Radix Rad>
CUDA_HOST_DEVICE_CALLABLE fixed_point<Rep, Rad>& numeric::fixed_point< Rep, Rad >::operator++ ( )
inline

operator ++ (post-increment)

Returns
The incremented result

Definition at line 399 of file fixed_point.hpp.

◆ operator+=()

template<typename Rep , Radix Rad>
template<typename Rep1 , Radix Rad1>
CUDA_HOST_DEVICE_CALLABLE fixed_point<Rep1, Rad1>& numeric::fixed_point< Rep, Rad >::operator+= ( fixed_point< Rep1, Rad1 > const &  rhs)
inline

operator +=

Template Parameters
Rep1Representation type of number being added to this
Rad1Radix (base) type of number being added to this
Returns
The sum

Definition at line 345 of file fixed_point.hpp.

◆ operator-=()

template<typename Rep , Radix Rad>
template<typename Rep1 , Radix Rad1>
CUDA_HOST_DEVICE_CALLABLE fixed_point<Rep1, Rad1>& numeric::fixed_point< Rep, Rad >::operator-= ( fixed_point< Rep1, Rad1 > const &  rhs)
inline

operator -=

Template Parameters
Rep1Representation type of number being added to this
Rad1Radix (base) type of number being added to this
Returns
The difference

Definition at line 373 of file fixed_point.hpp.

◆ operator/=()

template<typename Rep , Radix Rad>
template<typename Rep1 , Radix Rad1>
CUDA_HOST_DEVICE_CALLABLE fixed_point<Rep1, Rad1>& numeric::fixed_point< Rep, Rad >::operator/= ( fixed_point< Rep1, Rad1 > const &  rhs)
inline

operator /=

Template Parameters
Rep1Representation type of number being added to this
Rad1Radix (base) type of number being added to this
Returns
The quotient

Definition at line 387 of file fixed_point.hpp.

◆ rescaled()

template<typename Rep , Radix Rad>
CUDA_HOST_DEVICE_CALLABLE fixed_point<Rep, Rad> numeric::fixed_point< Rep, Rad >::rescaled ( scale_type  scale) const
inline

Method for creating a fixed_point number with a new scale

The fixed_point number returned will have the same value, underlying representation and radix as this, the only thing changed is the scale

Parameters
scaleThe scale of the returned fixed_point number
Returns
fixed_point number with a new scale

Definition at line 560 of file fixed_point.hpp.

◆ scale()

template<typename Rep , Radix Rad>
CUDA_HOST_DEVICE_CALLABLE scale_type numeric::fixed_point< Rep, Rad >::scale ( ) const
inline

Method that returns the scale of the fixed_point number.

Returns
The scale of the fixed_point number

Definition at line 325 of file fixed_point.hpp.

◆ value()

template<typename Rep , Radix Rad>
CUDA_HOST_DEVICE_CALLABLE rep numeric::fixed_point< Rep, Rad >::value ( ) const
inline

Method that returns the underlying value of the fixed_point number.

Returns
The underlying value of the fixed_point number

Definition at line 318 of file fixed_point.hpp.

Friends And Related Function Documentation

◆ operator!=

template<typename Rep , Radix Rad>
template<typename Rep1 , Radix Rad1>
CUDA_HOST_DEVICE_CALLABLE friend bool operator!= ( fixed_point< Rep1, Rad1 > const &  lhs,
fixed_point< Rep1, Rad1 > const &  rhs 
)
friend

operator != (for comparing two fixed_point numbers)

If _scales are equal, _values are compared
If _scales are not equal, number with smaller _scale is shifted to the greater _scale, and then _values are compared

Template Parameters
Rep1Representation type of number being added to this
Rad1Radix (base) type of number being added to this
Returns
true if lhs and rhs are not equal, false if not

Definition at line 731 of file fixed_point.hpp.

◆ operator*

template<typename Rep , Radix Rad>
template<typename Rep1 , Radix Rad1>
CUDA_HOST_DEVICE_CALLABLE friend fixed_point<Rep1, Rad1> operator* ( fixed_point< Rep1, Rad1 > const &  lhs,
fixed_point< Rep1, Rad1 > const &  rhs 
)
friend

operator * (for multiplying two fixed_point numbers)

_scales are added and _values are multiplied

Template Parameters
Rep1Representation type of number being added to this
Rad1Radix (base) type of number being added to this
Returns
The resulting fixed_point product

Definition at line 692 of file fixed_point.hpp.

◆ operator+

template<typename Rep , Radix Rad>
template<typename Rep1 , Radix Rad1>
CUDA_HOST_DEVICE_CALLABLE friend fixed_point<Rep1, Rad1> operator+ ( fixed_point< Rep1, Rad1 > const &  lhs,
fixed_point< Rep1, Rad1 > const &  rhs 
)
friend

operator + (for adding two fixed_point numbers)

If _scales are equal, _values are added
If _scales are not equal, number with smaller _scale is shifted to the greater _scale, and then _values are added

Template Parameters
Rep1Representation type of number being added to this
Rad1Radix (base) type of number being added to this
Returns
The resulting fixed_point sum

Definition at line 656 of file fixed_point.hpp.

◆ operator-

template<typename Rep , Radix Rad>
template<typename Rep1 , Radix Rad1>
CUDA_HOST_DEVICE_CALLABLE friend fixed_point<Rep1, Rad1> operator- ( fixed_point< Rep1, Rad1 > const &  lhs,
fixed_point< Rep1, Rad1 > const &  rhs 
)
friend

operator - (for subtracting two fixed_point numbers)

If _scales are equal, _values are subtracted
If _scales are not equal, number with smaller _scale is shifted to the greater _scale, and then _values are subtracted

Template Parameters
Rep1Representation type of number being added to this
Rad1Radix (base) type of number being added to this
Returns
The resulting fixed_point difference

Definition at line 674 of file fixed_point.hpp.

◆ operator/

template<typename Rep , Radix Rad>
template<typename Rep1 , Radix Rad1>
CUDA_HOST_DEVICE_CALLABLE friend fixed_point<Rep1, Rad1> operator/ ( fixed_point< Rep1, Rad1 > const &  lhs,
fixed_point< Rep1, Rad1 > const &  rhs 
)
friend

operator / (for dividing two fixed_point numbers)

_scales are subtracted and _values are divided

Template Parameters
Rep1Representation type of number being added to this
Rad1Radix (base) type of number being added to this
Returns
The resulting fixed_point quotient

Definition at line 707 of file fixed_point.hpp.

◆ operator<

template<typename Rep , Radix Rad>
template<typename Rep1 , Radix Rad1>
CUDA_HOST_DEVICE_CALLABLE friend bool operator< ( fixed_point< Rep1, Rad1 > const &  lhs,
fixed_point< Rep1, Rad1 > const &  rhs 
)
friend

operator < (for comparing two fixed_point numbers)

If _scales are equal, _values are compared
If _scales are not equal, number with smaller _scale is shifted to the greater _scale, and then _values are compared

Template Parameters
Rep1Representation type of number being added to this
Rad1Radix (base) type of number being added to this
Returns
true if lhs less than rhs, false if not

Definition at line 758 of file fixed_point.hpp.

◆ operator<=

template<typename Rep , Radix Rad>
template<typename Rep1 , Radix Rad1>
CUDA_HOST_DEVICE_CALLABLE friend bool operator<= ( fixed_point< Rep1, Rad1 > const &  lhs,
fixed_point< Rep1, Rad1 > const &  rhs 
)
friend

operator <= (for comparing two fixed_point numbers)

If _scales are equal, _values are compared
If _scales are not equal, number with smaller _scale is shifted to the greater _scale, and then _values are compared

Template Parameters
Rep1Representation type of number being added to this
Rad1Radix (base) type of number being added to this
Returns
true if lhs less than or equal to rhs, false if not

Definition at line 740 of file fixed_point.hpp.

◆ operator==

template<typename Rep , Radix Rad>
template<typename Rep1 , Radix Rad1>
CUDA_HOST_DEVICE_CALLABLE friend bool operator== ( fixed_point< Rep1, Rad1 > const &  lhs,
fixed_point< Rep1, Rad1 > const &  rhs 
)
friend

operator == (for comparing two fixed_point numbers)

If _scales are equal, _values are compared
If _scales are not equal, number with smaller _scale is shifted to the greater _scale, and then _values are compared

Template Parameters
Rep1Representation type of number being added to this
Rad1Radix (base) type of number being added to this
Returns
true if lhs and rhs are equal, false if not

Definition at line 722 of file fixed_point.hpp.

◆ operator>

template<typename Rep , Radix Rad>
template<typename Rep1 , Radix Rad1>
CUDA_HOST_DEVICE_CALLABLE friend bool operator> ( fixed_point< Rep1, Rad1 > const &  lhs,
fixed_point< Rep1, Rad1 > const &  rhs 
)
friend

operator > (for comparing two fixed_point numbers)

If _scales are equal, _values are compared
If _scales are not equal, number with smaller _scale is shifted to the greater _scale, and then _values are compared

Template Parameters
Rep1Representation type of number being added to this
Rad1Radix (base) type of number being added to this
Returns
true if lhs greater than rhs, false if not

Definition at line 767 of file fixed_point.hpp.

◆ operator>=

template<typename Rep , Radix Rad>
template<typename Rep1 , Radix Rad1>
CUDA_HOST_DEVICE_CALLABLE friend bool operator>= ( fixed_point< Rep1, Rad1 > const &  lhs,
fixed_point< Rep1, Rad1 > const &  rhs 
)
friend

operator >= (for comparing two fixed_point numbers)

If _scales are equal, _values are compared
If _scales are not equal, number with smaller _scale is shifted to the greater _scale, and then _values are compared

Template Parameters
Rep1Representation type of number being added to this
Rad1Radix (base) type of number being added to this
Returns
true if lhs greater than or equal to rhs, false if not

Definition at line 749 of file fixed_point.hpp.


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