8#include "../bool/bool.hpp"
9#include "../circuit_builders/circuit_builders.hpp"
15template <
typename Builder>
40template <
typename Builder>
42 const size_t difference_bit_size,
43 std::string
const& description)
const
84 safe_uint_t<Builder> difference(difference_val, (
size_t)(current_max.get_msb() + 1),
"- operator");
96 throw_or_abort(
"maximum value exceeded in safe_uint minus operator");
111template <
typename Builder>
114 const size_t quotient_bit_size,
115 const size_t remainder_bit_size,
116 std::string
const& description,
128 remainder_field, remainder_bit_size,
format(
"divide method remainder: ", description));
131 safe_uint_t int_val = quotient * other + remainder;
137 other - remainder_plus_one;
139 this->assert_equal(int_val,
"divide method quotient and/or remainder incorrect");
165 safe_uint_t int_val = quotient * other + remainder;
171 other - remainder_plus_one;
173 this->assert_equal(int_val,
"/ operator quotient and/or remainder incorrect");
181 auto norm_value =
value.normalize();
182 return safe_uint_t(norm_value, current_max, IS_UNSAFE);
187 value.assert_is_zero(msg);
192 value.assert_is_not_zero(msg);
202 return value.get_value();
212 return !operator==(other);
214template <
typename Builder>
226 const auto msb_plus_one = uint32_t(msb) + 1;
227 const auto hi_mask = ((
uint256_t(1) << (256 - uint32_t(msb))) - 1);
228 const auto hi = (
value >> msb_plus_one) & hi_mask;
230 const auto lo_mask = (
uint256_t(1) << lsb) - 1;
231 const auto lo =
value & lo_mask;
233 const auto slice_mask = ((
uint256_t(1) << (uint32_t(msb - lsb) + 1)) - 1);
234 const auto slice = (
value >> lsb) & slice_mask;
236 if (this->value.is_constant()) {
#define BB_ASSERT_GTE(left, right,...)
#define BB_ASSERT_EQ(actual, expected,...)
#define BB_ASSERT_LTE(left, right,...)
#define BB_ASSERT_LT(left, right,...)
#define ASSERT(expression,...)
constexpr std::pair< uint256_t, uint256_t > divmod(const uint256_t &b) const
constexpr uint64_t get_msb() const
Implements boolean logic in-circuit.
bb::fr get_value() const
Given a := *this, compute its value given by a.v * a.mul + a.add.
void assert_is_zero(std::string const &msg="safe_uint_t::assert_is_zero") const
safe_uint_t subtract(const safe_uint_t &other, const size_t difference_bit_size, std::string const &description="") const
Subtraction when you have a pre-determined bound on the difference size.
safe_uint_t operator/(const safe_uint_t &other) const
Potentially less efficient than divide function - bounds remainder and quotient by max of this.
OriginTag get_origin_tag() const
safe_uint_t normalize() const
std::array< safe_uint_t< Builder >, 3 > slice(const uint8_t msb, const uint8_t lsb) const
bool_ct operator==(const safe_uint_t &other) const
safe_uint_t operator-(const safe_uint_t &other) const
Subtraction on two safe_uint_t objects.
void set_origin_tag(OriginTag tag) const
Builder * get_context() const
safe_uint_t operator*(const safe_uint_t &other) const
safe_uint_t operator+(const safe_uint_t &other) const
bool_ct operator!=(const safe_uint_t &other) const
safe_uint_t divide(const safe_uint_t &other, const size_t quotient_bit_size, const size_t remainder_bit_size, std::string const &description="", const std::function< std::pair< uint256_t, uint256_t >(uint256_t, uint256_t)> &get_quotient=[](uint256_t val, uint256_t divisor) { return std::make_pair((uint256_t)(val/(uint256_t) divisor),(uint256_t)(val %(uint256_t) divisor));}) const
division when you have a pre-determined bound on the sizes of the quotient and remainder
void assert_is_not_zero(std::string const &msg="safe_uint_t::assert_is_not_zero") const
std::string format(Args... args)
constexpr size_t MAX_NO_WRAP_INTEGER_BIT_LENGTH
uintx< uint256_t > uint512_t
std::conditional_t< IsGoblinBigGroup< C, Fq, Fr, G >, element_goblin::goblin_element< C, goblin_field< C >, Fr, G >, element_default::element< C, Fq, Fr, G > > element
element wraps either element_default::element or element_goblin::goblin_element depending on parametr...
C slice(C const &container, size_t start)
constexpr decltype(auto) get(::tuplet::tuple< T... > &&t) noexcept
BB_INLINE constexpr bool is_zero() const noexcept
void throw_or_abort(std::string const &err)