#10761: Numerical approximation of an algebraic number raises a ValueError
----------------------------+-----------------------------------------------
   Reporter:  slabbe        |       Owner:  tbd                              
       Type:  defect        |      Status:  needs_review                     
   Priority:  major         |   Milestone:  sage-4.7                         
  Component:  numerical     |    Keywords:  numerical_approx, AlgebraicNumber
     Author:  Simon Spicer  |    Upstream:  N/A                              
   Reviewer:                |      Merged:                                   
Work_issues:                |  
----------------------------+-----------------------------------------------
Changes (by newvalueoldvalue):

  * keywords:  => numerical_approx, AlgebraicNumber
  * status:  new => needs_review
  * component:  PLEASE CHANGE => numerical
  * author:  => Simon Spicer


Comment:

 The patch provides a short and sweet fix to the above problem. The issue
 arises in sage/misc/functional.py's numerical_approx() function:
 {{{
 if not (is_ComplexNumber(x) or is_ComplexDoubleElement(x)):
             try:
                 return sage.rings.real_mpfr.RealField(prec)(x)
             except TypeError:
                 pass
         return sage.rings.complex_field.ComplexField(prec)(x)
 }}}
 Attempting to call RealField() on a complex AlgebraicNumber raises a
 ValueError and not a TypeError, so the exception is not caught. Changing
 the except clause to catch all errors fixes this:
 {{{
 if not (is_ComplexNumber(x) or is_ComplexDoubleElement(x)):
             try:
                 return sage.rings.real_mpfr.RealField(prec)(x)
             # Trac 10761: now catches all errors (instead of just
             # a TypeError), since calling RealField on AlgebraicNumbers
             # can raise a ValueError
             except:
                 pass
         return sage.rings.complex_field.ComplexField(prec)(x)
 }}}

-- 
Ticket URL: <http://trac.sagemath.org/sage_trac/ticket/10761#comment:1>
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 post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/sage-trac?hl=en.

Reply via email to