Esempio n. 1
0
 def __div__(self,x):
     if type(x)==GenBase:
         if p.frombase(x.value['base'],x.value['value'])==0:
             print "The divisor can't be zero!"
         else:        
             div=p.frombase(self.value['base'],self.value['value'])/p.frombase(x.value['base'],x.value['value'])
             return GenBase(self.value['base'],div)
     else:
         raise TypeError
Esempio n. 2
0
 def __sub__(self,x):
     if type(x)==GenBase:
         subt = p.frombase(self.value['base'],self.value['value'])-p.frombase(x.value['base'],x.value['value'])
         if subt<0:
             print "subtraction is less than 0"
         else:
             return GenBase(self.value['base'], subt)
     else:
         raise TypeError
Esempio n. 3
0
 def changebase(self,base_new):
     n = p.frombase(self.value['base'],self.value['value'])
     m = p.tobase(base_new,n)
     self.value=dict(base=base_new,value=m)
Esempio n. 4
0
 def modulo(self,x):
     if type(x)==GenBase:    
         res = p.frombase(self.value['base'],self.value['value'])%p.frombase(x.value['base'],x.value['value'])
         return GenBase(self.value['base'],res)
     else:
         raise TypeError
Esempio n. 5
0
 def __mul__(self,x):
     if type(x)==GenBase:
         pro = p.frombase(self.value['base'],self.value['value'])*p.frombase(x.value['base'],x.value['value'])
         return GenBase(self.value['base'], pro)
     else:
         raise TypeError
Esempio n. 6
0
 def __add__(self,x):
     if type(x)==GenBase:
         summ = p.frombase(self.value['base'],self.value['value']) + p.frombase(x.value['base'], x.value['value'])
         return GenBase(self.value['base'], summ)
     else:
         raise TypeError