Esempio n. 1
0
 def __truediv__(self, other):
     if isinstance(other, Rational):
         return Rational(self._p * other._q, self._q * other._p)
     elif isinstance(other, integer.Integer):
         return Rational(self._p, self._q * other._value)
     elif isinstance(other, real.Real):
         return real.Real((self._p / self._q) / other._value)
     elif isinstance(other, infinity.Infinity):
         return integer.Integer(0)
     raise AttributeError("Not a numerical term: " + str(other))
Esempio n. 2
0
 def __sub__(self, other):
     if isinstance(other, Rational):
         return Rational(self._p * other._q - other._p * self._q,
                         self._q * other._q)
     elif isinstance(other, integer.Integer):
         return Rational(self._p - self._q * other._value, self._q)
     elif isinstance(other, real.Real):
         return real.Real(self._p / self._q - other._value)
     elif isinstance(other, infinity.Infinity):
         return infinity.Infinity(not other._is_positive)
     raise AttributeError("Not a numerical term: " + str(other))
Esempio n. 3
0
 def __add__(self, other):
     if isinstance(other, Rational):
         return Rational(self._p * other._q + other._p * self._q,
                         self._q * other._q)
     elif isinstance(other, integer.Integer):
         return Rational(self._p + self._q * other._value, self._q)
     elif isinstance(other, real.Real):
         return real.Real(self._p / self._q + other._value)
     elif isinstance(other, infinity.Infinity):
         return other
     raise AttributeError("Not a numerical term: " + str(other))
Esempio n. 4
0
 def __add__(self, other):
     if isinstance(other, Integer):
         return Integer(self._value + other._value)
     elif isinstance(other, rational.Rational):
         return rational.Rational(self._value * other._q + other._p,
                                  other._q)
     elif isinstance(other, real.Real):
         return real.Real(self._value + other._value)
     elif isinstance(other, infinity.Infinity):
         return other
     raise AttributeError("Not a numerical term: " + str(other) +
                          " type: " + str(type(other)))
Esempio n. 5
0
 def __mul__(self, other):
     if isinstance(other, Integer):
         return Integer(self._value * other._value)
     elif isinstance(other, rational.Rational):
         return rational.Rational(self._value * other._p, other._q)
     elif isinstance(other, real.Real):
         return real.Real(self._value * other._value)
     elif isinstance(other, infinity.Infinity):
         if self._value == 0:
             return self
         else:
             return infinity.Infinity(
                 other._is_positive == (self._value > 0))
     raise AttributeError("Not a numerical term: " + str(other))
Esempio n. 6
0
 def __mul__(self, other):
     if isinstance(other, Rational):
         return Rational(self._p * other._p, self._q * other._q)
     elif isinstance(other, integer.Integer):
         return Rational(self._p * other._value, self._q)
     elif isinstance(other, real.Real):
         return real.Real(self._p / self._q * other._value)
     elif isinstance(other, infinity.Infinity):
         if self >= integer.Integer(0) \
            and self < integer.Integer(1):
             return integer.Integer(0)
         else:
             return infinity.Infinity(
                 other._is_positive == (self > integer.Integer(0)))
     raise AttributeError("Not a numerical term: " + str(other))