#19110: QQ(0)^-1 raises SIGFPE (which is caught)
-------------------------------------+-------------------------------------
       Reporter:  dkrenn             |        Owner:
           Type:  defect             |       Status:  new
       Priority:  critical           |    Milestone:  sage-6.9
      Component:  basic arithmetic   |   Resolution:
       Keywords:                     |    Merged in:
        Authors:                     |    Reviewers:
Report Upstream:  N/A                |  Work issues:
         Branch:                     |       Commit:
  u/behackl/arithmetic/QQ-inversion  |  310bbba440fd94f298e6024edd889c68f08ed1c0
   Dependencies:                     |     Stopgaps:
-------------------------------------+-------------------------------------
Changes (by behackl):

 * commit:   => 310bbba440fd94f298e6024edd889c68f08ed1c0
 * branch:   => u/behackl/arithmetic/QQ-inversion


Comment:

 ... well, that makes sense. The following approach (pushed to the branch
 attached to this ticket) should be better -- however, I really don't know
 if thats the best way to check if x is 0...

 {{{#!diff
 --- a/src/sage/rings/rational.pyx
 +++ b/src/sage/rings/rational.pyx
 @@ -2329,6 +2336,9 @@ cdef class
 Rational(sage.structure.element.FieldElement):

          if nn < 0:
              sig_on()
 +            if mpz_sgn(mpq_numref(x.value)) == 0:
 +                sig_off()
 +                raise ZeroDivisionError('rational division by zero')
              # mpz_pow_ui(mpq_denref(x.value), mpq_numref(_self.value),
 <unsigned long int>(-nn))
              # mpz_pow_ui(mpq_numref(x.value), mpq_denref(_self.value),
 <unsigned long int>(-nn))
              # The above causes segfaults, so swap after instead...
 }}}
 ----
 New commits:
 
||[http://git.sagemath.org/sage.git/commit/?id=3b6b436622037bc516c9ec3a24e7fc8065e3e638
 3b6b436]||{{{raise ZeroDivisionError when QQ(0) is taken to a negative
 power}}}||
 
||[http://git.sagemath.org/sage.git/commit/?id=310bbba440fd94f298e6024edd889c68f08ed1c0
 310bbba]||{{{add a doctest for QQ(0)^(-1)}}}||

--
Ticket URL: <http://trac.sagemath.org/ticket/19110#comment:9>
Sage <http://www.sagemath.org>
Sage: Creating a Viable Open Source Alternative to Magma, Maple, Mathematica, 
and MATLAB

-- 
You received this message because you are subscribed to the Google Groups 
"sage-trac" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
Visit this group at http://groups.google.com/group/sage-trac.
For more options, visit https://groups.google.com/d/optout.

Reply via email to