If you use the same HUGE number many times:

  • import sys
  • sys.maxint = sys.maxint+sys.maxint
  • This is because if you have the INFINITE(or lower) refrence to the same integer, It will take up the sppace of that integer.
    If you use many diffrent huge numbers:

  • Use a accurate way to calculate when needed[1]

  • Use an inacurrate one

Here's the code:

class num(object):
For STORING numbers,many operations will be slow
(will also cause a temporary low memory when the function is running,
so may cause memory error)
need to have it's memory freed,
Also, use x += y not x = x + y and for subtraction and power, but DO NOT use it for anything else.
    def convertto(self,n):
        if n != 0:
            x = math.log(float(n),2)
            y = x - math.floor(x)
            x = 0.0
            y = -1
        return x,y
    def __float__(self):
        return 2**self.x + self.y
    regular = __float__
    def totalmem(self):
        tot = 0
        if type(n.y) == num:
            tot = n.y.totalmem()+tot
            tot = n.x.totalmem()+tot
            tot = math.abs(n.y)+tot
            tot = math.abs(n.x)+tot
        return tot
    def freememory(self):
        "call when many increment/decrement/power operations have been called in a row, if the last called was not increment/decrement/power, do not call"
        self.x,self.y = self.convertto(self.convertfrom())
    def newlevel(self):
        "frees memory even more, may be redundant and calculations are even slower"
        if (type(self.y) == int) or (type(self.y) == long) or (type(self.y) == float):
            self.y = num(self.y)
            self.x = num(self.x)
    def check(self):
        if (type(self.y) == long):
        if type(self.y) == num:
            if self.y.check():
    def __init__(self,n=1):
        self.x , self.y = self.convertto(n)
        def __divmod__(self,other):
            return divmod(self.convertfrom(),other)
    def __ipow__(self,other):
        self.x = self.x * other
        self.y = self.y ** other
        return self
    def __iadd__(self,other):
        self.y += other
        return self
    def __str__(self):
        return "2^"+str(self.x)+" + " + str(self.y)
    def __cmp__(self,other):
        if type(other) == num:
            if self.x != other.x:
                return self.x.__cmp__(other.x)
                return self.y.__cmp__(other.x)
            s = self.convertfrom()
            if other < s:
                return 1
            elif other == s:
                return 0
                return -1
            return other.__cmp__(self)
def _nop(name,sym):# majic funcs to implement diffrent kinds of +-*/ and others
    setattr(num,"__"+name+"__",eval("lambda self,other:self.convertfrom() %s other"%sym))
def _rnop(name,sym):
    sym = "\""+sym+"\""
    setattr(num,"__r"+name+"__",eval("lambda self,other:_op(other,%s)"%sym))
def _fnop(name,sym):
    setattr(num,"__"+name+"__",eval("lambda self:[0](int(self))"%sym))
class string(object):

    def __init__(self,initialize=""):
        self.l = []
        for c in initialize:
    def __str__(self):
        for i in self.l:
            r =  r + chr(int(i))
        return r
    regular = __str__
_nop("add","+") #lazy!!!!!!!!
num.__truediv__ = lambda self,other:convertto(self)/float(other)
def compress(obj,verbose=False):
    'compress any object'
    "return for builtins and classes, but in place for objects."
    if type(obj) == list:
        return [compress(i) for i in obj]
    elif type(obj) == int:
        return num(obj)
    elif type(obj) == str:
        return string(obj)
    elif type(obj) == type:
        return obj
    elif str(type(obj))== "<type 'function'>":
        return obj
    elif type(obj) in (type(string),type(num)):
        return obj
    elif type(obj) == dict:
        for k,v in zip(obj.keys(),obj.values()):
            obj[k] = compress(v)
        for i in dir(obj):
                if i.startswith("__") and i.endswith("__"):
                a = getattr(obj,i)
                if verbose:
                    print "SUCCCESS on " + i + " with type of " + str(type(a))
            except Exception , e:
                if str(e).endswith("is read-only"):
                if verbose:
                    print "FAIL on " + i + " with type of " + str(type(i))

Edited 3 Years Ago by pritaeas: Markdown retry.

This question has already been answered. Start a new discussion instead.