5 #include <libutl/Number.h> 38 virtual size_t hash(
size_t size)
const;
114 return (
size_t)(this->_n % size);
124 if (!isdigit(c) && (c !=
'-') && (c !=
'+'))
goto fail;
125 if (std::is_signed<T>())
127 this->_n = strtol(str,
nullptr, 0);
131 this->_n = strtoul(str,
nullptr, 0);
133 if (errno == EINVAL)
goto fail;
146 if (!isdigit(str[0]))
goto fail;
147 if (std::is_signed<T>())
149 this->_n = strtol(str,
nullptr, 2);
153 this->_n = strtoul(str,
nullptr, 2);
155 if (errno == EINVAL)
goto fail;
169 if (!isxdigit(str[0]))
goto fail;
170 if (std::is_signed<T>())
172 this->_n = strtol(str,
nullptr, 16);
176 this->_n = strtoul(str,
nullptr, 16);
178 if (errno == EINVAL)
goto fail;
192 uint64_t n = (this->_n < 0) ? -1 * this->_n : this->_n;
196 while (((n & (1ULL << (numDigits - 1))) == 0) && (numDigits > 1))
202 char* res =
new char[numDigits + 2];
222 ASSERTD((resChar + 1 - res) <= (numDigits + 2));
223 return String(res,
true,
false);
232 if (numDigits == 0)
return this->
toString();
236 sprintf(buf, fmt, (
int)numDigits, this->_n);
257 sprintf(buf, fmt, (
int)numDigits, this->_n);
278 sprintf(buf, fmt, (
int)numDigits, this->_n);
#define UTL_CLASS_IMPL_TPL(className, T)
Implementation of standard UTL++ functionality for a template class.
#define UTL_CLASS_DEFID
Default init() and deInit() (which are merely place-holders).
String toString(const FwdIt &begin, const FwdIt &end, const String &sep, bool key=false)
Obtain a string representation of a sequence (via Object::toString()).
bool isDivisibleBy(const T &x, const T &n)
Determine whether x is evenly divisible by n.
unsigned long uint64_t
Unsigned 64-bit integer.
bool isDivisibleBy(T num) const
Determine whether self is divisible by the given number.
unsigned int uint_t
Unsigned integer.
Provide printf formatting strings for common types.
#define UTL_CLASS_DECL_TPL(DC, T, BC)
Declaration of standard UTL++ functionality for a template class with one parameter.
Integer< T > mod(const Integer< T > &rhs) const
Get the result of self modulo rhs.
Integer< T > nextMultiple(T target) const
Determine the smallest number n, s.t.
#define ASSERTD
Do an assertion in DEBUG mode only.
T nextMultiple(const T &x, const T &target)
Return the smallest number n s.t.