17#ifndef SPARROW_USE_LARGE_INT_PLACEHOLDERS
20# if defined(__clang__) || defined(__GNUC__)
21# pragma GCC diagnostic push
22# pragma GCC diagnostic ignored "-Wold-style-cast"
23# pragma GCC diagnostic ignored "-Wsign-conversion"
24# pragma GCC diagnostic ignored "-Wshadow"
26# include <sparrow/details/3rdparty/large_integers/int128_t.hpp>
27# include <sparrow/details/3rdparty/large_integers/int256_t.hpp>
29# if defined(__clang__) || defined(__GNUC__)
30# pragma GCC diagnostic pop
40#ifdef SPARROW_USE_LARGE_INT_PLACEHOLDERS
47 std::uint64_t words[2];
51 return words[0] == other.words[0] && words[1] == other.words[1];
54 bool operator!=(
const int128_t& other)
const
56 return !(*
this == other);
63 std::uint64_t words[4];
67 return words[0] == other.words[0] && words[1] == other.words[1] && words[2] == other.words[2]
68 && words[3] == other.words[3];
71 bool operator!=(
const int256_t& other)
const
73 return !(*
this == other);
77 constexpr bool is_int_placeholder_v = std::is_same_v<T, int128_t> || std::is_same_v<T, int256_t>;
95 bool negative =
false;
96 for (
auto it = str.begin(); it != str.end(); ++it)
100 if (it == str.begin())
107 throw std::invalid_argument(
"Invalid character in string for conversion to large integer");
110 else if (*it <
'0' || *it >
'9')
112 throw std::invalid_argument(
"Invalid character in string for conversion to large integer");
115 digits += T(*it -
'0');
127#if defined(__cpp_lib_format)
134template <
class charT>
137 template <
class ParseContext>
138 constexpr ParseContext::iterator parse(ParseContext& ctx)
143 template <
class FmtContext>
146# ifdef SPARROW_USE_LARGE_INT_PLACEHOLDERS
147 return std::format_to(ctx.out(),
"int128_t({}, {})", n.words[0], n.words[1]);
149 const std::string str = primesum::to_string(n);
150 return std::format_to(ctx.out(),
"{}", str);
155template <
class charT>
158 template <
class ParseContext>
159 constexpr ParseContext::iterator parse(ParseContext& ctx)
164 template <
class FmtContext>
167# ifdef SPARROW_USE_LARGE_INT_PLACEHOLDERS
168 return std::format_to(ctx.out(),
"int256_t({}, {}, {}, {})", n.words[0], n.words[1], n.words[2], n.words[3]);
170 const std::string str = primesum::to_string(n);
171 return std::format_to(ctx.out(),
"{}", str);
primesum::int128_t int128_t
SPARROW_API bool operator==(const array &lhs, const array &rhs)
Compares the content of two arrays.
constexpr bool is_int_placeholder_v
constexpr bool large_int_placeholders
primesum::int256_t int256_t
T stobigint(std::string_view str)