# HG changeset patch
# User Travis Scrimshaw <tscrim@ucdavis.edu>
# Date 1359992187 28800
# Node ID 605233157dc94826ba55455ac55706081c914c36
# Parent c5243f6b97063139cd6ff94bc811e8ad0bb6ba13
Trac #14045: Fix coercion from float to infinity.
diff git a/sage/rings/infinity.py b/sage/rings/infinity.py
a

b

class UnsignedInfinityRing_class(_uniq, 
588  588  A number less than infinity 
589  589  sage: UnsignedInfinityRing(infinity) 
590  590  Infinity 
 591  sage: UnsignedInfinityRing(float('+inf')) 
 592  Infinity 
591  593  """ 
592  594  if isinstance(x, InfinityElement): 
593  595  if x.parent() is self: 
594  596  return x 
595  597  else: 
596  598  return self.gen() 
597   elif isinstance(x, RingElement) or isinstance(x, (int,long,float,complex)): 
 599  elif isinstance(x, RingElement) or isinstance(x, (int,long)): 
 600  return self.less_than_infinity() 
 601  elif isinstance(x, (float, complex)): 
 602  if x == float('+inf') or x == float('inf'): 
 603  return self.gen() 
598  604  return self.less_than_infinity() 
599  605  else: 
600  606  raise TypeError 
… 
… 
class InfinityRing_class(_uniq, Ring): 
897  903  A positive finite number 
898  904  sage: InfinityRing(a  2) 
899  905  A negative finite number 
 906  
 907  Check that :trac:`14045` is fixed:: 
 908  
 909  sage: InfinityRing(float('+inf')) 
 910  +Infinity 
 911  sage: InfinityRing(float('inf')) 
 912  Infinity 
 913  sage: oo > float('+inf') 
 914  False 
 915  sage: oo == float('+inf') 
 916  True 
900  917  """ 
901  918  if isinstance(x, PlusInfinityElement): 
902  919  return self.gen(0) 
… 
… 
class InfinityRing_class(_uniq, Ring): 
910  927  sage.rings.real_mpfr.RealNumber)) 
911  928  or isinstance(x, (int,long,float)) 
912  929  or sage.rings.real_mpfr.RealField(sage.rings.real_mpfr.mpfr_prec_min())(x)): 
913   if x < 0: 
 930  if x == float('+inf'): 
 931  return self.gen(0) 
 932  elif x == float('inf'): 
 933  return self.gen(1) 
 934  elif x < 0: 
914  935  return FiniteNumber(self, 1) 
915  936  elif x > 0: 
916  937  return FiniteNumber(self, 1) 