X-Git-Url: https://www.ginac.de/ginac.git//ginac.git?p=ginac.git;a=blobdiff_plain;f=ginac%2Fnumeric.cpp;h=858cbbd578ee0ba2fd332876249ddef43e8c026a;hp=0274d63af6fcee55c222c507253a7f124a53d8c5;hb=89779632ca81383a8fa44244d7825947638e7fbd;hpb=de552105d0e4304d869f3d88729b34a613a11b45 diff --git a/ginac/numeric.cpp b/ginac/numeric.cpp index 0274d63a..858cbbd5 100644 --- a/ginac/numeric.cpp +++ b/ginac/numeric.cpp @@ -1688,9 +1688,12 @@ const numeric smod(const numeric &a, const numeric &b) * In general, mod(a,b) has the sign of b or is zero, and irem(a,b) has the * sign of a or is zero. * - * @return remainder of a/b if both are integer, 0 otherwise. */ + * @return remainder of a/b if both are integer, 0 otherwise. + * @exception overflow_error (division by zero) if b is zero. */ const numeric irem(const numeric &a, const numeric &b) { + if (b.is_zero()) + throw std::overflow_error("numeric::irem(): division by zero"); if (a.is_integer() && b.is_integer()) return cln::rem(cln::the(a.to_cl_N()), cln::the(b.to_cl_N())); @@ -1705,9 +1708,12 @@ const numeric irem(const numeric &a, const numeric &b) * and irem(a,b) has the sign of a or is zero. * * @return remainder of a/b and quotient stored in q if both are integer, - * 0 otherwise. */ + * 0 otherwise. + * @exception overflow_error (division by zero) if b is zero. */ const numeric irem(const numeric &a, const numeric &b, numeric &q) { + if (b.is_zero()) + throw std::overflow_error("numeric::irem(): division by zero"); if (a.is_integer() && b.is_integer()) { const cln::cl_I_div_t rem_quo = cln::truncate2(cln::the(a.to_cl_N()), cln::the(b.to_cl_N())); @@ -1723,9 +1729,12 @@ const numeric irem(const numeric &a, const numeric &b, numeric &q) /** Numeric integer quotient. * Equivalent to Maple's iquo as far as sign conventions are concerned. * - * @return truncated quotient of a/b if both are integer, 0 otherwise. */ + * @return truncated quotient of a/b if both are integer, 0 otherwise. + * @exception overflow_error (division by zero) if b is zero. */ const numeric iquo(const numeric &a, const numeric &b) { + if (b.is_zero()) + throw std::overflow_error("numeric::iquo(): division by zero"); if (a.is_integer() && b.is_integer()) return cln::truncate1(cln::the(a.to_cl_N()), cln::the(b.to_cl_N())); @@ -1739,9 +1748,12 @@ const numeric iquo(const numeric &a, const numeric &b) * r == a - iquo(a,b,r)*b. * * @return truncated quotient of a/b and remainder stored in r if both are - * integer, 0 otherwise. */ + * integer, 0 otherwise. + * @exception overflow_error (division by zero) if b is zero. */ const numeric iquo(const numeric &a, const numeric &b, numeric &r) { + if (b.is_zero()) + throw std::overflow_error("numeric::iquo(): division by zero"); if (a.is_integer() && b.is_integer()) { const cln::cl_I_div_t rem_quo = cln::truncate2(cln::the(a.to_cl_N()), cln::the(b.to_cl_N()));