# HG changeset patch
# User André Apitzsch <andre.apitzsch@st.ovgu.de>
# Date 1333059614 -7200
# Node ID d7f382f9fb19c52d030244f39959706cae1c0080
# Parent  84d0fab1adaafd6c8fdbcf8ff463aee56b9dcd0d
trac 10217: inverse mod longlong + indirect doctest

diff --git a/sage/ext/multi_modular.pxd b/sage/ext/multi_modular.pxd
--- a/sage/ext/multi_modular.pxd
+++ b/sage/ext/multi_modular.pxd
@@ -24,7 +24,7 @@
     cdef int _extend_moduli_to_height_c(self, mpz_t height) except -1
     cdef void _refresh_products(self, int start)
     cdef void _refresh_prod(self)
-    cdef void _refresh_precomputations(self, int start)
+    cdef void _refresh_precomputations(self, int start) except *
     cdef int min_moduli_count(self, mpz_t height) except -1
     
     cdef int mpz_reduce_tail(self, mpz_t z, mod_int* b, int offset, int len) except -1
diff --git a/sage/ext/multi_modular.pyx b/sage/ext/multi_modular.pyx
--- a/sage/ext/multi_modular.pyx
+++ b/sage/ext/multi_modular.pyx
@@ -157,24 +157,32 @@
             sage: mm = MultiModularBasis_base(0); mm
             MultiModularBasis with moduli [28499]
 
+            sage: mm = MultiModularBasis_base([6, 10])
+            Traceback (most recent call last):
+            ...
+            ValueError: the values provided are not relatively prime
         """
         if l_bound == 0:
             self._l_bound = 2**10
         elif l_bound < 2:
-            raise ValueError, "minimum value for lower bound is 2, given: %s"%(l_bound)
+            raise ValueError("minimum value for lower bound is 2, given: %s"%(l_bound))
         else:
             self._l_bound = l_bound
 
         if u_bound == 0:
             self._u_bound = 2**15
         elif u_bound > MAX_MODULUS:
-            raise ValueError, "upper bound cannot be greater than MAX_MODULUS: %s, given: %s"%(MAX_MODULUS, u_bound)
+            raise ValueError("upper bound cannot be greater than MAX_MODULUS: %s, given: %s"%(MAX_MODULUS, u_bound))
         else:
             self._u_bound = u_bound
 
         cdef int i
         if isinstance(val, (list, tuple, GeneratorType)):
-            self.extend_with_primes(val, check=True)
+            try:
+                self.extend_with_primes(val, check=True)
+            except ArithmeticError:
+                #See :trac:`10217`
+                raise ValueError("the values provided are not relatively prime")
         else:
             self._extend_moduli_to_height(val)
 
@@ -424,7 +432,7 @@
         mpz_set(self.product, self.partial_products[self.n-1])
         mpz_fdiv_q_ui(self.half_product, self.product, 2)
         
-    cdef void _refresh_precomputations(self, int start):
+    cdef void _refresh_precomputations(self, int start) except *:
         r"""
         Compute and store $\prod_j=1^{i-1} m_j^{-1} (mod m_i)$ of i >= start.
         """
diff --git a/sage/rings/fast_arith.pyx b/sage/rings/fast_arith.pyx
--- a/sage/rings/fast_arith.pyx
+++ b/sage/rings/fast_arith.pyx
@@ -366,6 +366,8 @@
     cdef public long long c_inverse_mod_longlong(self, long long a, long long m) except -1:
         cdef long long g, s, t
         g = self.c_xgcd_longlong(a,m, &s, &t)
+        if g != 1:
+            raise ArithmeticError("The inverse of %s modulo %s is not defined."%(a,m))
         s = s % m
         if s < 0:
             s = s + m
