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/types.hpp>
#include <cuda/std/limits>
#include <cuda/std/type_traits>
#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::scale_type = strong_typedef< int32_t >
 
using numeric::decimal32 = fixed_point< int32_t, Radix::BASE_10 >
 
using numeric::decimal64 = fixed_point< int64_t, Radix::BASE_10 >
 

Enumerations

enum  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 ()
 
template<typename T >
constexpr auto numeric::is_supported_construction_value_type ()
 
template<typename Rep , Radix Base, typename T , typename cuda::std::enable_if_t<(cuda::std::is_same< int32_t, T >::value &&is_supported_representation_type< Rep >())> * = nullptr>
CUDA_HOST_DEVICE_CALLABLE Rep numeric::detail::ipow (T exponent)
 A function for integer exponentiation by squaring. More...
 
CUDA_HOST_DEVICE_CALLABLE auto numeric::detail::negate (scale_type const &scale)
 Helper function to negate strongly typed scale_type. More...
 
template<typename Rep , Radix Rad, typename T >
constexpr CUDA_HOST_DEVICE_CALLABLE T numeric::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 CUDA_HOST_DEVICE_CALLABLE T numeric::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 CUDA_HOST_DEVICE_CALLABLE T numeric::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 >
CUDA_HOST_DEVICE_CALLABLE auto numeric::addition_overflow (T lhs, T rhs)
 Function for identifying integer overflow when adding. More...
 
template<typename Rep , typename T >
CUDA_HOST_DEVICE_CALLABLE auto numeric::subtraction_overflow (T lhs, T rhs)
 Function for identifying integer overflow when subtracting. More...
 
template<typename Rep , typename T >
CUDA_HOST_DEVICE_CALLABLE auto numeric::division_overflow (T lhs, T rhs)
 Function for identifying integer overflow when dividing. More...
 
template<typename Rep , typename T >
CUDA_HOST_DEVICE_CALLABLE auto numeric::multiplication_overflow (T lhs, T rhs)
 Function for identifying integer overflow when multiplying. More...
 
template<typename Rep1 , Radix Rad1>
CUDA_HOST_DEVICE_CALLABLE fixed_point< Rep1, Rad1 > numeric::operator+ (fixed_point< Rep1, Rad1 > const &lhs, fixed_point< Rep1, Rad1 > const &rhs)
 
template<typename Rep1 , Radix Rad1>
CUDA_HOST_DEVICE_CALLABLE fixed_point< Rep1, Rad1 > numeric::operator- (fixed_point< Rep1, Rad1 > const &lhs, fixed_point< Rep1, Rad1 > const &rhs)
 
template<typename Rep1 , Radix Rad1>
CUDA_HOST_DEVICE_CALLABLE fixed_point< Rep1, Rad1 > numeric::operator* (fixed_point< Rep1, Rad1 > const &lhs, fixed_point< Rep1, Rad1 > const &rhs)
 
template<typename Rep1 , Radix Rad1>
CUDA_HOST_DEVICE_CALLABLE fixed_point< Rep1, Rad1 > numeric::operator/ (fixed_point< Rep1, Rad1 > const &lhs, fixed_point< Rep1, Rad1 > const &rhs)
 
template<typename Rep1 , Radix Rad1>
CUDA_HOST_DEVICE_CALLABLE bool numeric::operator== (fixed_point< Rep1, Rad1 > const &lhs, fixed_point< Rep1, Rad1 > const &rhs)
 
template<typename Rep1 , Radix Rad1>
CUDA_HOST_DEVICE_CALLABLE bool numeric::operator!= (fixed_point< Rep1, Rad1 > const &lhs, fixed_point< Rep1, Rad1 > const &rhs)
 
template<typename Rep1 , Radix Rad1>
CUDA_HOST_DEVICE_CALLABLE bool numeric::operator<= (fixed_point< Rep1, Rad1 > const &lhs, fixed_point< Rep1, Rad1 > const &rhs)
 
template<typename Rep1 , Radix Rad1>
CUDA_HOST_DEVICE_CALLABLE bool numeric::operator>= (fixed_point< Rep1, Rad1 > const &lhs, fixed_point< Rep1, Rad1 > const &rhs)
 
template<typename Rep1 , Radix Rad1>
CUDA_HOST_DEVICE_CALLABLE bool numeric::operator< (fixed_point< Rep1, Rad1 > const &lhs, fixed_point< Rep1, Rad1 > const &rhs)
 
template<typename Rep1 , Radix Rad1>
CUDA_HOST_DEVICE_CALLABLE bool 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< int32_t, T >::value &&is_supported_representation_type< Rep >())> * = nullptr>
CUDA_HOST_DEVICE_CALLABLE Rep numeric::detail::ipow ( exponent)

A function for integer exponentiation by squaring.

https://simple.wikipedia.org/wiki/Exponentiation_by_squaring
Note: this is the iterative equivalent of the recursive definition (faster)
Quick-bench: http://quick-bench.com/Wg7o7HYQC9FW5M0CO0wQAjSwP_Y
exponent comes from using scale_type = strong_typedef<int32_t>

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

◆ left_shift()

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

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

◆ negate()

CUDA_HOST_DEVICE_CALLABLE auto numeric::detail::negate ( scale_type const &  scale)

Helper function to negate strongly typed scale_type.

Parameters
scaleThe scale to be negated
Returns
The negated scale

Definition at line 115 of file fixed_point.hpp.

◆ right_shift()

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

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

◆ shift()

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

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