25#include "lmmc/config.h"
42 mp_ptr data_ =
nullptr;
44 mp_size_t capacity_ = 0;
47 void realloc_to(mp_size_t new_alloc);
53 void import_unsigned(std::uint64_t magnitude);
54 std::optional<std::uint64_t> magnitude_uint64() const noexcept;
63 BigInt(const BigInt& other);
66 BigInt(BigInt&& other) noexcept;
69 BigInt& operator=(const BigInt& other);
72 BigInt& operator=(BigInt&& other) noexcept;
75 BigInt(std::int64_t value);
77 BigInt(std::uint64_t value);
79 BigInt(
unsigned int value);
81 template <typename Integer,
82 std::enable_if_t<std::is_integral_v<Integer> &&
83 sizeof(Integer) <= sizeof(std::uint64_t) &&
84 !std::is_same_v<Integer,
int> &&
85 !std::is_same_v<Integer,
unsigned int> &&
86 !std::is_same_v<Integer, std::int64_t> &&
87 !std::is_same_v<Integer, std::uint64_t>,
int> = 0>
89 : BigInt(static_cast<std::conditional_t<std::is_signed_v<Integer>,
90 std::int64_t, std::uint64_t>>(value)) {}
97 BigInt(
const std::string& str);
103 std::string to_string()
const;
112 std::optional<std::int64_t> try_to_int64() const noexcept;
115 std::optional<std::uint64_t> try_to_uint64() const noexcept;
117 std::
size_t bit_length() const noexcept;
123 lmmc_real_t to_double() const;
131 static
int cmp_abs(const BigInt& a, const BigInt& b);
133 bool operator==(const BigInt& other) const;
134 bool operator!=(const BigInt& other) const;
135 bool operator<(const BigInt& other) const;
136 bool operator>(const BigInt& other) const;
137 bool operator<=(const BigInt& other) const;
138 bool operator>=(const BigInt& other) const;
139 bool operator!() const;
140 explicit operator
bool() const;
143 bool is_zero() const;
149 std::vector<uint64_t> get_digits() const;
155 std::
size_t hash() const;
164 bool is_negative() const;
170 BigInt negate() const;
173 BigInt operator-() const;
181 static
void add_abs(BigInt& dst, const BigInt& a, const BigInt& b);
189 static
void sub_abs(BigInt& dst, const BigInt& a, const BigInt& b);
192 BigInt operator+(const BigInt& other) const;
195 BigInt operator-(const BigInt& other) const;
198 BigInt operator*(const BigInt& other) const;
206 BigInt operator/(const BigInt& other) const;
214 BigInt operator%(const BigInt& other) const;
216 BigInt& operator+=(const BigInt& other);
217 BigInt& operator-=(const BigInt& other);
218 BigInt& operator*=(const BigInt& other);
219 BigInt& operator/=(const BigInt& other);
220 BigInt& operator%=(const BigInt& other);
227 BigInt power(
unsigned long exp) const;
235 BigInt power(BigInt exp) const;
248 bool is_even() const;
254 mp_size_t trailing_zeros() const;
261 BigInt& operator>>=(mp_size_t shift);
268 BigInt& operator<<=(mp_size_t shift);
271 BigInt operator>>(mp_size_t shift) const;
274 BigInt operator<<(mp_size_t shift) const;
281 static BigInt factorial(const BigInt& n);
282 static Result<BigInt> factorial_checked(const BigInt& n, ComputationContext& context);
283 static Result<BigInt> factorial_checked(const BigInt& n);
291 static BigInt npr(const BigInt& n, const BigInt& r);
292 static Result<BigInt> npr_checked(const BigInt& n, const BigInt& r,
293 ComputationContext& context);
294 static Result<BigInt> npr_checked(const BigInt& n, const BigInt& r);
302 static BigInt ncr(const BigInt& n, const BigInt& r);
303 static Result<BigInt> ncr_checked(const BigInt& n, const BigInt& r,
304 ComputationContext& context);
305 static Result<BigInt> ncr_checked(const BigInt& n, const BigInt& r);
314 static BigInt multinomial(
unsigned int n, const std::vector<
unsigned int>& r);
322 static BigInt gcd(const BigInt& a, const BigInt& b);
330 static BigInt lcm(const BigInt& a, const BigInt& b);
340 static BigInt pow_mod(const BigInt& base, const BigInt& exp, const BigInt& mod);
347 Result<
bool> is_prime_checked() const;
353 bool is_perfect_square() const;
ExpressionResult normalize(const Node &value, ComputationContext &context)
Sign
Sign classification for symbols and expressions.