fixed_point.hpp
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2020-2022, 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 // Note: The <cuda/std/*> versions are used in order for Jitify to work with our fixed_point type.
24 // Jitify is needed for several algorithms (binaryop, rolling, etc)
25 #include <cuda/std/climits>
26 #include <cuda/std/limits>
27 #include <cuda/std/type_traits> // add cuda namespace
28 
29 #include <algorithm>
30 #include <cassert>
31 #include <cmath>
32 #include <string>
33 
35 namespace numeric {
36 
38 enum scale_type : int32_t {};
39 
49 enum class Radix : int32_t { BASE_2 = 2, BASE_10 = 10 };
50 
57 template <typename T>
58 constexpr inline auto is_supported_representation_type()
59 {
60  return cuda::std::is_same_v<T, int32_t> || //
61  cuda::std::is_same_v<T, int64_t> || //
62  cuda::std::is_same_v<T, __int128_t>;
63 }
64 
71 template <typename T>
72 constexpr inline auto is_supported_construction_value_type()
73 {
74  return cuda::std::is_integral<T>() || cuda::std::is_floating_point_v<T>;
75 }
76 
77 // Helper functions for `fixed_point` type
78 namespace detail {
91 template <typename Rep,
92  Radix Base,
93  typename T,
94  typename cuda::std::enable_if_t<(cuda::std::is_same_v<int32_t, T> &&
95  is_supported_representation_type<Rep>())>* = nullptr>
96 CUDF_HOST_DEVICE inline Rep ipow(T exponent)
97 {
98  cudf_assert(exponent >= 0 && "integer exponentiation with negative exponent is not possible.");
99  if (exponent == 0) { return static_cast<Rep>(1); }
100 
101  auto extra = static_cast<Rep>(1);
102  auto square = static_cast<Rep>(Base);
103  while (exponent > 1) {
104  if (exponent & 1 /* odd */) {
105  extra *= square;
106  exponent -= 1;
107  }
108  exponent /= 2;
109  square *= square;
110  }
111  return square * extra;
112 }
113 
125 template <typename Rep, Radix Rad, typename T>
126 CUDF_HOST_DEVICE inline constexpr T right_shift(T const& val, scale_type const& scale)
127 {
128  return val / ipow<Rep, Rad>(static_cast<int32_t>(scale));
129 }
130 
142 template <typename Rep, Radix Rad, typename T>
143 CUDF_HOST_DEVICE inline constexpr T left_shift(T const& val, scale_type const& scale)
144 {
145  return val * ipow<Rep, Rad>(static_cast<int32_t>(-scale));
146 }
147 
161 template <typename Rep, Radix Rad, typename T>
162 CUDF_HOST_DEVICE inline constexpr T shift(T const& val, scale_type const& scale)
163 {
164  if (scale == 0) { return val; }
165  if (scale > 0) { return right_shift<Rep, Rad>(val, scale); }
166  return left_shift<Rep, Rad>(val, scale);
167 }
168 
169 } // namespace detail
170 
189 template <typename Rep,
190  typename cuda::std::enable_if_t<is_supported_representation_type<Rep>()>* = nullptr>
192  Rep value;
194 
200  CUDF_HOST_DEVICE inline explicit scaled_integer(Rep v, scale_type s) : value{v}, scale{s} {}
201 };
202 
212 template <typename Rep, Radix Rad>
213 class fixed_point {
214  Rep _value{};
215  scale_type _scale;
216 
217  public:
218  using rep = Rep;
219 
228  template <typename T,
229  typename cuda::std::enable_if_t<cuda::std::is_floating_point<T>() &&
230  is_supported_representation_type<Rep>()>* = nullptr>
231  CUDF_HOST_DEVICE inline explicit fixed_point(T const& value, scale_type const& scale)
232  : _value{static_cast<Rep>(detail::shift<Rep, Rad>(value, scale))}, _scale{scale}
233  {
234  }
235 
244  template <typename T,
245  typename cuda::std::enable_if_t<cuda::std::is_integral<T>() &&
246  is_supported_representation_type<Rep>()>* = nullptr>
247  CUDF_HOST_DEVICE inline explicit fixed_point(T const& value, scale_type const& scale)
248  // `value` is cast to `Rep` to avoid overflow in cases where
249  // constructing to `Rep` that is wider than `T`
250  : _value{detail::shift<Rep, Rad>(static_cast<Rep>(value), scale)}, _scale{scale}
251  {
252  }
253 
259  CUDF_HOST_DEVICE inline explicit fixed_point(scaled_integer<Rep> s)
260  : _value{s.value}, _scale{s.scale}
261  {
262  }
263 
271  template <typename T,
272  typename cuda::std::enable_if_t<is_supported_construction_value_type<T>()>* = nullptr>
273  CUDF_HOST_DEVICE inline fixed_point(T const& value)
274  : _value{static_cast<Rep>(value)}, _scale{scale_type{0}}
275  {
276  }
277 
282  CUDF_HOST_DEVICE inline fixed_point() : _scale{scale_type{0}} {}
283 
290  template <typename U,
291  typename cuda::std::enable_if_t<cuda::std::is_floating_point_v<U>>* = nullptr>
292  explicit constexpr operator U() const
293  {
294  return detail::shift<Rep, Rad>(static_cast<U>(_value), scale_type{-_scale});
295  }
296 
303  template <typename U, typename cuda::std::enable_if_t<cuda::std::is_integral_v<U>>* = nullptr>
304  explicit constexpr operator U() const
305  {
306  // Cast to the larger of the two types (of U and Rep) before converting to Rep because in
307  // certain cases casting to U before shifting will result in integer overflow (i.e. if U =
308  // int32_t, Rep = int64_t and _value > 2 billion)
309  auto const value = std::common_type_t<U, Rep>(_value);
310  return static_cast<U>(detail::shift<Rep, Rad>(value, scale_type{-_scale}));
311  }
312 
318  CUDF_HOST_DEVICE inline operator scaled_integer<Rep>() const
319  {
320  return scaled_integer<Rep>{_value, _scale};
321  }
322 
328  CUDF_HOST_DEVICE inline rep value() const { return _value; }
329 
335  CUDF_HOST_DEVICE inline scale_type scale() const { return _scale; }
336 
342  CUDF_HOST_DEVICE inline explicit constexpr operator bool() const
343  {
344  return static_cast<bool>(_value);
345  }
346 
355  template <typename Rep1, Radix Rad1>
356  CUDF_HOST_DEVICE inline fixed_point<Rep1, Rad1>& operator+=(fixed_point<Rep1, Rad1> const& rhs)
357  {
358  *this = *this + rhs;
359  return *this;
360  }
361 
370  template <typename Rep1, Radix Rad1>
371  CUDF_HOST_DEVICE inline fixed_point<Rep1, Rad1>& operator*=(fixed_point<Rep1, Rad1> const& rhs)
372  {
373  *this = *this * rhs;
374  return *this;
375  }
376 
385  template <typename Rep1, Radix Rad1>
386  CUDF_HOST_DEVICE inline fixed_point<Rep1, Rad1>& operator-=(fixed_point<Rep1, Rad1> const& rhs)
387  {
388  *this = *this - rhs;
389  return *this;
390  }
391 
400  template <typename Rep1, Radix Rad1>
401  CUDF_HOST_DEVICE inline fixed_point<Rep1, Rad1>& operator/=(fixed_point<Rep1, Rad1> const& rhs)
402  {
403  *this = *this / rhs;
404  return *this;
405  }
406 
412  CUDF_HOST_DEVICE inline fixed_point<Rep, Rad>& operator++()
413  {
414  *this = *this + fixed_point<Rep, Rad>{1, scale_type{_scale}};
415  return *this;
416  }
417 
431  template <typename Rep1, Radix Rad1>
432  CUDF_HOST_DEVICE inline friend fixed_point<Rep1, Rad1> operator+(
433  fixed_point<Rep1, Rad1> const& lhs, fixed_point<Rep1, Rad1> const& rhs);
434 
448  template <typename Rep1, Radix Rad1>
449  CUDF_HOST_DEVICE inline friend fixed_point<Rep1, Rad1> operator-(
450  fixed_point<Rep1, Rad1> const& lhs, fixed_point<Rep1, Rad1> const& rhs);
451 
463  template <typename Rep1, Radix Rad1>
464  CUDF_HOST_DEVICE inline friend fixed_point<Rep1, Rad1> operator*(
465  fixed_point<Rep1, Rad1> const& lhs, fixed_point<Rep1, Rad1> const& rhs);
466 
478  template <typename Rep1, Radix Rad1>
479  CUDF_HOST_DEVICE inline friend fixed_point<Rep1, Rad1> operator/(
480  fixed_point<Rep1, Rad1> const& lhs, fixed_point<Rep1, Rad1> const& rhs);
481 
495  template <typename Rep1, Radix Rad1>
496  CUDF_HOST_DEVICE inline friend fixed_point<Rep1, Rad1> operator%(
497  fixed_point<Rep1, Rad1> const& lhs, fixed_point<Rep1, Rad1> const& rhs);
498 
512  template <typename Rep1, Radix Rad1>
513  CUDF_HOST_DEVICE inline friend bool operator==(fixed_point<Rep1, Rad1> const& lhs,
514  fixed_point<Rep1, Rad1> const& rhs);
515 
529  template <typename Rep1, Radix Rad1>
530  CUDF_HOST_DEVICE inline friend bool operator!=(fixed_point<Rep1, Rad1> const& lhs,
531  fixed_point<Rep1, Rad1> const& rhs);
532 
546  template <typename Rep1, Radix Rad1>
547  CUDF_HOST_DEVICE inline friend bool operator<=(fixed_point<Rep1, Rad1> const& lhs,
548  fixed_point<Rep1, Rad1> const& rhs);
549 
563  template <typename Rep1, Radix Rad1>
564  CUDF_HOST_DEVICE inline friend bool operator>=(fixed_point<Rep1, Rad1> const& lhs,
565  fixed_point<Rep1, Rad1> const& rhs);
566 
580  template <typename Rep1, Radix Rad1>
581  CUDF_HOST_DEVICE inline friend bool operator<(fixed_point<Rep1, Rad1> const& lhs,
582  fixed_point<Rep1, Rad1> const& rhs);
583 
597  template <typename Rep1, Radix Rad1>
598  CUDF_HOST_DEVICE inline friend bool operator>(fixed_point<Rep1, Rad1> const& lhs,
599  fixed_point<Rep1, Rad1> const& rhs);
600 
610  CUDF_HOST_DEVICE inline fixed_point<Rep, Rad> rescaled(scale_type scale) const
611  {
612  if (scale == _scale) { return *this; }
613  Rep const value = detail::shift<Rep, Rad>(_value, scale_type{scale - _scale});
615  }
616 
620  explicit operator std::string() const
621  {
622  if (_scale < 0) {
623  auto const av = detail::abs(_value);
624  Rep const n = detail::exp10<Rep>(-_scale);
625  Rep const f = av % n;
626  auto const num_zeros =
627  std::max(0, (-_scale - static_cast<int32_t>(detail::to_string(f).size())));
628  auto const zeros = std::string(num_zeros, '0');
629  auto const sign = _value < 0 ? std::string("-") : std::string();
630  return sign + detail::to_string(av / n) + std::string(".") + zeros +
631  detail::to_string(av % n);
632  }
633  auto const zeros = std::string(_scale, '0');
634  return detail::to_string(_value) + zeros;
635  }
636 };
637 
647 template <typename Rep, typename T>
648 CUDF_HOST_DEVICE inline auto addition_overflow(T lhs, T rhs)
649 {
650  return rhs > 0 ? lhs > cuda::std::numeric_limits<Rep>::max() - rhs
651  : lhs < cuda::std::numeric_limits<Rep>::min() - rhs;
652 }
653 
662 template <typename Rep, typename T>
663 CUDF_HOST_DEVICE inline auto subtraction_overflow(T lhs, T rhs)
664 {
665  return rhs > 0 ? lhs < cuda::std::numeric_limits<Rep>::min() + rhs
666  : lhs > cuda::std::numeric_limits<Rep>::max() + rhs;
667 }
668 
677 template <typename Rep, typename T>
678 CUDF_HOST_DEVICE inline auto division_overflow(T lhs, T rhs)
679 {
680  return lhs == cuda::std::numeric_limits<Rep>::min() && rhs == -1;
681 }
682 
691 template <typename Rep, typename T>
692 CUDF_HOST_DEVICE inline auto multiplication_overflow(T lhs, T rhs)
693 {
694  auto const min = cuda::std::numeric_limits<Rep>::min();
695  auto const max = cuda::std::numeric_limits<Rep>::max();
696  if (rhs > 0) { return lhs > max / rhs || lhs < min / rhs; }
697  if (rhs < -1) { return lhs > min / rhs || lhs < max / rhs; }
698  return rhs == -1 && lhs == min;
699 }
700 
701 // PLUS Operation
702 template <typename Rep1, Radix Rad1>
703 CUDF_HOST_DEVICE inline fixed_point<Rep1, Rad1> operator+(fixed_point<Rep1, Rad1> const& lhs,
704  fixed_point<Rep1, Rad1> const& rhs)
705 {
706  auto const scale = std::min(lhs._scale, rhs._scale);
707  auto const sum = lhs.rescaled(scale)._value + rhs.rescaled(scale)._value;
708 
709 #if defined(__CUDACC_DEBUG__)
710 
711  assert(!addition_overflow<Rep1>(lhs.rescaled(scale)._value, rhs.rescaled(scale)._value) &&
712  "fixed_point overflow");
713 
714 #endif
715 
716  return fixed_point<Rep1, Rad1>{scaled_integer<Rep1>{sum, scale}};
717 }
718 
719 // MINUS Operation
720 template <typename Rep1, Radix Rad1>
721 CUDF_HOST_DEVICE inline fixed_point<Rep1, Rad1> operator-(fixed_point<Rep1, Rad1> const& lhs,
722  fixed_point<Rep1, Rad1> const& rhs)
723 {
724  auto const scale = std::min(lhs._scale, rhs._scale);
725  auto const diff = lhs.rescaled(scale)._value - rhs.rescaled(scale)._value;
726 
727 #if defined(__CUDACC_DEBUG__)
728 
729  assert(!subtraction_overflow<Rep1>(lhs.rescaled(scale)._value, rhs.rescaled(scale)._value) &&
730  "fixed_point overflow");
731 
732 #endif
733 
734  return fixed_point<Rep1, Rad1>{scaled_integer<Rep1>{diff, scale}};
735 }
736 
737 // MULTIPLIES Operation
738 template <typename Rep1, Radix Rad1>
739 CUDF_HOST_DEVICE inline fixed_point<Rep1, Rad1> operator*(fixed_point<Rep1, Rad1> const& lhs,
740  fixed_point<Rep1, Rad1> const& rhs)
741 {
742 #if defined(__CUDACC_DEBUG__)
743 
744  assert(!multiplication_overflow<Rep1>(lhs._value, rhs._value) && "fixed_point overflow");
745 
746 #endif
747 
749  scaled_integer<Rep1>(lhs._value * rhs._value, scale_type{lhs._scale + rhs._scale})};
750 }
751 
752 // DIVISION Operation
753 template <typename Rep1, Radix Rad1>
754 CUDF_HOST_DEVICE inline fixed_point<Rep1, Rad1> operator/(fixed_point<Rep1, Rad1> const& lhs,
755  fixed_point<Rep1, Rad1> const& rhs)
756 {
757 #if defined(__CUDACC_DEBUG__)
758 
759  assert(!division_overflow<Rep1>(lhs._value, rhs._value) && "fixed_point overflow");
760 
761 #endif
762 
764  scaled_integer<Rep1>(lhs._value / rhs._value, scale_type{lhs._scale - rhs._scale})};
765 }
766 
767 // EQUALITY COMPARISON Operation
768 template <typename Rep1, Radix Rad1>
769 CUDF_HOST_DEVICE inline bool operator==(fixed_point<Rep1, Rad1> const& lhs,
770  fixed_point<Rep1, Rad1> const& rhs)
771 {
772  auto const scale = std::min(lhs._scale, rhs._scale);
773  return lhs.rescaled(scale)._value == rhs.rescaled(scale)._value;
774 }
775 
776 // EQUALITY NOT COMPARISON Operation
777 template <typename Rep1, Radix Rad1>
778 CUDF_HOST_DEVICE inline bool operator!=(fixed_point<Rep1, Rad1> const& lhs,
779  fixed_point<Rep1, Rad1> const& rhs)
780 {
781  auto const scale = std::min(lhs._scale, rhs._scale);
782  return lhs.rescaled(scale)._value != rhs.rescaled(scale)._value;
783 }
784 
785 // LESS THAN OR EQUAL TO Operation
786 template <typename Rep1, Radix Rad1>
787 CUDF_HOST_DEVICE inline bool operator<=(fixed_point<Rep1, Rad1> const& lhs,
788  fixed_point<Rep1, Rad1> const& rhs)
789 {
790  auto const scale = std::min(lhs._scale, rhs._scale);
791  return lhs.rescaled(scale)._value <= rhs.rescaled(scale)._value;
792 }
793 
794 // GREATER THAN OR EQUAL TO Operation
795 template <typename Rep1, Radix Rad1>
796 CUDF_HOST_DEVICE inline bool operator>=(fixed_point<Rep1, Rad1> const& lhs,
797  fixed_point<Rep1, Rad1> const& rhs)
798 {
799  auto const scale = std::min(lhs._scale, rhs._scale);
800  return lhs.rescaled(scale)._value >= rhs.rescaled(scale)._value;
801 }
802 
803 // LESS THAN Operation
804 template <typename Rep1, Radix Rad1>
805 CUDF_HOST_DEVICE inline bool operator<(fixed_point<Rep1, Rad1> const& lhs,
806  fixed_point<Rep1, Rad1> const& rhs)
807 {
808  auto const scale = std::min(lhs._scale, rhs._scale);
809  return lhs.rescaled(scale)._value < rhs.rescaled(scale)._value;
810 }
811 
812 // GREATER THAN Operation
813 template <typename Rep1, Radix Rad1>
814 CUDF_HOST_DEVICE inline bool operator>(fixed_point<Rep1, Rad1> const& lhs,
815  fixed_point<Rep1, Rad1> const& rhs)
816 {
817  auto const scale = std::min(lhs._scale, rhs._scale);
818  return lhs.rescaled(scale)._value > rhs.rescaled(scale)._value;
819 }
820 
821 // MODULO OPERATION
822 template <typename Rep1, Radix Rad1>
823 CUDF_HOST_DEVICE inline fixed_point<Rep1, Rad1> operator%(fixed_point<Rep1, Rad1> const& lhs,
824  fixed_point<Rep1, Rad1> const& rhs)
825 {
826  auto const scale = std::min(lhs._scale, rhs._scale);
827  auto const remainder = lhs.rescaled(scale)._value % rhs.rescaled(scale)._value;
828  return fixed_point<Rep1, Rad1>{scaled_integer<Rep1>{remainder, scale}};
829 }
830 
834  // end of group
836 } // namespace numeric
numeric::fixed_point::rescaled
CUDF_HOST_DEVICE fixed_point< Rep, Rad > rescaled(scale_type scale) const
Method for creating a fixed_point number with a new scale
Definition: fixed_point.hpp:610
numeric::fixed_point::scale
CUDF_HOST_DEVICE scale_type scale() const
Method that returns the scale of the fixed_point number.
Definition: fixed_point.hpp:335
numeric::multiplication_overflow
CUDF_HOST_DEVICE auto multiplication_overflow(T lhs, T rhs)
Function for identifying integer overflow when multiplying.
Definition: fixed_point.hpp:692
numeric::operator>=
CUDF_HOST_DEVICE bool operator>=(fixed_point< Rep1, Rad1 > const &lhs, fixed_point< Rep1, Rad1 > const &rhs)
Definition: fixed_point.hpp:796
numeric::fixed_point::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)
Definition: fixed_point.hpp:769
numeric::fixed_point::fixed_point
CUDF_HOST_DEVICE fixed_point()
Default constructor that constructs fixed_point number with a value and scale of zero.
Definition: fixed_point.hpp:282
numeric::Radix
Radix
Scoped enumerator to use when constructing fixed_point
Definition: fixed_point.hpp:49
numeric::fixed_point::operator-
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)
Definition: fixed_point.hpp:721
numeric::fixed_point::operator+=
CUDF_HOST_DEVICE fixed_point< Rep1, Rad1 > & operator+=(fixed_point< Rep1, Rad1 > const &rhs)
operator +=
Definition: fixed_point.hpp:356
numeric::operator+
CUDF_HOST_DEVICE fixed_point< Rep1, Rad1 > operator+(fixed_point< Rep1, Rad1 > const &lhs, fixed_point< Rep1, Rad1 > const &rhs)
Definition: fixed_point.hpp:703
numeric::fixed_point
A type for representing a number with a fixed amount of precision.
Definition: fixed_point.hpp:213
numeric::operator/
CUDF_HOST_DEVICE fixed_point< Rep1, Rad1 > operator/(fixed_point< Rep1, Rad1 > const &lhs, fixed_point< Rep1, Rad1 > const &rhs)
Definition: fixed_point.hpp:754
types.hpp
Type declarations for libcudf.
numeric::fixed_point::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)
Definition: fixed_point.hpp:778
numeric::fixed_point::operator/=
CUDF_HOST_DEVICE fixed_point< Rep1, Rad1 > & operator/=(fixed_point< Rep1, Rad1 > const &rhs)
operator /=
Definition: fixed_point.hpp:401
numeric::scaled_integer::scale
scale_type scale
The scale of the value.
Definition: fixed_point.hpp:193
numeric::fixed_point::operator++
CUDF_HOST_DEVICE fixed_point< Rep, Rad > & operator++()
operator ++ (post-increment)
Definition: fixed_point.hpp:412
numeric::detail::left_shift
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
Definition: fixed_point.hpp:143
numeric::detail::ipow
CUDF_HOST_DEVICE Rep ipow(T exponent)
A function for integer exponentiation by squaring.
Definition: fixed_point.hpp:96
numeric::fixed_point::rep
Rep rep
The representation type.
Definition: fixed_point.hpp:218
numeric::fixed_point::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)
Definition: fixed_point.hpp:814
numeric::fixed_point::operator*=
CUDF_HOST_DEVICE fixed_point< Rep1, Rad1 > & operator*=(fixed_point< Rep1, Rad1 > const &rhs)
operator *=
Definition: fixed_point.hpp:371
numeric::fixed_point::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)
Definition: fixed_point.hpp:754
numeric::is_supported_construction_value_type
constexpr auto is_supported_construction_value_type()
Returns true if the value type is supported for constructing a fixed_point
Definition: fixed_point.hpp:72
numeric::subtraction_overflow
CUDF_HOST_DEVICE auto subtraction_overflow(T lhs, T rhs)
Function for identifying integer overflow when subtracting.
Definition: fixed_point.hpp:663
numeric::operator*
CUDF_HOST_DEVICE fixed_point< Rep1, Rad1 > operator*(fixed_point< Rep1, Rad1 > const &lhs, fixed_point< Rep1, Rad1 > const &rhs)
Definition: fixed_point.hpp:739
numeric::fixed_point::operator%
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)
Definition: fixed_point.hpp:823
numeric::scaled_integer
Helper struct for constructing fixed_point when value is already shifted.
Definition: fixed_point.hpp:191
numeric::fixed_point::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)
Definition: fixed_point.hpp:703
numeric::addition_overflow
CUDF_HOST_DEVICE auto addition_overflow(T lhs, T rhs)
Function for identifying integer overflow when adding.
Definition: fixed_point.hpp:648
numeric::is_supported_representation_type
constexpr auto is_supported_representation_type()
Returns true if the representation type is supported by fixed_point
Definition: fixed_point.hpp:58
numeric::operator-
CUDF_HOST_DEVICE fixed_point< Rep1, Rad1 > operator-(fixed_point< Rep1, Rad1 > const &lhs, fixed_point< Rep1, Rad1 > const &rhs)
Definition: fixed_point.hpp:721
numeric::scaled_integer::scaled_integer
CUDF_HOST_DEVICE scaled_integer(Rep v, scale_type s)
Constructor for scaled_integer
Definition: fixed_point.hpp:200
numeric::division_overflow
CUDF_HOST_DEVICE auto division_overflow(T lhs, T rhs)
Function for identifying integer overflow when dividing.
Definition: fixed_point.hpp:678
numeric::scaled_integer::value
Rep value
The value of the fixed point number.
Definition: fixed_point.hpp:192
numeric::operator>
CUDF_HOST_DEVICE bool operator>(fixed_point< Rep1, Rad1 > const &lhs, fixed_point< Rep1, Rad1 > const &rhs)
Definition: fixed_point.hpp:814
numeric::detail::right_shift
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
Definition: fixed_point.hpp:126
numeric::fixed_point::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)
Definition: fixed_point.hpp:796
numeric::fixed_point::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)
Definition: fixed_point.hpp:805
numeric::fixed_point::value
CUDF_HOST_DEVICE rep value() const
Method that returns the underlying value of the fixed_point number.
Definition: fixed_point.hpp:328
numeric::fixed_point::operator-=
CUDF_HOST_DEVICE fixed_point< Rep1, Rad1 > & operator-=(fixed_point< Rep1, Rad1 > const &rhs)
operator -=
Definition: fixed_point.hpp:386
numeric::fixed_point::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)
Definition: fixed_point.hpp:787
numeric::operator==
CUDF_HOST_DEVICE bool operator==(fixed_point< Rep1, Rad1 > const &lhs, fixed_point< Rep1, Rad1 > const &rhs)
Definition: fixed_point.hpp:769
numeric::fixed_point::operator*
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)
Definition: fixed_point.hpp:739
numeric::operator<
CUDF_HOST_DEVICE bool operator<(fixed_point< Rep1, Rad1 > const &lhs, fixed_point< Rep1, Rad1 > const &rhs)
Definition: fixed_point.hpp:805
numeric::operator%
CUDF_HOST_DEVICE fixed_point< Rep1, Rad1 > operator%(fixed_point< Rep1, Rad1 > const &lhs, fixed_point< Rep1, Rad1 > const &rhs)
Definition: fixed_point.hpp:823
numeric::scale_type
scale_type
The scale type for fixed_point.
Definition: fixed_point.hpp:38
numeric::operator<=
CUDF_HOST_DEVICE bool operator<=(fixed_point< Rep1, Rad1 > const &lhs, fixed_point< Rep1, Rad1 > const &rhs)
Definition: fixed_point.hpp:787
numeric
fixed_point and supporting types
Definition: fixed_point.hpp:35
numeric::operator!=
CUDF_HOST_DEVICE bool operator!=(fixed_point< Rep1, Rad1 > const &lhs, fixed_point< Rep1, Rad1 > const &rhs)
Definition: fixed_point.hpp:778