Classes | Namespaces | Typedefs | Enumerations | Functions
fixed_point.hpp File Reference

Class definition for fixed point data type. More...

#include <cudf/detail/utilities/assert.cuh>
#include <cudf/fixed_point/temporary.hpp>
#include <cudf/types.hpp>
#include <cuda/std/limits>
#include <cuda/std/type_traits>
#include <cuda/std/utility>
#include <algorithm>
#include <cassert>
#include <cmath>
#include <string>

Go to the source code of this file.

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

Namespaces

 numeric
 fixed_point and supporting types
 

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 Rep , Radix Base, typename T , typename cuda::std::enable_if_t<(cuda::std::is_same_v< int32_t, T > &&is_supported_representation_type< Rep >())> * = nullptr>
CUDF_HOST_DEVICE Rep numeric::detail::ipow (T exponent)
 A function for integer exponentiation by squaring. More...
 
template<typename Rep , Radix Rad, typename T >
constexpr CUDF_HOST_DEVICEnumeric::detail::right_shift (T const &val, scale_type const &scale)
 Function that performs a right shift scale "times" on the val More...
 
template<typename Rep , Radix Rad, typename T >
constexpr CUDF_HOST_DEVICEnumeric::detail::left_shift (T const &val, scale_type const &scale)
 Function that performs a left shift scale "times" on the val More...
 
template<typename Rep , Radix Rad, typename T >
constexpr CUDF_HOST_DEVICEnumeric::detail::shift (T const &val, scale_type const &scale)
 Function that performs a right or left shift scale "times" on the val 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

Class definition for fixed point data type.

Definition in file fixed_point.hpp.

Function Documentation

◆ ipow()

template<typename Rep , Radix Base, typename T , typename cuda::std::enable_if_t<(cuda::std::is_same_v< int32_t, T > &&is_supported_representation_type< Rep >())> * = nullptr>
CUDF_HOST_DEVICE Rep numeric::detail::ipow ( exponent)
inline

A function for integer exponentiation by squaring.

Template Parameters
RepRepresentation type for return type
BaseThe base to be exponentiated
Parameters
exponentThe exponent to be used for exponentiation
Returns
Result of Base to the power of exponent of type Rep

Definition at line 88 of file fixed_point.hpp.

◆ left_shift()

template<typename Rep , Radix Rad, typename T >
constexpr CUDF_HOST_DEVICE T numeric::detail::left_shift ( T const &  val,
scale_type const &  scale 
)
inlineconstexpr

Function that performs a left shift scale "times" on the val

Note: perform this operation when constructing with negative scale

Template Parameters
RepRepresentation type needed for integer exponentiation
RadThe radix which will act as the base in the exponentiation
TType for value val being shifted and the return type
Parameters
valThe value being shifted
scaleThe amount to shift the value by
Returns
Shifted value of type T

Definition at line 138 of file fixed_point.hpp.

◆ right_shift()

template<typename Rep , Radix Rad, typename T >
constexpr CUDF_HOST_DEVICE T numeric::detail::right_shift ( T const &  val,
scale_type const &  scale 
)
inlineconstexpr

Function that performs a right shift scale "times" on the val

Note: perform this operation when constructing with positive scale

Template Parameters
RepRepresentation type needed for integer exponentiation
RadThe radix which will act as the base in the exponentiation
TType for value val being shifted and the return type
Parameters
valThe value being shifted
scaleThe amount to shift the value by
Returns
Shifted value of type T

Definition at line 121 of file fixed_point.hpp.

◆ shift()

template<typename Rep , Radix Rad, typename T >
constexpr CUDF_HOST_DEVICE T numeric::detail::shift ( T const &  val,
scale_type const &  scale 
)
inlineconstexpr

Function that performs a right or left shift scale "times" on the val

Note: Function will call the correct right or left shift based on the sign of val

Template Parameters
RepRepresentation type needed for integer exponentiation
RadThe radix which will act as the base in the exponentiation
TType for value val being shifted and the return type
Parameters
valThe value being shifted
scaleThe amount to shift the value by
Returns
Shifted value of type T

Definition at line 157 of file fixed_point.hpp.