mirror of
https://github.com/Z3Prover/z3
synced 2025-04-27 10:55:50 +00:00
u256
Signed-off-by: Nikolaj Bjorner <nbjorner@microsoft.com>
This commit is contained in:
parent
ff717a9db1
commit
e19a7f71aa
3 changed files with 100 additions and 4 deletions
|
@ -1,17 +1,52 @@
|
|||
#pragma once
|
||||
|
||||
#include "util/util.h"
|
||||
#include "util/rational.h"
|
||||
|
||||
class u256 {
|
||||
uint64_t m_num[4];
|
||||
u256(uint64_t const* v);
|
||||
public:
|
||||
u256();
|
||||
u256(uint64_t n);
|
||||
u256(uint64_t const* v);
|
||||
u256(rational const& n);
|
||||
u256 operator*(u256 const& other) const;
|
||||
u256 operator+(u256 const& other) const { u256 r = *this; return r += other; }
|
||||
u256 operator-(u256 const& other) const { u256 r = *this; return r -= other; }
|
||||
u256 operator-() const { u256 r = *this; return r.inv(); }
|
||||
|
||||
u256 mul_inverse() const;
|
||||
unsigned trailing_zeros() const;
|
||||
u256 gcd(u256 const& other) const;
|
||||
|
||||
// updates
|
||||
void reset() { m_num[0] = m_num[1] = m_num[2] = m_num[3] = 0; }
|
||||
u256& operator+=(u256 const& other);
|
||||
u256& operator*=(u256 const& other);
|
||||
u256& operator-=(u256 const& other);
|
||||
u256& inv(); /* unary minus */
|
||||
|
||||
// comparisons
|
||||
bool operator==(u256 const& other) const;
|
||||
bool operator!=(u256 const& other) const;
|
||||
bool operator<(u256 const& other) const;
|
||||
bool operator<=(u256 const& other) const;
|
||||
bool operator>(u256 const& other) const;
|
||||
bool operator>=(u256 const& other) const;
|
||||
|
||||
bool operator<(uint64_t other) const;
|
||||
bool operator<=(uint64_t other) const;
|
||||
bool operator>(uint64_t other) const;
|
||||
bool operator>=(uint64_t other) const;
|
||||
|
||||
bool is_zero() const { return m_num[0] == 0 && m_num[1] == 0 && m_num[2] == 0 && m_num[3] == 0; }
|
||||
bool is_one() const { return m_num[0] == 1 && m_num[1] == 0 && m_num[2] == 0 && m_num[3] == 0; }
|
||||
bool is_even() const { return (m_num[0]&1) == 0; }
|
||||
|
||||
std::ostream& display(std::ostream& out) const;
|
||||
|
||||
};
|
||||
|
||||
inline std::ostream& operator<<(std::ostream& out, u256 const& u) {
|
||||
return u.display(out);
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue