chore: leave `mpz` untouched
This PR restores the last two removals in `runtime/mpz.{h,cpp}`, `operator=(char const *)` and `power`/`_power`/`pow`, so the `mpz` wrapper is left exactly as on master.
Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
diff --git a/src/runtime/mpz.cpp b/src/runtime/mpz.cpp
index ac37cea..2be1405 100644
--- a/src/runtime/mpz.cpp
+++ b/src/runtime/mpz.cpp
@@ -118,6 +118,10 @@
mpz_set(m_val, v.m_val); return *this;
}
+mpz & mpz::operator=(char const * v) {
+ mpz_set_str(m_val, v, 10); return *this;
+}
+
mpz & mpz::operator=(unsigned int v) {
mpz_set_ui(m_val, v); return *this;
}
@@ -296,6 +300,10 @@
return static_cast<int64>(mod64());
}
+void power(mpz & a, mpz const & b, unsigned k) {
+ mpz_pow_ui(a.m_val, b.m_val, k);
+}
+
void gcd(mpz & g, mpz const & a, mpz const & b) {
mpz_gcd(g.m_val, a.m_val, b.m_val);
}
@@ -528,6 +536,12 @@
return *this;
}
+mpz & mpz::operator=(char const * v) {
+ mpz_dealloc(m_digits, sizeof(mpn_digit)*m_size);
+ init_str(v);
+ return *this;
+}
+
mpz & mpz::operator=(unsigned int v) {
mpz_dealloc(m_digits, sizeof(mpn_digit)*m_size);
init_uint(v);
@@ -1049,6 +1063,11 @@
return static_cast<int64>(mod64());
}
+void power(mpz & a, mpz const & b, unsigned k) {
+ a = b;
+ a.pow(k);
+}
+
void gcd(mpz & g, mpz const & a, mpz const & b) {
mpz tmp1(a);
mpz tmp2(b);
diff --git a/src/runtime/mpz.h b/src/runtime/mpz.h
index b6ffa54..d3c33305 100644
--- a/src/runtime/mpz.h
+++ b/src/runtime/mpz.h
@@ -142,6 +142,7 @@
mpz & operator=(mpz const & v);
mpz & operator=(mpz && v) { swap(*this, v); return *this; }
+ mpz & operator=(char const * v);
mpz & operator=(unsigned int v);
mpz & operator=(int v);
@@ -291,6 +292,9 @@
*/
size_t size_in_bytes() const;
+ friend void power(mpz & a, mpz const & b, unsigned k);
+ friend void _power(mpz & a, mpz const & b, unsigned k) { power(a, b, k); }
+ friend mpz pow(mpz a, unsigned k) { power(a, a, k); return a; }
friend void gcd(mpz & g, mpz const & a, mpz const & b);
friend mpz gcd(mpz const & a, mpz const & b) { mpz r; gcd(r, a, b); return r; }