Changeset 7754:c3917dbf54c0


Ignore:
Timestamp:
12/10/07 22:27:13 (5 years ago)
Author:
William Stein <wstein@…>
Branch:
default
Message:

Trac #1457 -- part 2 -- make sure result is mathematically correct

File:
1 edited

Legend:

Unmodified
Added
Removed
  • sage/rings/rational.pyx

    r7753 r7754  
    10301030            sage: complex(1,2)**(1/2) 
    10311031            (1.272019649514069+0.78615137775742328j) 
     1032            sage: int(2)^(1/2) 
     1033            sqrt(2) 
     1034            sage: a = int(2)^(3/1); a 
     1035            8 
     1036            sage: type(a) 
     1037            <type 'sage.rings.rational.Rational'> 
    10321038        """ 
    10331039        if dummy is not None: 
    10341040            raise ValueError, "__pow__ dummy variable not used" 
    1035          
    1036         if not PY_TYPE_CHECK(self, Rational):  #this is here for no good reason apparent to me... should be removed in the future. 
    1037             return self.__pow__(type(self)(n)) 
     1041 
     1042        if not PY_TYPE_CHECK(self, Rational): 
     1043            # If the base is not a rational, e.g., it is an int, complex, float, user-defined type, etc. 
     1044            try: 
     1045                self_coerced = Rational(self) 
     1046            except TypeError: 
     1047                n_coerced = type(self)(n) 
     1048                if n != n_coerced: 
     1049                    # dangerous coercion -- don't use -- try symbolic result 
     1050                    from sage.calculus.calculus import SR 
     1051                    return SR(self)**SR(n) 
     1052                return self.__pow__(n_coerced) 
     1053            return self_coerced.__pow__(n) 
    10381054         
    10391055        cdef Rational _self = <Rational>self 
Note: See TracChangeset for help on using the changeset viewer.