- * @return a mod b in the range [-iquo(abs(b)-1,2), iquo(abs(b),2)]. */
-const numeric smod(const numeric &a, const numeric &b)
-{
- if (a.is_integer() && b.is_integer()) {
- const cln::cl_I b2 = cln::ceiling1(cln::the<cln::cl_I>(b.to_cl_N()) >> 1) - 1;
- return numeric(cln::mod(cln::the<cln::cl_I>(a.to_cl_N()) + b2,
- cln::the<cln::cl_I>(b.to_cl_N())) - b2);
+ * @return a mod b in the range [-iquo(abs(b),2), iquo(abs(b),2)]. */
+const numeric smod(const numeric &a_, const numeric &b_)
+{
+ if (a_.is_integer() && b_.is_integer()) {
+ const cln::cl_I a = cln::the<cln::cl_I>(a_.to_cl_N());
+ const cln::cl_I b = cln::the<cln::cl_I>(b_.to_cl_N());
+ const cln::cl_I b2 = b >> 1;
+ const cln::cl_I m = cln::mod(a, b);
+ const cln::cl_I m_b = m - b;
+ const cln::cl_I ret = m > b2 ? m_b : m;
+ return numeric(ret);