diff options
author | Reinier Heeres <rwh@rwh.(none)> | 2008-03-06 13:33:28 (GMT) |
---|---|---|
committer | Reinier Heeres <rwh@rwh.(none)> | 2008-03-06 13:33:28 (GMT) |
commit | 587185cc5c94acb3565f90a7df030d49ffb47639 (patch) | |
tree | 6a099899083719db7749d90af55d37b3d3061827 /rational.py | |
parent | 4ddf6837a3867dee4230161baf9514b5e175ccf4 (diff) |
Implement power operator for Rationals
Diffstat (limited to 'rational.py')
-rw-r--r-- | rational.py | 7 |
1 files changed, 7 insertions, 0 deletions
diff --git a/rational.py b/rational.py index 564d4d9..381b05a 100644 --- a/rational.py +++ b/rational.py @@ -130,3 +130,10 @@ class Rational: self.n = abs(self.n) self.d = abs(self.d) + def __pow__(self, rval): + if type(rval) is types.IntType or type(rval) is types.LongType: + ret = Rational(self.n ** rval, self.d ** rval) + else: + ret = float(self.n) ** rval / float(self.d) ** rval + + return ret |