libcudf  24.04.00
Files | Classes | Typedefs | Enumerations | Functions
Fixed Point

Files

file  fixed_point.hpp
 Class definition for fixed point data type.
 
file  fixed_point.hpp
 Class definition for fixed point data type.
 

Classes

struct  numeric::scaled_integer< Rep, >
 Helper struct for constructing fixed_point when value is already shifted. More...
 
class  numeric::fixed_point< Rep, Rad >
 A type for representing a number with a fixed amount of precision. More...
 

Typedefs

using numeric::decimal32 = fixed_point< int32_t, Radix::BASE_10 >
 32-bit decimal fixed point
 
using numeric::decimal64 = fixed_point< int64_t, Radix::BASE_10 >
 64-bit decimal fixed point
 
using numeric::decimal128 = fixed_point< __int128_t, Radix::BASE_10 >
 128-bit decimal fixed point
 

Enumerations

enum  numeric::scale_type : int32_t
 The scale type for fixed_point.
 
enum class  numeric::Radix : int32_t { BASE_2 = 2 , BASE_10 = 10 }
 Scoped enumerator to use when constructing fixed_point More...
 

Functions

template<typename T >
constexpr auto numeric::is_supported_representation_type ()
 Returns true if the representation type is supported by fixed_point More...
 
template<typename T >
constexpr auto numeric::is_supported_construction_value_type ()
 Returns true if the value type is supported for constructing a fixed_point More...
 
template<typename Rep , typename T >
CUDF_HOST_DEVICE auto numeric::addition_overflow (T lhs, T rhs)
 Function for identifying integer overflow when adding. More...
 
template<typename Rep , typename T >
CUDF_HOST_DEVICE auto numeric::subtraction_overflow (T lhs, T rhs)
 Function for identifying integer overflow when subtracting. More...
 
template<typename Rep , typename T >
CUDF_HOST_DEVICE auto numeric::division_overflow (T lhs, T rhs)
 Function for identifying integer overflow when dividing. More...
 
template<typename Rep , typename T >
CUDF_HOST_DEVICE auto numeric::multiplication_overflow (T lhs, T rhs)
 Function for identifying integer overflow when multiplying. More...
 
template<typename Rep1 , Radix Rad1>
CUDF_HOST_DEVICE fixed_point< Rep1, Rad1 > numeric::operator+ (fixed_point< Rep1, Rad1 > const &lhs, fixed_point< Rep1, Rad1 > const &rhs)
 
template<typename Rep1 , Radix Rad1>
CUDF_HOST_DEVICE fixed_point< Rep1, Rad1 > numeric::operator- (fixed_point< Rep1, Rad1 > const &lhs, fixed_point< Rep1, Rad1 > const &rhs)
 
template<typename Rep1 , Radix Rad1>
CUDF_HOST_DEVICE fixed_point< Rep1, Rad1 > numeric::operator* (fixed_point< Rep1, Rad1 > const &lhs, fixed_point< Rep1, Rad1 > const &rhs)
 
template<typename Rep1 , Radix Rad1>
CUDF_HOST_DEVICE fixed_point< Rep1, Rad1 > numeric::operator/ (fixed_point< Rep1, Rad1 > const &lhs, fixed_point< Rep1, Rad1 > const &rhs)
 
template<typename Rep1 , Radix Rad1>
CUDF_HOST_DEVICE bool numeric::operator== (fixed_point< Rep1, Rad1 > const &lhs, fixed_point< Rep1, Rad1 > const &rhs)
 
template<typename Rep1 , Radix Rad1>
CUDF_HOST_DEVICE bool numeric::operator!= (fixed_point< Rep1, Rad1 > const &lhs, fixed_point< Rep1, Rad1 > const &rhs)
 
template<typename Rep1 , Radix Rad1>
CUDF_HOST_DEVICE bool numeric::operator<= (fixed_point< Rep1, Rad1 > const &lhs, fixed_point< Rep1, Rad1 > const &rhs)
 
template<typename Rep1 , Radix Rad1>
CUDF_HOST_DEVICE bool numeric::operator>= (fixed_point< Rep1, Rad1 > const &lhs, fixed_point< Rep1, Rad1 > const &rhs)
 
template<typename Rep1 , Radix Rad1>
CUDF_HOST_DEVICE bool numeric::operator< (fixed_point< Rep1, Rad1 > const &lhs, fixed_point< Rep1, Rad1 > const &rhs)
 
template<typename Rep1 , Radix Rad1>
CUDF_HOST_DEVICE bool numeric::operator> (fixed_point< Rep1, Rad1 > const &lhs, fixed_point< Rep1, Rad1 > const &rhs)
 
