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
 The representation type.
 

Public Member Functions

template<typename T , typename cuda::std::enable_if_t< cuda::std::is_floating_point< T >() &&is_supported_representation_type< Rep >()> * = nullptr>
CUDF_HOST_DEVICE 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>
CUDF_HOST_DEVICE fixed_point (T const &value, scale_type const &scale)
 Constructor that will perform shifting to store value appropriately (from integral types) More...
 
CUDF_HOST_DEVICE 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>
CUDF_HOST_DEVICE fixed_point (T const &value)
 "Scale-less" constructor that constructs fixed_point number with a specified value and scale of zero More...
 
CUDF_HOST_DEVICE 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_v< U >> * = 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_v< U >> * = nullptr>
constexpr operator U () const
 Explicit conversion operator for casting to integral types. More...
 
CUDF_HOST_DEVICE operator scaled_integer< Rep > () const
 Converts the fixed_point number to a scaled_integer More...
 
CUDF_HOST_DEVICE rep value () const
 Method that returns the underlying value of the fixed_point number. More...
 
CUDF_HOST_DEVICE scale_type scale () const
 Method that returns the scale of the fixed_point number. More...
 
constexpr CUDF_HOST_DEVICE operator bool () const
 Explicit conversion operator to bool More...
 
template<typename Rep1 , Radix Rad1>
CUDF_HOST_DEVICE fixed_point< Rep1, Rad1 > & operator+= (fixed_point< Rep1, Rad1 > const &rhs)
 operator += More...
 
template<typename Rep1 , Radix Rad1>
CUDF_HOST_DEVICE fixed_point< Rep1, Rad1 > & operator*= (fixed_point< Rep1, Rad1 > const &rhs)
 operator *= More...
 
template<typename Rep1 , Radix Rad1>
CUDF_HOST_DEVICE fixed_point< Rep1, Rad1 > & operator-= (fixed_point< Rep1, Rad1 > const &rhs)
 operator -= More...
 
template<typename Rep1 , Radix Rad1>
CUDF_HOST_DEVICE fixed_point< Rep1, Rad1 > & operator/= (fixed_point< Rep1, Rad1 > const &rhs)
 operator /= More...
 
CUDF_HOST_DEVICE fixed_point< Rep, Rad > & operator++ ()
 operator ++ (post-increment) More...
 
CUDF_HOST_DEVICE 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>
CUDF_HOST_DEVICE 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>
CUDF_HOST_DEVICE 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>
CUDF_HOST_DEVICE 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>
CUDF_HOST_DEVICE 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>
CUDF_HOST_DEVICE friend fixed_point< Rep1, Rad1 > operator% (fixed_point< Rep1, Rad1 > const &lhs, fixed_point< Rep1, Rad1 > const &rhs)
 operator % (for computing the modulo operation of two fixed_point numbers) More...
 
template<typename Rep1 , Radix Rad1>
CUDF_HOST_DEVICE 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>
CUDF_HOST_DEVICE 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>
CUDF_HOST_DEVICE 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>
CUDF_HOST_DEVICE 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>
CUDF_HOST_DEVICE 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>
CUDF_HOST_DEVICE 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 212 of file fixed_point.hpp.

Constructor & Destructor Documentation

◆ fixed_point() [1/4]

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>
CUDF_HOST_DEVICE 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 230 of file fixed_point.hpp.

◆ fixed_point() [2/4]

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>
CUDF_HOST_DEVICE 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 246 of file fixed_point.hpp.

◆ fixed_point() [3/4]

template<typename Rep , Radix Rad>
CUDF_HOST_DEVICE 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 258 of file fixed_point.hpp.

◆ fixed_point() [4/4]

template<typename Rep , Radix Rad>
template<typename T , typename cuda::std::enable_if_t< is_supported_construction_value_type< T >()> * = nullptr>
CUDF_HOST_DEVICE numeric::fixed_point< Rep, Rad >::fixed_point ( T const &  value)
inline

