diff --git a/src/fp.cpp b/src/fp.cpp index 3487586..015e351 100644 --- a/src/fp.cpp +++ b/src/fp.cpp @@ -75,8 +75,13 @@ struct OpeFunc { static const size_t N = (bitSize + UnitBitSize - 1) / UnitBitSize; static inline void set_mpz_t(mpz_t& z, const Unit* p, int n = (int)N) { + int s = n; + while (s > 0) { + if (p[s - 1]) break; + s--; + } z->_mp_alloc = n; - z->_mp_size = (int)getNonZeroArraySize(p, n); + z->_mp_size = s; z->_mp_d = (mp_limb_t*)const_cast(p); } static inline void set_zero(mpz_t& z, Unit *p, size_t n)