21template<
typename T,
int S>
22inline void UIntF<T, S>::set_from_str(
const StringRefNull
str,
const int base)
26 mpz_set_str(
x,
str.c_str(), base);
27 for (
int i = 0; i < S; i++) {
28 static_assert(
sizeof(
T) <=
sizeof(
decltype(mpz_get_ui(
x))));
29 this->
v[i] =
T(mpz_get_ui(
x));
30 mpz_div_2exp(
x,
x, 8 *
sizeof(T));
35template<
typename T,
int S>
36inline void IntF<T, S>::set_from_str(
const StringRefNull
str,
const int base)
39 const UIntF<T, S> unsigned_value(
str.c_str() + 1, base);
40 this->
v = unsigned_value.v;
44 const UIntF<T, S> unsigned_value(
str.c_str(), base);
45 this->
v = unsigned_value.v;
49template<
typename T,
int S>
inline std::string UIntF<T, S>::to_string(
const int base)
const
53 for (
int i = S - 1; i >= 0; i--) {
54 static_assert(
sizeof(
T) <=
sizeof(
decltype(mpz_get_ui(
x))));
55 mpz_mul_2exp(
x,
x, 8 *
sizeof(T));
56 mpz_add_ui(
x,
x, this->
v[i]);
60 const int str_size = mpz_sizeinbase(
x, base) + 2;
61 Array<char, 1024>
str(str_size);
62 mpz_get_str(
str.data(), base,
x);
64 return std::string(
str.data());
67template<
typename T,
int S>
inline std::string IntF<T, S>::to_string(
const int base)
const
70 std::string
str = UIntF<T, S>(-*
this).to_string(base);
71 str.insert(
str.begin(),
'-');
74 return UIntF<T, S>(*this).to_string();
ATTR_WARN_UNUSED_RESULT const BMVert * v
bool is_negative(const IntF< T, Size > &a)