"Scale-less" constructor that constructs fixed_point number with a specified value and scale of zero

Template Parameters
TThe value type being constructing from
Parameters
valueThe value that will be constructed from

Definition at line 272 of file fixed_point.hpp.

Member Function Documentation

◆ operator bool()

template<typename Rep , Radix Rad>
constexpr CUDF_HOST_DEVICE 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 341 of file fixed_point.hpp.

◆ operator scaled_integer< Rep >()

template<typename Rep , Radix Rad>
CUDF_HOST_DEVICE numeric::fixed_point< Rep, Rad >::operator scaled_integer< Rep > ( ) const
inline

Converts the fixed_point number to a scaled_integer

Returns
The scaled_integer representation of the fixed_point number

Definition at line 317 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_v< U >> * = 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 291 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_v< U >> * = 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 303 of file fixed_point.hpp.

◆ operator*=()

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

operator *=

Template Parameters
Rep1Representation type of the operand rhs
Rad1Radix (base) type of the operand rhs
Parameters
rhsThe number being multiplied to this
Returns
The product

Definition at line 370 of file fixed_point.hpp.

◆ operator++()

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

operator ++ (post-increment)

Returns
The incremented result

Definition at line 411 of file fixed_point.hpp.

◆ operator+=()

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

operator +=

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

Definition at line 355 of file fixed_point.hpp.

◆ operator-=()

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

operator -=

Template Parameters
Rep1Representation type of the operand rhs
Rad1Radix (base) type of the operand rhs
Parameters
rhsThe number being subtracted from this
Returns
The difference

Definition at line 385 of file fixed_point.hpp.

◆ operator/=()

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

operator /=

Template Parameters
Rep1Representation type of the operand rhs
Rad1Radix (base) type of the operand rhs
Parameters
rhsThe number being divided from this
Returns
The quotient

Definition at line 400 of file fixed_point.hpp.

◆ rescaled()

template<typename Rep , Radix Rad>
CUDF_HOST_DEVICE 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 609 of file fixed_point.hpp.

◆ scale()

template<typename Rep , Radix Rad>
CUDF_HOST_DEVICE 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 334 of file fixed_point.hpp.

◆ value()

template<typename Rep , Radix Rad>
CUDF_HOST_DEVICE 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 327 of file fixed_point.hpp.

Friends And Related Function Documentation

◆ operator!=

template<typename Rep , Radix Rad>
template<typename Rep1 , Radix Rad1>
CUDF_HOST_DEVICE 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, the number with the larger _scale is shifted to the smaller _scale, and then the _values are compared.

Template Parameters
Rep1Representation type of the operand lhs and rhs
Rad1Radix (base) type of the operand lhs and rhs
Parameters
lhsThe left hand side operand
rhsThe right hand side operand
Returns
true if lhs and rhs are not equal, false if not

Definition at line 777 of file fixed_point.hpp.

◆ operator%

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

operator % (for computing the modulo operation of two fixed_point numbers)

If _scales are equal, the modulus is computed directly. If _scales are not equal, the number with larger _scale is shifted to the smaller _scale, and then the modulus is computed.

Template Parameters
Rep1Representation type of the operand lhs and rhs
Rad1Radix (base) type of the operand lhs and rhs
Parameters
lhsThe left hand side operand
rhsThe right hand side operand
Returns
The resulting fixed_point number

Definition at line 822 of file fixed_point.hpp.

◆ operator*

template<typename Rep , Radix Rad>
template<typename Rep1 , Radix Rad1>
CUDF_HOST_DEVICE 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 the operand lhs and rhs
Rad1Radix (base) type of the operand lhs and rhs
Parameters
lhsThe left hand side operand
rhsThe right hand side operand
Returns
The resulting fixed_point product

Definition at line 738 of file fixed_point.hpp.

◆ operator+

template<typename Rep , Radix Rad>
template<typename Rep1 , Radix Rad1>
CUDF_HOST_DEVICE 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, the number with the larger _scale is shifted to the smaller _scale, and then the _values are added.

