File tree Expand file tree Collapse file tree 2 files changed +17
-8
lines changed Expand file tree Collapse file tree 2 files changed +17
-8
lines changed Original file line number Diff line number Diff line change @@ -6,7 +6,7 @@ from libc.stdio cimport FILE
66
77from libc.stdint cimport intmax_t, uintmax_t
88
9- cdef extern from " gmp.h" :
9+ cdef extern from " gmp.h" nogil :
1010
1111 # ## Integer Functions ###
1212
Original file line number Diff line number Diff line change @@ -3022,18 +3022,25 @@ cdef class Integer(sage.structure.element.EuclideanDomainElement):
30223022 raise ArithmeticError (" self must be nonzero" )
30233023 if not isinstance (m, Integer):
30243024 m = Integer(m)
3025- if not m:
3025+ cdef Integer m_ = < Integer> m
3026+ if m_.is_zero():
30263027 return one
3028+ if m_.is_unit():
3029+ return self
30273030
30283031 cdef mpz_t mm, n
30293032 mpz_init(mm)
3030- mpz_init(n)
3031- mpz_set(n, self .value)
3032- mpz_set(mm, (< Integer> m).value)
30333033 sig_on()
3034- while mpz_cmp_ui(mm, 1 ):
3035- mpz_gcd(mm, n, mm)
3036- mpz_divexact(n, n, mm)
3034+ mpz_gcd(mm, self .value, m_.value)
3035+ if mpz_cmp_ui(mm, 1 ) == 0 :
3036+ sig_off()
3037+ return self
3038+ else :
3039+ mpz_init(n)
3040+ mpz_divexact(n, self .value, mm)
3041+ while mpz_cmp_ui(mm, 1 ):
3042+ mpz_gcd(mm, n, mm)
3043+ mpz_divexact(n, n, mm)
30373044 sig_off()
30383045 mpz_clear(mm)
30393046 return move_integer_from_mpz(n)
@@ -3352,6 +3359,8 @@ cdef class Integer(sage.structure.element.EuclideanDomainElement):
33523359 sage: abs(z) == abs(1)
33533360 True
33543361 """
3362+ if mpz_sgn(self .value) >= 0 :
3363+ return self
33553364 cdef Integer x = PY_NEW(Integer)
33563365 mpz_abs(x.value, self .value)
33573366 return x
You can’t perform that action at this time.
0 commit comments