libcudf  23.12.00
fixed_point.hpp
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2020-2023, NVIDIA CORPORATION.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 
17 #pragma once
18 
19 #include <cudf/detail/utilities/assert.cuh>
20 #include <cudf/fixed_point/temporary.hpp>
21 #include <cudf/types.hpp>
22 
23 #include <cuda/std/limits>
24 #include <cuda/std/type_traits>
25 
26 #include <algorithm>
27 #include <cassert>
28 #include <cmath>
29 #include <string>
30 
32 namespace numeric {
33 
35 enum scale_type : int32_t {};
36 
46 enum class Radix : int32_t { BASE_2 = 2, BASE_10 = 10 };
47 
54 template <typename T>
55 constexpr inline auto is_supported_representation_type()
56 {
57  return cuda::std::is_same_v<T, int32_t> || //
58  cuda::std::is_same_v<T, int64_t> || //
59  cuda::std::is_same_v<T, __int128_t>;
60 }
61 
68 template <typename T>
69 constexpr inline auto is_supported_construction_value_type()
70 {
71  return cuda::std::is_integral<T>() || cuda::std::is_floating_point_v<T>;
72 }
73 
74 // Helper functions for `fixed_point` type
75 namespace detail {
88 template <typename Rep,
89  Radix Base,
90  typename T,
91  typename cuda::std::enable_if_t<(cuda::std::is_same_v<int32_t, T> &&
92  is_supported_representation_type<Rep>())>* = nullptr>
93 CUDF_HOST_DEVICE inline Rep ipow(T exponent)
94 {
95  cudf_assert(exponent >= 0 && "integer exponentiation with negative exponent is not possible.");
96  if (exponent == 0) { return static_cast<Rep>(1); }
97 
98  auto extra = static_cast<Rep>(1);
99  auto square = static_cast<Rep>(Base);
100  while (exponent > 1) {
101  if (exponent & 1 /* odd */) {
102  extra *= square;
103  exponent -= 1;
104  }
105  exponent /= 2;
106  square *= square;
107  }
108  return square * extra;
109 }
110 
122 template <typename Rep, Radix Rad, typename T>
123 CUDF_HOST_DEVICE inline constexpr T right_shift(T const& val, scale_type const& scale)
124 {
125  return val / ipow<Rep, Rad>(static_cast<int32_t>(scale));
126 }
127 
139 template <typename Rep, Radix Rad, typename T>
140 CUDF_HOST_DEVICE inline constexpr T left_shift(T const& val, scale_type const& scale)
141 {
142  return val * ipow<Rep, Rad>(static_cast<int32_t>(-scale));
143 }
144 
158 template <typename Rep, Radix Rad, typename T>
159 CUDF_HOST_DEVICE inline constexpr T shift(T const& val, scale_type const& scale)
160 {
161  if (scale == 0) { return val; }
162  if (scale > 0) { return right_shift<Rep, Rad>(val, scale); }
163  return left_shift<Rep, Rad>(val, scale);
164 }
165 
166 } // namespace detail
167 
186 template <typename Rep,
187  typename cuda::std::enable_if_t<is_supported_representation_type<Rep>()>* = nullptr>
189  Rep value;
197  CUDF_HOST_DEVICE inline explicit scaled_integer(Rep v, scale_type s) : value{v}, scale{s} {}
198 };
199 
209 template <typename Rep, Radix Rad>
210 class fixed_point {
211  Rep _value{};
212  scale_type _scale;
213 
214  public:
215  using rep = Rep;
216 
225  template <typename T,
226  typename cuda::std::enable_if_t<cuda::std::is_floating_point<T>() &&
227  is_supported_representation_type<Rep>()>* = nullptr>
228  CUDF_HOST_DEVICE inline explicit fixed_point(T const& value, scale_type const& scale)
229  : _value{static_cast<Rep>(detail::shift<Rep, Rad>(value, scale))}, _scale{scale}
230  {
231  }
232 
241  template <typename T,
242  typename cuda::std::enable_if_t<cuda::std::is_integral<T>() &&
243  is_supported_representation_type<Rep>()>* = nullptr>
244  CUDF_HOST_DEVICE inline explicit fixed_point(T const& value, scale_type const& scale)
245  // `value` is cast to `Rep` to avoid overflow in cases where
246  // constructing to `Rep` that is wider than `T`
247  : _value{detail::shift<Rep, Rad>(static_cast<Rep>(value), scale)}, _scale{scale}
248  {
249  }
250 
256  CUDF_HOST_DEVICE inline explicit fixed_point(scaled_integer<Rep> s)
257  : _value{s.value}, _scale{s.scale}
258  {
259  }
260 
268  template <typename T,
269  typename cuda::std::enable_if_t<is_supported_construction_value_type<T>()>* = nullptr>
270  CUDF_HOST_DEVICE inline fixed_point(T const& value)
271  : _value{static_cast<Rep>(value)}, _scale{scale_type{0}}
272  {
273  }
274 
279  CUDF_HOST_DEVICE inline fixed_point() : _scale{scale_type{0}} {}
280 
287  template <typename U,
288  typename cuda::std::enable_if_t<cuda::std::is_floating_point_v<U>>* = nullptr>
289  explicit constexpr operator U() const
290  {
291  return detail::shift<Rep, Rad>(static_cast<U>(_value), scale_type{-_scale});
292  }
293 
300  template <typename U, typename cuda::std::enable_if_t<cuda::std::is_integral_v<U>>* = nullptr>
301  explicit constexpr operator U() const
302  {
303  // Cast to the larger of the two types (of U and Rep) before converting to Rep because in
304  // certain cases casting to U before shifting will result in integer overflow (i.e. if U =
305  // int32_t, Rep = int64_t and _value > 2 billion)
306  auto const value = std::common_type_t<U, Rep>(_value);
307  return static_cast<U>(detail::shift<Rep, Rad>(value, scale_type{-_scale}));
308  }
309 
315  CUDF_HOST_DEVICE inline operator scaled_integer<Rep>() const
316  {
317  return scaled_integer<Rep>{_value, _scale};
318  }
319 
325  CUDF_HOST_DEVICE inline rep value() const { return _value; }
326 
332  CUDF_HOST_DEVICE inline scale_type scale() const { return _scale; }
333 
339  CUDF_HOST_DEVICE inline explicit constexpr operator bool() const
340  {
341  return static_cast<bool>(_value);
342  }
343 
352  template <typename Rep1, Radix Rad1>
353  CUDF_HOST_DEVICE inline fixed_point<Rep1, Rad1>& operator+=(fixed_point<Rep1, Rad1> const& rhs)
354  {
355  *this = *this + rhs;
356  return *this;
357  }
358 
367  template <typename Rep1, Radix Rad1>
368  CUDF_HOST_DEVICE inline fixed_point<Rep1, Rad1>& operator*=(fixed_point<Rep1, Rad1> const& rhs)
369  {
370  *this = *this * rhs;
371  return *this;
372  }
373 
382  template <typename Rep1, Radix Rad1>
383  CUDF_HOST_DEVICE inline fixed_point<Rep1, Rad1>& operator-=(fixed_point<Rep1, Rad1> const& rhs)
384  {
385  *this = *this - rhs;
386  return *this;
387  }
388 
397  template <typename Rep1, Radix Rad1>
398  CUDF_HOST_DEVICE inline fixed_point<Rep1, Rad1>& operator/=(fixed_point<Rep1, Rad1> const& rhs)
399  {
400  *this = *this / rhs;
401  return *this;
402  }
403 
409  CUDF_HOST_DEVICE inline fixed_point<Rep, Rad>& operator++()
410  {
411  *this = *this + fixed_point<Rep, Rad>{1, scale_type{_scale}};
412  return *this;
413  }
414 
428  template <typename Rep1, Radix Rad1>
429  CUDF_HOST_DEVICE inline friend fixed_point<Rep1, Rad1> operator+(
430  fixed_point<Rep1, Rad1> const& lhs, fixed_point<Rep1, Rad1> const& rhs);
431 
445  template <typename Rep1, Radix Rad1>
446  CUDF_HOST_DEVICE inline friend fixed_point<Rep1, Rad1> operator-(
447  fixed_point<Rep1, Rad1> const& lhs, fixed_point<Rep1, Rad1> const& rhs);
448 
460  template <typename Rep1, Radix Rad1>
461  CUDF_HOST_DEVICE inline friend fixed_point<Rep1, Rad1> operator*(
462  fixed_point<Rep1, Rad1> const& lhs, fixed_point<Rep1, Rad1> const& rhs);
463 
475  template <typename Rep1, Radix Rad1>
476  CUDF_HOST_DEVICE inline friend fixed_point<Rep1, Rad1> operator/(
477  fixed_point<Rep1, Rad1> const& lhs, fixed_point<Rep1, Rad1> const& rhs);
478 
492  template <typename Rep1, Radix Rad1>
493  CUDF_HOST_DEVICE inline friend fixed_point<Rep1, Rad1> operator%(
494  fixed_point<Rep1, Rad1> const& lhs, fixed_point<Rep1, Rad1> const& rhs);
495 
509  template <typename Rep1, Radix Rad1>
510  CUDF_HOST_DEVICE inline friend bool operator==(fixed_point<Rep1, Rad1> const& lhs,
511  fixed_point<Rep1, Rad1> const& rhs);
512 
526  template <typename Rep1, Radix Rad1>
527  CUDF_HOST_DEVICE inline friend bool operator!=(fixed_point<Rep1, Rad1> const& lhs,
528  fixed_point<Rep1, Rad1> const& rhs);
529 
543  template <typename Rep1, Radix Rad1>
544  CUDF_HOST_DEVICE inline friend bool operator<=(fixed_point<Rep1, Rad1> const& lhs,
545  fixed_point<Rep1, Rad1> const& rhs);
546 
560  template <typename Rep1, Radix Rad1>
561  CUDF_HOST_DEVICE inline friend bool operator>=(fixed_point<Rep1, Rad1> const& lhs,
562  fixed_point<Rep1, Rad1> const& rhs);
563 
577  template <typename Rep1, Radix Rad1>
578  CUDF_HOST_DEVICE inline friend bool operator<(fixed_point<Rep1, Rad1> const& lhs,
579  fixed_point<Rep1, Rad1> const& rhs);
580 
594  template <typename Rep1, Radix Rad1>
595  CUDF_HOST_DEVICE inline friend bool operator>(fixed_point<Rep1, Rad1> const& lhs,
596  fixed_point<Rep1, Rad1> const& rhs);
597 
607  CUDF_HOST_DEVICE inline fixed_point<Rep, Rad> rescaled(scale_type scale) const
608  {
609  if (scale == _scale) { return *this; }
610  Rep const value = detail::shift<Rep, Rad>(_value, scale_type{scale - _scale});
612  }
613 
617  explicit operator std::string() const
618  {
619  if (_scale < 0) {
620  auto const av = detail::abs(_value);
621  Rep const n = detail::exp10<Rep>(-_scale);
622  Rep const f = av % n;
623  auto const num_zeros =
624  std::max(0, (-_scale - static_cast<int32_t>(detail::to_string(f).size())));
625  auto const zeros = std::string(num_zeros, '0');
626  auto const sign = _value < 0 ? std::string("-") : std::string();
627  return sign + detail::to_string(av / n) + std::string(".") + zeros +
628  detail::to_string(av % n);
629  }
630  auto const zeros = std::string(_scale, '0');
631  return detail::to_string(_value) + zeros;
632  }
633 };
634 
644 template <typename Rep, typename T>
645 CUDF_HOST_DEVICE inline auto addition_overflow(T lhs, T rhs)
646 {
647  return rhs > 0 ? lhs > cuda::std::numeric_limits<Rep>::max() - rhs
648  : lhs < cuda::std::numeric_limits<Rep>::min() - rhs;
649 }
650 
659 template <typename Rep, typename T>
660 CUDF_HOST_DEVICE inline auto subtraction_overflow(T lhs, T rhs)
661 {
662  return rhs > 0 ? lhs < cuda::std::numeric_limits<Rep>::min() + rhs
663  : lhs > cuda::std::numeric_limits<Rep>::max() + rhs;
664 }
665 
674 template <typename Rep, typename T>
675 CUDF_HOST_DEVICE inline auto division_overflow(T lhs, T rhs)
676 {
677  return lhs == cuda::std::numeric_limits<Rep>::min() && rhs == -1;
678 }
679 
688 template <typename Rep, typename T>
689 CUDF_HOST_DEVICE inline auto multiplication_overflow(T lhs, T rhs)
690 {
691  auto const min = cuda::std::numeric_limits<Rep>::min();
692  auto const max = cuda::std::numeric_limits<Rep>::max();
693  if (rhs > 0) { return lhs > max / rhs || lhs < min / rhs; }
694  if (rhs < -1) { return lhs > min / rhs || lhs < max / rhs; }
695  return rhs == -1 && lhs == min;
696 }
697 
698 // PLUS Operation
699 template <typename Rep1, Radix Rad1>
700 CUDF_HOST_DEVICE inline fixed_point<Rep1, Rad1> operator+(fixed_point<Rep1, Rad1> const& lhs,
701  fixed_point<Rep1, Rad1> const& rhs)
702 {
703  auto const scale = std::min(lhs._scale, rhs._scale);
704  auto const sum = lhs.rescaled(scale)._value + rhs.rescaled(scale)._value;
705 
706 #if defined(__CUDACC_DEBUG__)
707 
708  assert(!addition_overflow<Rep1>(lhs.rescaled(scale)._value, rhs.rescaled(scale)._value) &&
709  "fixed_point overflow");
710 
711 #endif
712 
713  return fixed_point<Rep1, Rad1>{scaled_integer<Rep1>{sum, scale}};
714 }
715 
716 // MINUS Operation
717 template <typename Rep1, Radix Rad1>
718 CUDF_HOST_DEVICE inline fixed_point<Rep1, Rad1> operator-(fixed_point<Rep1, Rad1> const& lhs,
719  fixed_point<Rep1, Rad1> const& rhs)
720 {
721  auto const scale = std::min(lhs._scale, rhs._scale);
722  auto const diff = lhs.rescaled(scale)._value - rhs.rescaled(scale)._value;
723 
724 #if defined(__CUDACC_DEBUG__)
725 
726  assert(!subtraction_overflow<Rep1>(lhs.rescaled(scale)._value, rhs.rescaled(scale)._value) &&
727  "fixed_point overflow");
728 
729 #endif
730 
731  return fixed_point<Rep1, Rad1>{scaled_integer<Rep1>{diff, scale}};
732 }
733 
734 // MULTIPLIES Operation
735 template <typename Rep1, Radix Rad1>
736 CUDF_HOST_DEVICE inline fixed_point<Rep1, Rad1> operator*(fixed_point<Rep1, Rad1> const& lhs,
737  fixed_point<Rep1, Rad1> const& rhs)
738 {
739 #if defined(__CUDACC_DEBUG__)
740 
741  assert(!multiplication_overflow<Rep1>(lhs._value, rhs._value) && "fixed_point overflow");
742 
743 #endif
744 
746  scaled_integer<Rep1>(lhs._value * rhs._value, scale_type{lhs._scale + rhs._scale})};
747 }
748 
749 // DIVISION Operation
750 template <typename Rep1, Radix Rad1>
751 CUDF_HOST_DEVICE inline fixed_point<Rep1, Rad1> operator/(fixed_point<Rep1, Rad1> const& lhs,
752  fixed_point<Rep1, Rad1> const& rhs)
753 {
754 #if defined(__CUDACC_DEBUG__)
755 
756  assert(!division_overflow<Rep1>(lhs._value, rhs._value) && "fixed_point overflow");
757 
758 #endif
759 
761  scaled_integer<Rep1>(lhs._value / rhs._value, scale_type{lhs._scale - rhs._scale})};
762 }
763 
764 // EQUALITY COMPARISON Operation
765 template <typename Rep1, Radix Rad1>
766 CUDF_HOST_DEVICE inline bool operator==(fixed_point<Rep1, Rad1> const& lhs,
767  fixed_point<Rep1, Rad1> const& rhs)
768 {
769  auto const scale = std::min(lhs._scale, rhs._scale);
770  return lhs.rescaled(scale)._value == rhs.rescaled(scale)._value;
771 }
772 
773 // EQUALITY NOT COMPARISON Operation
774 template <typename Rep1, Radix Rad1>
775 CUDF_HOST_DEVICE inline bool operator!=(fixed_point<Rep1, Rad1> const& lhs,
776  fixed_point<Rep1, Rad1> const& rhs)
777 {
778  auto const scale = std::min(lhs._scale, rhs._scale);
779  return lhs.rescaled(scale)._value != rhs.rescaled(scale)._value;
780 }
781 
782 // LESS THAN OR EQUAL TO Operation
783 template <typename Rep1, Radix Rad1>
784 CUDF_HOST_DEVICE inline bool operator<=(fixed_point<Rep1, Rad1> const& lhs,
785  fixed_point<Rep1, Rad1> const& rhs)
786 {
787  auto const scale = std::min(lhs._scale, rhs._scale);
788  return lhs.rescaled(scale)._value <= rhs.rescaled(scale)._value;
789 }
790 
791 // GREATER THAN OR EQUAL TO Operation
792 template <typename Rep1, Radix Rad1>
793 CUDF_HOST_DEVICE inline bool operator>=(fixed_point<Rep1, Rad1> const& lhs,
794  fixed_point<Rep1, Rad1> const& rhs)
795 {
796  auto const scale = std::min(lhs._scale, rhs._scale);
797  return lhs.rescaled(scale)._value >= rhs.rescaled(scale)._value;
798 }
799 
800 // LESS THAN Operation
801 template <typename Rep1, Radix Rad1>
802 CUDF_HOST_DEVICE inline bool operator<(fixed_point<Rep1, Rad1> const& lhs,
803  fixed_point<Rep1, Rad1> const& rhs)
804 {
805  auto const scale = std::min(lhs._scale, rhs._scale);
806  return lhs.rescaled(scale)._value < rhs.rescaled(scale)._value;
807 }
808 
809 // GREATER THAN Operation
810 template <typename Rep1, Radix Rad1>
811 CUDF_HOST_DEVICE inline bool operator>(fixed_point<Rep1, Rad1> const& lhs,
812  fixed_point<Rep1, Rad1> const& rhs)
813 {
814  auto const scale = std::min(lhs._scale, rhs._scale);
815  return lhs.rescaled(scale)._value > rhs.rescaled(scale)._value;
816 }
817 
818 // MODULO OPERATION
819 template <typename Rep1, Radix Rad1>
820 CUDF_HOST_DEVICE inline fixed_point<Rep1, Rad1> operator%(fixed_point<Rep1, Rad1> const& lhs,
821  fixed_point<Rep1, Rad1> const& rhs)
822 {
823  auto const scale = std::min(lhs._scale, rhs._scale);
824  auto const remainder = lhs.rescaled(scale)._value % rhs.rescaled(scale)._value;
825  return fixed_point<Rep1, Rad1>{scaled_integer<Rep1>{remainder, scale}};
826 }
827 
831  // end of group
833 } // namespace numeric
A type for representing a number with a fixed amount of precision.
CUDF_HOST_DEVICE fixed_point< Rep, Rad > rescaled(scale_type scale) const
Method for creating a fixed_point number with a new scale
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)
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)
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)
CUDF_HOST_DEVICE rep value() const
Method that returns the underlying value of the fixed_point number.
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)
CUDF_HOST_DEVICE fixed_point< Rep1, Rad1 > & operator*=(fixed_point< Rep1, Rad1 > const &rhs)
operator *=
CUDF_HOST_DEVICE scale_type scale() const
Method that returns the scale of the fixed_point number.
CUDF_HOST_DEVICE fixed_point< Rep1, Rad1 > & operator-=(fixed_point< Rep1, Rad1 > const &rhs)
operator -=
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)
CUDF_HOST_DEVICE fixed_point< Rep1, Rad1 > & operator+=(fixed_point< Rep1, Rad1 > const &rhs)
operator +=
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)
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)
Rep rep
The representation type.
CUDF_HOST_DEVICE fixed_point()
Default constructor that constructs fixed_point number with a value and scale of zero.
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)
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)
CUDF_HOST_DEVICE fixed_point< Rep1, Rad1 > & operator/=(fixed_point< Rep1, Rad1 > const &rhs)
operator /=
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)
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)
CUDF_HOST_DEVICE fixed_point< Rep, Rad > & operator++()
operator ++ (post-increment)
constexpr CUDF_HOST_DEVICE T left_shift(T const &val, scale_type const &scale)
Function that performs a left shift scale "times" on the val
constexpr CUDF_HOST_DEVICE T right_shift(T const &val, scale_type const &scale)
Function that performs a right shift scale "times" on the val
CUDF_HOST_DEVICE Rep ipow(T exponent)
A function for integer exponentiation by squaring.
Definition: fixed_point.hpp:93
CUDF_HOST_DEVICE fixed_point< Rep1, Rad1 > operator-(fixed_point< Rep1, Rad1 > const &lhs, fixed_point< Rep1, Rad1 > const &rhs)
CUDF_HOST_DEVICE bool operator>=(fixed_point< Rep1, Rad1 > const &lhs, fixed_point< Rep1, Rad1 > const &rhs)
CUDF_HOST_DEVICE bool operator<=(fixed_point< Rep1, Rad1 > const &lhs, fixed_point< Rep1, Rad1 > const &rhs)
CUDF_HOST_DEVICE bool operator==(fixed_point< Rep1, Rad1 > const &lhs, fixed_point< Rep1, Rad1 > const &rhs)
CUDF_HOST_DEVICE fixed_point< Rep1, Rad1 > operator%(fixed_point< Rep1, Rad1 > const &lhs, fixed_point< Rep1, Rad1 > const &rhs)
CUDF_HOST_DEVICE auto division_overflow(T lhs, T rhs)
Function for identifying integer overflow when dividing.
CUDF_HOST_DEVICE fixed_point< Rep1, Rad1 > operator/(fixed_point< Rep1, Rad1 > const &lhs, fixed_point< Rep1, Rad1 > const &rhs)
CUDF_HOST_DEVICE fixed_point< Rep1, Rad1 > operator*(fixed_point< Rep1, Rad1 > const &lhs, fixed_point< Rep1, Rad1 > const &rhs)
CUDF_HOST_DEVICE bool operator>(fixed_point< Rep1, Rad1 > const &lhs, fixed_point< Rep1, Rad1 > const &rhs)
CUDF_HOST_DEVICE auto addition_overflow(T lhs, T rhs)
Function for identifying integer overflow when adding.
CUDF_HOST_DEVICE fixed_point< Rep1, Rad1 > operator+(fixed_point< Rep1, Rad1 > const &lhs, fixed_point< Rep1, Rad1 > const &rhs)
CUDF_HOST_DEVICE auto multiplication_overflow(T lhs, T rhs)
Function for identifying integer overflow when multiplying.
CUDF_HOST_DEVICE bool operator!=(fixed_point< Rep1, Rad1 > const &lhs, fixed_point< Rep1, Rad1 > const &rhs)
CUDF_HOST_DEVICE auto subtraction_overflow(T lhs, T rhs)
Function for identifying integer overflow when subtracting.
CUDF_HOST_DEVICE bool operator<(fixed_point< Rep1, Rad1 > const &lhs, fixed_point< Rep1, Rad1 > const &rhs)
fixed_point and supporting types
Definition: fixed_point.hpp:32
Radix
Scoped enumerator to use when constructing fixed_point
Definition: fixed_point.hpp:46
constexpr auto is_supported_construction_value_type()
Returns true if the value type is supported for constructing a fixed_point
Definition: fixed_point.hpp:69
scale_type
The scale type for fixed_point.
Definition: fixed_point.hpp:35
constexpr auto is_supported_representation_type()
Returns true if the representation type is supported by fixed_point
Definition: fixed_point.hpp:55
Helper struct for constructing fixed_point when value is already shifted.
Rep value
The value of the fixed point number.
CUDF_HOST_DEVICE scaled_integer(Rep v, scale_type s)
Constructor for scaled_integer
scale_type scale
The scale of the value.
Type declarations for libcudf.