Advertisement
Guest User

Python FastArithmetic

a guest
Apr 14th, 2015
1,194
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.40 KB | None | 0 0
  1. class FastArithmetic(object):
  2.    
  3.     def __init__(self):
  4.         self.x = -9223372036854775808
  5.         self.y = -9223372036854775808
  6.  
  7.     def add(self, a, b):
  8.         while (self.x + self.y) != (a + b):
  9.             self.x += 1
  10.  
  11.             if (self.x == 9223372036854775807):
  12.                 self.__second_sieve()
  13.  
  14.         return self.x + self.y
  15.  
  16.     def subtract(self, a, b):
  17.         self.x += 9223372036854775807
  18.  
  19.         while (self.x - self.y) != (a - b):
  20.             self.x -= 1
  21.  
  22.             if (self.x == 9223372036854775807):
  23.                 self.__second_sieve()
  24.                 self.x += 9223372036854775807
  25.  
  26.         return self.x - self.y
  27.  
  28.     def multiply(self, a, b):
  29.         self.y += 9223372036854775809
  30.        
  31.         while (self.x * self.y) != (a * b):
  32.             self.x += 1
  33.  
  34.         return self.x * self.y
  35.  
  36.     def divide(self, a, b):
  37.         #do some math
  38.         while self.x != 9223372036854775807:
  39.             self.y /= self.x
  40.             self.x += 1
  41.  
  42.         return a/b
  43.  
  44.     def show(self):
  45.         print("x =", self.x)
  46.         print("y =", self.y)
  47.  
  48.     def reset(self):
  49.         """This method makes it more like a real calcualtor where you have to clear out the screen after you use it or else it doesnt work"""
  50.         self.x = -9223372036854775808
  51.         self.y = -9223372036854775808
  52.  
  53.     def __second_sieve():
  54.         self.x = 0
  55.         self.y = 0
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement