20#include "bytes_view.h"
22#include "detail/config.h"
23#include "detail/mpi.h"
38 friend class big_decimal;
40 using mpi_t = detail::mpi;
41 using word_t = mpi_t::word;
45 using mag_array_view = mpi_t::mag_view;
97 big_integer(
const std::int8_t *val, std::int32_t len, std::int8_t sign,
bool big_endian =
true);
105 big_integer(
const std::byte *data, std::size_t size);
130 if (&other == &this->m_mpi) {
148 if (&other == &this->m_mpi) {
191 [[nodiscard]] std::int8_t
get_sign() const noexcept {
return std::int8_t(m_mpi.sign()); }
198 [[nodiscard]] mag_array_view
get_magnitude() const noexcept {
return m_mpi.magnitude(); }
205 [[nodiscard]] std::uint32_t
bit_length() const noexcept;
212 [[nodiscard]] std::
size_t byte_size() const noexcept;
227 [[nodiscard]] std::vector<std::
byte>
to_bytes()
const {
228 std::vector<std::byte> bytes(
byte_size());
246 void pow(std::int32_t exp);
294 void add(std::uint64_t x);
311 [[nodiscard]] std::int64_t
to_int64() const;
318 [[nodiscard]]
bool is_negative() const noexcept {
return m_mpi.is_negative(); }
325 [[nodiscard]]
bool is_zero() const noexcept {
return m_mpi.is_zero(); }
332 [[nodiscard]]
bool is_positive() const noexcept {
return m_mpi.is_positive(); }
342 [[nodiscard]] std::string
to_string()
const;
383 [[nodiscard]] std::uint32_t magnitude_bit_length() const noexcept;
403 void from_binary(const std::uint8_t *data, std::
size_t size,
bool negative = false);
419 return lhs.compare(rhs) == 0;
430 return lhs.compare(rhs) != 0;
441 return lhs.compare(rhs) < 0;
452 return lhs.compare(rhs) <= 0;
463 return lhs.compare(rhs) > 0;
474 return lhs.compare(rhs) >= 0;
499 lhs.subtract(rhs, res);
512 lhs.multiply(rhs, res);
525 lhs.divide(rhs, res);
539 lhs.divide(rhs, res, rem);
Definition big_integer.h:37
void assign_string(const std::string &val)
Definition big_integer.cpp:90
void assign_int64(std::int64_t val)
Definition big_integer.cpp:63
big_integer(big_integer &&other) noexcept=default
friend std::ostream & operator<<(std::ostream &os, const big_integer &val)
Definition big_integer.cpp:258
bool is_positive() const noexcept
Definition big_integer.h:332
void store_bytes(std::byte *data) const
Definition big_integer.cpp:133
void add(const big_integer &other, big_integer &res) const
Definition big_integer.cpp:196
std::int32_t get_precision() const noexcept
Definition big_integer.cpp:153
std::size_t byte_size() const noexcept
Definition big_integer.cpp:128
big_integer & operator=(const big_integer &other)=default
std::int64_t to_int64() const
Definition big_integer.cpp:232
big_integer(const char *val, std::int32_t len)
Definition big_integer.h:86
std::vector< std::byte > to_bytes() const
Definition big_integer.h:227
void pow(std::int32_t exp)
Definition big_integer.cpp:170
mag_array_view get_magnitude() const noexcept
Definition big_integer.h:198
big_integer & operator=(const mpi_t &other)
Definition big_integer.h:129
static void get_power_of_ten(std::int32_t pow, big_integer &res)
Definition big_integer.cpp:239
std::string to_string() const
Definition big_integer.cpp:254
friend std::istream & operator>>(std::istream &is, big_integer &val)
Definition big_integer.cpp:262
friend void swap(big_integer &lhs, big_integer &rhs)
Definition big_integer.cpp:287
bool is_negative() const noexcept
Definition big_integer.h:318
big_integer(const std::string &val)
Definition big_integer.h:78
big_integer(const big_integer &other)=default
big_integer & operator=(mpi_t &&other) noexcept
Definition big_integer.h:145
std::int8_t get_sign() const noexcept
Definition big_integer.h:191
big_integer(std::int64_t val)
Definition big_integer.h:71
big_integer & operator=(big_integer &&other) noexcept=default
bool is_zero() const noexcept
Definition big_integer.h:325
void divide(const big_integer &divisor, big_integer &res) const
Definition big_integer.cpp:188
big_integer(const std::int8_t *val, std::int32_t len, std::int8_t sign, bool big_endian=true)
void multiply(const big_integer &other, big_integer &res) const
Definition big_integer.cpp:184
std::uint32_t bit_length() const noexcept
Definition big_integer.cpp:102
void subtract(const big_integer &other, big_integer &res) const
Definition big_integer.cpp:200
void assign_uint64(std::uint64_t val)
Definition big_integer.cpp:72
void negate()
Definition big_integer.h:337
int compare(const big_integer &other, bool ignore_sign=false) const
Definition big_integer.cpp:228