Bugs item #1770416, was opened at 2007-08-08 18:13 Message generated for change (Comment added) made by aryx You can respond by visiting: https://sourceforge.net/tracker/?func=detail&atid=105470&aid=1770416&group_id=5470
Please note that this message will contain a full copy of the comment thread, including the initial issue submission, for this request, not just the latest update. Category: Python Library Group: None Status: Open Resolution: None Priority: 5 Private: No Submitted By: Jason G (aryx) Assigned to: Nobody/Anonymous (nobody) Summary: Decimal.__int__ overflows for large values Initial Comment: This also affects Decimal.__hash__, since it [indirectly] calls Decimal.__int__. >>> from decimal import Decimal as D >>> e = D("1e1234567890987654321") >>> int(e) Traceback (most recent call last): File "<stdin>", line 1, in <module> File "/usr/lib/python2.5/decimal.py", line 1501, in __int__ s = ''.join(map(str, self._int)) + '0'*self._exp OverflowError: cannot fit 'long' into an index-sized integer >>> e = D("1e1234567890") >>> int(e) Traceback (most recent call last): File "<stdin>", line 1, in <module> File "/usr/lib/python2.5/decimal.py", line 1501, in __int__ s = ''.join(map(str, self._int)) + '0'*self._exp MemoryError Also, for values that do work this is incredibly slow if they are still fairly large. ---------------------------------------------------------------------- >Comment By: Jason G (aryx) Date: 2007-08-09 12:39 Message: Logged In: YES user_id=1289703 Originator: YES Hey Daniel, The bigger issue for us is mostly the fact that Decimal.__hash__ us calling Decimal.__int__ and not because we want an integer/long version of a very large Decimal. We do not actually cast the decimal into an int/long explicitly. I wouldn't have any issues if Decimal.__int__ remained as it is, but I think it would be a good idea for Decimal.__hash__ to do something differently. Probably something that is fast and simple, such as hash( self.as_tuple() ), self being a Decimal of course. Our project is a CAS and we use Decimal for our real number class. I happened to run into this issue when I was implementing approximation of log(x) for extremely large/small values of x. I just started keyboard bashing numbers and behold, Decimal crashed on me :) ---------------------------------------------------------------------- Comment By: ajaksu (ajaksu2) Date: 2007-08-09 05:39 Message: Logged In: YES user_id=1200609 Originator: NO Hi Jason, The OverflowError is related to "index-sized ints" as in "ints that are valid indexes for sequences", try: >>> e = "0" * 1234567890 So it seems that this error is avoiding the creation of a string of length 1234567890, which is a good thing (sorta) :) Once I tried to implement a dec2long function that was based on numbers instead of strings, see if it helps (it's VERY slow and naive, but IIRC it was a bit faster than the original version and correct): http://groups.google.com/group/comp.lang.python/msg/aba7264ab38eb25e Now, do you really need all that precision for such huge numbers? I know I didn't ;) Daniel ---------------------------------------------------------------------- You can respond by visiting: https://sourceforge.net/tracker/?func=detail&atid=105470&aid=1770416&group_id=5470 _______________________________________________ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com