This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

classification
Title: Problem with abs function
Type: Stage:
Components: Interpreter Core Versions: Python 2.4
process
Status: closed Resolution: out of date
Dependencies: Superseder:
Assigned To: Nosy List: ncoghlan, rhettinger, ric-b, terry.reedy
Priority: normal Keywords:

Created on 2005-05-16 16:32 by ric-b, last changed 2022-04-11 14:56 by admin. This issue is now closed.

Messages (5)
msg25371 - (view) Author: ric-b (ric-b) Date: 2005-05-16 16:32
On windows version I get :

>>> abs(-9999999999999999999)

Traceback (most recent call last):
  File "<pyshell#7>", line 1, in -toplevel-
    abs(-9999999999999999999)
OverflowError: long too big to convert

does not handle new longs.


I am using the following work around:

            t = a - b  # calc t = abs(a - b)
            if t < 0 :  
                t *= -1
msg25372 - (view) Author: Raymond Hettinger (rhettinger) * (Python committer) Date: 2005-05-16 17:33
Logged In: YES 
user_id=80475

That's odd.  It works for me:

Python 2.4.1 (#65, Mar 30 2005, 09:13:57) [MSC v.1310 32 bit
(Intel)] on win32
Type "help", "copyright", "credits" or "license" for more
information.
>>> abs(-9999999999999999999)
9999999999999999999L
msg25373 - (view) Author: Nick Coghlan (ncoghlan) * (Python committer) Date: 2005-05-18 11:53
Logged In: YES 
user_id=1038590

I tried the OP's example in wxPython's PyShell as well as in
the standard interpreter, and got the same result as Raymond.

However, I was able to provoke a similar looking error by
trying to convert a large long to a float (and the exception
is telling the plain truth - a double precision float can't
handle a number that big):

Py> num = 1.0
Py> lng =
-999999999999999999999999999999999999999999999999999999999999999999999
99999999999999999999999999999999999999999999999999999999999999999999999999999999
99999999999999999999999999999999999999999999999999999999999999999999999999999999
99999999999999999999999999999999999999999999999999999999999999999999999999999999
99999999999999999999999999999999999999999999999999999999999999999999999999999999
999999999999
Py> num += abs(lng)
Traceback (most recent call last):
  File "<stdin>", line 1, in ?
OverflowError: long int too large to convert to float
msg25374 - (view) Author: Terry J. Reedy (terry.reedy) * (Python committer) Date: 2005-05-19 02:10
Logged In: YES 
user_id=593130

Python 2.2.1 (#34, Apr  9 2002, 19:34:33) [MSC 32 bit (Intel)] on 
win32
Type "help", "copyright", "credits" or "license" for more 
information.
>>> abs(-9999999999999999999)
9999999999999999999L

Ric-b: what windows version? Even older?  If the problem is not 
with current or future (cvs) Python, please close this.
msg25375 - (view) Author: Raymond Hettinger (rhettinger) * (Python committer) Date: 2005-05-26 07:12
Logged In: YES 
user_id=80475

No response from the OP.
Presuming that Terry's explanation is correct.
Please re-open if presented with evidence to the contrary.
History
Date User Action Args
2022-04-11 14:56:11adminsetgithub: 41989
2005-05-16 16:32:14ric-bcreate