# HG changeset patch
# User Simon Spicer <mlungu@uw.edu>
# Date 1300915138 25200
# Node ID 56681ee951d826097119ebf4faa1114e4d863e6e
# Parent 361a4ad7d52c69b64ae2e658ffd0820af0d87e93
Ticket 10761: fixes numerical_approx() in misc/functional.py so that it works on AlgebraicNumbers
diff r 361a4ad7d52c r 56681ee951d8 sage/misc/functional.py
a

b


1246  1246  
1247  1247  sage: type(numerical_approx(CC(1/2))) 
1248  1248  <type 'sage.rings.complex_number.ComplexNumber'> 
 1249  
 1250  The following tests Trac 10761, in which n() would break when 
 1251  called on complexvalued AlgebraicNumbers:: 
 1252  
 1253  sage: E = matrix(3, [3,1,6,5,2,9,7,3,13]).eigenvalues(); E 
 1254  [18.16815365088822?, 0.08407682544410650?  0.2190261484802906?*I, 0.08407682544410650? + 0.2190261484802906?*I] 
 1255  sage: E[1].parent() 
 1256  Algebraic Field 
 1257  sage: [a.n() for a in E] 
 1258  [18.1681536508882, 0.0840768254441065  0.219026148480291*I, 0.0840768254441065 + 0.219026148480291*I] 
1249  1259  """ 
1250  1260  if prec is None: 
1251  1261  if digits is None: 
… 
… 

1260  1270  if not (is_ComplexNumber(x) or is_ComplexDoubleElement(x)): 
1261  1271  try: 
1262  1272  return sage.rings.real_mpfr.RealField(prec)(x) 
1263   except TypeError: 
 1273  # Trac 10761: now catches ValueErrors as well as TypeErrors 
 1274  except (TypeError, ValueError): 
1264  1275  pass 
1265  1276  return sage.rings.complex_field.ComplexField(prec)(x) 
1266  1277  