Beispiel #1
0
 def _norm(self):
     "Normalize: remove the common denominator"
     if self.num == 0:
         self.den = 1
         return
     if self.den == 0:
         #invalud value
         if   self.num < 0:
             self.num = -1
             
         elif self.num > 0:
             self.num = 1
                 
         return
         
     if self.den<0: #normalize sign
         self.num = -self.num
         self.den = -self.den
         
     k = numtheor.gcd(self.num, self.den)
     self.num /= k
     self.den /= k
Beispiel #2
0
 def simplify(a,b):
     d = gcd(a,b)
     return (a/d, b/d)