18template<
typename Integer =
int>
48 std::cout <<
"baseConverter.status()"
50 <<
"\tBase: " << this->m_base <<
"\n"
51 <<
"\tLength: " << this->m_length <<
"\n"
52 <<
"\tMax: " << this->m_max - 1 <<
"\n"
53 <<
"\tRegistered value: " << this->m_register << std::endl;
55 __host__ __device__ Integer
base()
const {
return this->
m_base; }
57 __host__ __device__ Integer
maxVal()
const {
return this->
m_max; }
70 template<
typename Input,
71 typename std::enable_if_t< !std::is_integral_v<Input> >* =
nullptr >
73 static_assert(std::is_integral<Input>::value ==
false);
74 Integer num = 0,
base = 1;
75 for(Integer pos = 0; pos <
m_length; ++pos) {
79 this->m_register = num;
82 template<
typename Input>
84 static_assert(std::is_integral<Input>::value ==
true);
85 this->m_register = num;
96 this->m_length = Length;
97 this->m_max = powi(Base, Length);
113 __host__ __device__ Integer
digit(Integer
const num, Integer
const pos, Integer
const base,
114 Integer
const length)
const {
119 __host__ __device__ Integer
digit(Integer
const num, Integer
const pos)
const {
122 __host__ __device__ Integer
digit(Integer
const pos)
const {
139 __host__ __device__ Integer
shiftDigits(Integer
const num, Integer
const trans,
140 Integer
const base, Integer
const length)
const {
143 Integer temp = powi(
base, Trans);
144 return (num / temp) + (num % temp) * powi(
base,
length - Trans);
147 __host__ __device__ Integer
shiftDigits(Integer
const num, Integer
const trans)
const {
165 template<
typename Input>
167 Integer
const length)
const {
168 Integer res = 0, p = 1;
169 for(
int l =
length - 1; l >= 0; --l) {
170 res += p * digits[l];
175 template<
typename Input>
190 template<
typename Output>
192 Integer
const base, Integer
const length)
const ->
193 typename std::enable_if< std::is_integral<Output>::value ==
false,
195 static_assert(std::is_integral<Output>::value ==
false);
198 std::cerr <<
"Warning:" << __PRETTY_FUNCTION__ <<
"\n\t"
200 <<
") cannot be expressed with base " <<
base <<
" and length " <<
length
205 for(
int l = 0; l <
length; ++l) {
210 template<
typename Output>
211 __host__ __device__
auto printInDigits(Output& output, Integer
const num)
const ->
212 typename std::enable_if< std::is_integral<Output>::value ==
false,
214 static_assert(std::is_integral<Output>::value ==
false);
218 template<
typename Output,
219 typename std::enable_if_t< !std::is_integral_v<Output> >* =
nullptr >
221 static_assert(std::is_integral<Output>::value ==
false);
227 Integer
const length)
const {
229 std::cerr <<
"Warning(" << __func__ <<
"): Input(" << num
230 <<
") cannot be expressed with base " <<
base <<
" and length " <<
length
233 for(
int l =
length - 1; l >= 0; --l) {
236 std::cout << std::endl;
Provides utilities for converting an integer to the corresponding expression in the positional notati...
Definition BaseNnumber.hpp:19
__host__ __device__ Integer value() const
Definition BaseNnumber.hpp:58
__host__ __device__ Integer shiftDigits(Integer const num, Integer const trans) const
Definition BaseNnumber.hpp:147
__host__ __device__ BaseConverter(BaseConverter< Integer > const &other)
Definition BaseNnumber.hpp:37
__host__ BaseConverter const & printInDigits(Integer const num) const
Definition BaseNnumber.hpp:240
__host__ BaseConverter const & printInDigits() const
Definition BaseNnumber.hpp:245
Integer m_max
Definition BaseNnumber.hpp:23
__host__ __device__ BaseConverter & setParam(Integer Base, Integer Length)
Set the base and the length of the positional notation to which the input number will converted.
Definition BaseNnumber.hpp:94
__host__ __device__ BaseConverter const & shiftDigits(Integer const trans) const
Definition BaseNnumber.hpp:151
__host__ __device__ Integer digit(Integer const num, Integer const pos, Integer const base, Integer const length) const
Returns the (pos)-th digit of the input (num) in given base and length.
Definition BaseNnumber.hpp:113
__host__ __device__ Integer digitsToNumber(Input const &digits) const
Definition BaseNnumber.hpp:176
__host__ __device__ Integer maxVal() const
Definition BaseNnumber.hpp:57
Integer m_length
Definition BaseNnumber.hpp:22
__host__ __device__ Integer base() const
Definition BaseNnumber.hpp:55
__host__ __device__ Integer digit(Integer const num, Integer const pos) const
Definition BaseNnumber.hpp:119
Integer m_base
Definition BaseNnumber.hpp:21
__host__ __device__ BaseConverter const & printInDigits(Output &output) const
Definition BaseNnumber.hpp:220
__host__ __device__ Integer shiftDigits(Integer const num, Integer const trans, Integer const base, Integer const length) const
Shifts a number (num) to right by (trans) in terms of the positional notation with given base and len...
Definition BaseNnumber.hpp:139
__host__ __device__ BaseConverter(Integer Base, Integer Length)
Construct a new BaseConverter object.
Definition BaseNnumber.hpp:34
__host__ __device__ Integer digit(Integer const pos) const
Definition BaseNnumber.hpp:122
__host__ __device__ BaseConverter const & set(Input num) const
Definition BaseNnumber.hpp:83
__host__ __device__ BaseConverter const & set(Input config) const
Definition BaseNnumber.hpp:72
__host__ __device__ Integer digitsToNumber(Input const &digits, Integer const base, Integer const length) const
Converts an array of integers to the corresponding integer in terms of the positional notation with g...
Definition BaseNnumber.hpp:166
__host__ __device__ Integer length() const
Definition BaseNnumber.hpp:56
Integer m_register
Definition BaseNnumber.hpp:24
__host__ void status(void) const
Show the status of the instance.
Definition BaseNnumber.hpp:47
__host__ __device__ BaseConverter()
Definition BaseNnumber.hpp:27
__host__ __device__ auto printInDigits(Output &output, Integer const num, Integer const base, Integer const length) const -> typename std::enable_if< std::is_integral< Output >::value==false, BaseConverter const & >::type
Expresses an integer (num) in the positional notation with given (base) and (length)
Definition BaseNnumber.hpp:191
__host__ __device__ auto printInDigits(Output &output, Integer const num) const -> typename std::enable_if< std::is_integral< Output >::value==false, BaseConverter const & >::type
Definition BaseNnumber.hpp:211
__host__ BaseConverter const & printInDigits(Integer const num, Integer const base, Integer const length) const
Definition BaseNnumber.hpp:226