Changeset 7449:2fcb657f9f75


Ignore:
Timestamp:
12/01/07 09:44:42 (5 years ago)
Author:
dmharvey@…
Branch:
default
Message:

fixed #1334 (Constant polynomial can't be converted to rational)

File:
1 edited

Legend:

Unmodified
Added
Removed
  • sage/rings/polynomial/polynomial_element.pyx

    r7423 r7449  
    525525 
    526526    def _integer_(self): 
     527        r""" 
     528        EXAMPLES: 
     529            sage: k = GF(47) 
     530            sage: R.<x> = PolynomialRing(k) 
     531            sage: ZZ(R(45)) 
     532            45 
     533            sage: ZZ(3*x + 45) 
     534            Traceback (most recent call last): 
     535            ... 
     536            TypeError: cannot coerce nonconstant polynomial 
     537        """ 
    527538        if self.degree() > 0: 
    528539            raise TypeError, "cannot coerce nonconstant polynomial" 
    529540        return sage.rings.integer.Integer(self[0]) 
     541 
     542    def _rational_(self): 
     543        r""" 
     544        EXAMPLES: 
     545            sage: R.<x> = PolynomialRing(QQ) 
     546            sage: QQ(R(45/4)) 
     547            45/4 
     548            sage: QQ(3*x + 45) 
     549            Traceback (most recent call last): 
     550            ... 
     551            TypeError: cannot coerce nonconstant polynomial 
     552        """ 
     553        if self.degree() > 0: 
     554            raise TypeError, "cannot coerce nonconstant polynomial" 
     555        return sage.rings.rational.Rational(self[0]) 
    530556 
    531557    def __invert__(self): 
Note: See TracChangeset for help on using the changeset viewer.