Template Parameters
Rep1Representation type of the operand lhs and rhs
Rad1Radix (base) type of the operand lhs and rhs
Parameters
lhsThe left hand side operand
rhsThe right hand side operand
Returns
The resulting fixed_point sum

Definition at line 702 of file fixed_point.hpp.

◆ operator-

template<typename Rep , Radix Rad>
template<typename Rep1 , Radix Rad1>
CUDF_HOST_DEVICE 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, the number with the larger _scale is shifted to the smaller _scale, and then the _values are subtracted.

Template Parameters
Rep1Representation type of the operand lhs and rhs
Rad1Radix (base) type of the operand lhs and rhs
Parameters
lhsThe left hand side operand
rhsThe right hand side operand
Returns
The resulting fixed_point difference

Definition at line 720 of file fixed_point.hpp.

◆ operator/

template<typename Rep , Radix Rad>
template<typename Rep1 , Radix Rad1>
CUDF_HOST_DEVICE 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 the operand lhs and rhs
Rad1Radix (base) type of the operand lhs and rhs
Parameters
lhsThe left hand side operand
rhsThe right hand side operand
Returns
The resulting fixed_point quotient

Definition at line 753 of file fixed_point.hpp.

◆ operator<

template<typename Rep , Radix Rad>
template<typename Rep1 , Radix Rad1>
CUDF_HOST_DEVICE 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, the number with the larger _scale is shifted to the smaller _scale, and then the _values are compared.

Template Parameters
Rep1Representation type of the operand lhs and rhs
Rad1Radix (base) type of the operand lhs and rhs
Parameters
lhsThe left hand side operand
rhsThe right hand side operand
Returns
true if lhs less than rhs, false if not

Definition at line 804 of file fixed_point.hpp.

◆ operator<=

template<typename Rep , Radix Rad>
template<typename Rep1 , Radix Rad1>
CUDF_HOST_DEVICE 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, the number with the larger _scale is shifted to the smaller _scale, and then the _values are compared.

Template Parameters
Rep1Representation type of the operand lhs and rhs
Rad1Radix (base) type of the operand lhs and rhs
Parameters
lhsThe left hand side operand
rhsThe right hand side operand
Returns
true if lhs less than or equal to rhs, false if not

Definition at line 786 of file fixed_point.hpp.

◆ operator==

template<typename Rep , Radix Rad>
template<typename Rep1 , Radix Rad1>
CUDF_HOST_DEVICE 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, the number with the larger _scale is shifted to the smaller _scale, and then the _values are compared.

Template Parameters
Rep1Representation type of the operand lhs and rhs
Rad1Radix (base) type of the operand lhs and rhs
Parameters
lhsThe left hand side operand
rhsThe right hand side operand
Returns
true if lhs and rhs are equal, false if not

Definition at line 768 of file fixed_point.hpp.

◆ operator>

template<typename Rep , Radix Rad>
template<typename Rep1 , Radix Rad1>
CUDF_HOST_DEVICE 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, the number with the larger _scale is shifted to the smaller _scale, and then the _values are compared.

Template Parameters
Rep1Representation type of the operand lhs and rhs
Rad1Radix (base) type of the operand lhs and rhs
Parameters
lhsThe left hand side operand
rhsThe right hand side operand
Returns
true if lhs greater than rhs, false if not

Definition at line 813 of file fixed_point.hpp.

◆ operator>=

template<typename Rep , Radix Rad>
template<typename Rep1 , Radix Rad1>
CUDF_HOST_DEVICE 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, the number with the larger _scale is shifted to the smaller _scale, and then the _values are compared.

Template Parameters
Rep1Representation type of the operand lhs and rhs
Rad1Radix (base) type of the operand lhs and rhs
Parameters
lhsThe left hand side operand
rhsThe right hand side operand
Returns
true if lhs greater than or equal to rhs, false if not

Definition at line 795 of file fixed_point.hpp.


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