template<typename Rep1 , Radix Rad1>
CUDF_HOST_DEVICE fixed_point< Rep1, Rad1 > numeric::operator% (fixed_point< Rep1, Rad1 > const &lhs, fixed_point< Rep1, Rad1 > const &rhs)
 

Detailed Description

Enumeration Type Documentation

◆ Radix

enum numeric::Radix : int32_t
strong

Scoped enumerator to use when constructing fixed_point

Examples:

using decimal32 = fixed_point<int32_t, Radix::BASE_10>;
using binary64 = fixed_point<int64_t, Radix::BASE_2>;
fixed_point< int32_t, Radix::BASE_10 > decimal32
32-bit decimal fixed point

Definition at line 54 of file fixed_point.hpp.

Function Documentation

◆ addition_overflow()

template<typename Rep , typename T >
CUDF_HOST_DEVICE auto numeric::addition_overflow ( lhs,
rhs 
)
inline

Function for identifying integer overflow when adding.

Template Parameters
RepType of integer to check for overflow on
TTypes of lhs and rhs (ensures they are the same type)
Parameters
lhsLeft hand side of addition
rhsRight hand side of addition
Returns
true if addition causes overflow, false otherwise

Definition at line 655 of file fixed_point.hpp.

◆ division_overflow()

template<typename Rep , typename T >
CUDF_HOST_DEVICE auto numeric::division_overflow ( lhs,
rhs 
)
inline

Function for identifying integer overflow when dividing.

Template Parameters
RepType of integer to check for overflow on
TTypes of lhs and rhs (ensures they are the same type)
Parameters
lhsLeft hand side of division
rhsRight hand side of division
Returns
true if division causes overflow, false otherwise

Definition at line 685 of file fixed_point.hpp.

◆ is_supported_construction_value_type()

template<typename T >
constexpr auto numeric::is_supported_construction_value_type ( )
inlineconstexpr

Returns true if the value type is supported for constructing a fixed_point

Template Parameters
TThe construction value type
Returns
true if the value type is supported to construct a fixed_point type

Definition at line 77 of file fixed_point.hpp.

◆ is_supported_representation_type()

template<typename T >
constexpr auto numeric::is_supported_representation_type ( )
inlineconstexpr

Returns true if the representation type is supported by fixed_point

Template Parameters
TThe representation type
Returns
true if the type is supported by fixed_point implementation

Definition at line 63 of file fixed_point.hpp.

◆ multiplication_overflow()

template<typename Rep , typename T >
CUDF_HOST_DEVICE auto numeric::multiplication_overflow ( lhs,
rhs 
)
inline

Function for identifying integer overflow when multiplying.

Template Parameters
RepType of integer to check for overflow on
TTypes of lhs and rhs (ensures they are the same type)
Parameters
lhsLeft hand side of multiplication
rhsRight hand side of multiplication
Returns
true if multiplication causes overflow, false otherwise

Definition at line 699 of file fixed_point.hpp.

◆ operator!=()

template<typename Rep1 , Radix Rad1>
CUDF_HOST_DEVICE bool numeric::operator!= ( fixed_point< Rep1, Rad1 > const &  lhs,
fixed_point< Rep1, Rad1 > const &  rhs 
)
inline

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

◆ operator%()

template<typename Rep1 , Radix Rad1>
CUDF_HOST_DEVICE fixed_point<Rep1, Rad1> numeric::operator% ( fixed_point< Rep1, Rad1 > const &  lhs,
fixed_point< Rep1, Rad1 > const &  rhs 
)
inline

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

◆ operator*()

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

_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 746 of file fixed_point.hpp.

◆ operator+()

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

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

◆ operator-()

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

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

◆ operator/()

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

_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 761 of file fixed_point.hpp.

◆ operator<()

template<typename Rep1 , Radix Rad1>
CUDF_HOST_DEVICE bool numeric::operator< ( fixed_point< Rep1, Rad1 > const &  lhs,
fixed_point< Rep1, Rad1 > const &  rhs 
)
inline

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

◆ operator<=()

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

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

◆ operator==()

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

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

◆ operator>()

template<typename Rep1 , Radix Rad1>
CUDF_HOST_DEVICE bool numeric::operator> ( fixed_point< Rep1, Rad1 > const &  lhs,
fixed_point< Rep1, Rad1 > const &  rhs 
)
inline

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

◆ operator>=()

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

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

◆ subtraction_overflow()

template<typename Rep , typename T >
CUDF_HOST_DEVICE auto numeric::subtraction_overflow ( lhs,
rhs 
)
inline

Function for identifying integer overflow when subtracting.

Template Parameters
RepType of integer to check for overflow on
TTypes of lhs and rhs (ensures they are the same type)
Parameters
lhsLeft hand side of subtraction
rhsRight hand side of subtraction
Returns
true if subtraction causes overflow, false otherwise

Definition at line 670 of file fixed_point.hpp.