[issue5377] Strange behavior when performing int on a Decimal made from -sys.maxint-1

2010-04-13 Thread Mark Dickinson
Mark Dickinson added the comment: Closing: it's too late for Python 2.x. -- resolution: -> out of date status: open -> closed ___ Python tracker ___

[issue5377] Strange behavior when performing int on a Decimal made from -sys.maxint-1

2010-01-10 Thread Mark Dickinson
Changes by Mark Dickinson : -- priority: low -> normal ___ Python tracker ___ ___ Python-bugs-list mailing list Unsubscribe: http://ma

[issue5377] Strange behavior when performing int on a Decimal made from -sys.maxint-1

2009-10-11 Thread Carl Friedrich Bolz
Carl Friedrich Bolz added the comment: [...] > Would the bool/int distinction matter to PyPy? No, it's really mostly about longs and ints, because RPython does not have automatic overflowing of ints to longs (the goal is really to translate ints them to C longs with normal C overflow behaviou

[issue5377] Strange behavior when performing int on a Decimal made from -sys.maxint-1

2009-10-11 Thread Mark Dickinson
Mark Dickinson added the comment: Carl, thanks for that. I was just thinking about abandoning this issue as not worth fixing. I need to look at Victor's patch again, but I recall that there were still some issues: e.g., if the __int__ method of some class returns a bool, that still ends up

[issue5377] Strange behavior when performing int on a Decimal made from -sys.maxint-1

2009-10-11 Thread Carl Friedrich Bolz
Carl Friedrich Bolz added the comment: PyPy is a bit of a special case, because it cares about the distinction of int and long in the translation toolchain. Nevertheless, this behavior has been annoying to us. -- nosy: +cfbolz ___ Python tracker

[issue5377] Strange behavior when performing int on a Decimal made from -sys.maxint-1

2009-06-08 Thread STINNER Victor
Changes by STINNER Victor : Removed file: http://bugs.python.org/file13456/force_int-3.patch ___ Python tracker ___ ___ Python-bugs-list mailin

[issue5377] Strange behavior when performing int on a Decimal made from -sys.maxint-1

2009-06-08 Thread STINNER Victor
STINNER Victor added the comment: > Thanks, Victor You're welcome :-) > - I'm getting a test failure in test_class fixed > - you should probably be using sys.maxint rather than sys.maxsize done > This still doesn't fix the case of int(Fraction(2L)) fixed: Fraction uses __trunc__ rather th

[issue5377] Strange behavior when performing int on a Decimal made from -sys.maxint-1

2009-03-29 Thread Mark Dickinson
Mark Dickinson added the comment: Thanks, Victor A couple of things: - I'm getting a test failure in test_class - you should probably be using sys.maxint rather than sys.maxsize: the two aren't necessarily the same. (E.g., on 64-bit windows, I believe that sys.maxint is 2**31-1 while sys.m

[issue5377] Strange behavior when performing int on a Decimal made from -sys.maxint-1

2009-03-29 Thread STINNER Victor
Changes by STINNER Victor : Removed file: http://bugs.python.org/file13426/force_int.patch ___ Python tracker ___ ___ Python-bugs-list mailing

[issue5377] Strange behavior when performing int on a Decimal made from -sys.maxint-1

2009-03-29 Thread STINNER Victor
STINNER Victor added the comment: (oops, my patch v2 includes an unrelated change) -- Added file: http://bugs.python.org/file13456/force_int-3.patch ___ Python tracker ___ __

[issue5377] Strange behavior when performing int on a Decimal made from -sys.maxint-1

2009-03-29 Thread STINNER Victor
Changes by STINNER Victor : Removed file: http://bugs.python.org/file13455/force_int-2.patch ___ Python tracker ___ ___ Python-bugs-list mailin

[issue5377] Strange behavior when performing int on a Decimal made from -sys.maxint-1

2009-03-29 Thread STINNER Victor
STINNER Victor added the comment: > I'm still not sure why anyone would care about getting longs > instead of ints back from int(x) It's strange that sometimes we need to write int(int(obj)) to get an integer :-/ I usually use int(x) to convert x to an integer (type 'int' and not 'long'). > (0

[issue5377] Strange behavior when performing int on a Decimal made from -sys.maxint-1

2009-03-28 Thread Mark Dickinson
Changes by Mark Dickinson : -- components: +Interpreter Core -Library (Lib) ___ Python tracker ___ ___ Python-bugs-list mailing list Un

[issue5377] Strange behavior when performing int on a Decimal made from -sys.maxint-1

2009-03-28 Thread Mark Dickinson
Changes by Mark Dickinson : -- assignee: -> marketdickinson priority: -> low ___ Python tracker ___ ___ Python-bugs-list mailing list

[issue5377] Strange behavior when performing int on a Decimal made from -sys.maxint-1

2009-03-27 Thread Mark Dickinson
Mark Dickinson added the comment: Thanks for the patch, Victor. I think this is the right thing to do, though I'm still not sure why anyone would care about getting longs instead of ints back from int(x). Comments and questions: (0) Please could you add some tests! (1) Shouldn't the first l

[issue5377] Strange behavior when performing int on a Decimal made from -sys.maxint-1

2009-03-26 Thread STINNER Victor
STINNER Victor added the comment: I added the two benchmark tools to my own public SVN: http://haypo.hachoir.org/trac/browser/misc/bench_int.py (improved version of the script attached to issue #4294) http://haypo.hachoir.org/trac/browser/misc/pidigits.py (improved version of the script attach

[issue5377] Strange behavior when performing int on a Decimal made from -sys.maxint-1

2009-03-26 Thread STINNER Victor
STINNER Victor added the comment: > The general machinery for implementing the built-in int function > should check any result of type long to see if it fits in an int, > and convert if so. Attached patch try to convert long to int, and so it fix the intial problem: assert isinstance(int(De

[issue5377] Strange behavior when performing int on a Decimal made from -sys.maxint-1

2009-02-28 Thread Mark Dickinson
Changes by Mark Dickinson : -- type: behavior -> feature request ___ Python tracker ___ ___ Python-bugs-list mailing list Unsubscribe:

[issue5377] Strange behavior when performing int on a Decimal made from -sys.maxint-1

2009-02-28 Thread Mark Dickinson
Mark Dickinson added the comment: The behaviour doesn't contradict the documentation, as far as I can tell, so I agree with Terry that this is not a bug. If we want the result from the built-in int function to have type int whenever possible (that is, whenever the result is in the closed in

[issue5377] Strange behavior when performing int on a Decimal made from -sys.maxint-1

2009-02-28 Thread STINNER Victor
STINNER Victor added the comment: @tjreedy: Do you expect conversion to small int if __int__() result fits in a small int? class A: def __int__(self): return 1L x=int(A()) print repr(x), type(x) Result with Python 2.5.1: 1L ___ Pyth

[issue5377] Strange behavior when performing int on a Decimal made from -sys.maxint-1

2009-02-27 Thread Terry J. Reedy
Terry J. Reedy added the comment: Unless there is a discrepancy between doc and behavior, this strikes me as an unspecified implementation detail. If so, it should be either closed or changed to a specific feature request. -- nosy: +tjreedy ___ Pyth

[issue5377] Strange behavior when performing int on a Decimal made from -sys.maxint-1

2009-02-27 Thread Mark Dickinson
Mark Dickinson added the comment: For anyone who does care about this, it should be noted that the Fraction type has similar issues. The following comes from Python 2.7 on a 64-bit machine: >>> int(Fraction(2**63-1)) 9223372036854775807L >>> int(2**63-1) 9223372036854775807 __

[issue5377] Strange behavior when performing int on a Decimal made from -sys.maxint-1

2009-02-27 Thread Mark Dickinson
Mark Dickinson added the comment: Why do you care whether the result is an int or a long in this case? Does it affect any code that you know of in a meaningful way? > And why the difference in this behavior between 2.5.1 and 2.5.2. There were some fairly major changes (many bugfixes, new func

[issue5377] Strange behavior when performing int on a Decimal made from -sys.maxint-1

2009-02-26 Thread Thomas Heller
Changes by Thomas Heller : -- assignee: theller -> ___ Python tracker ___ ___ Python-bugs-list mailing list Unsubscribe: http://mail.

[issue5377] Strange behavior when performing int on a Decimal made from -sys.maxint-1

2009-02-26 Thread Thomas Heller
Changes by Thomas Heller : -- components: -ctypes nosy: -theller ___ Python tracker ___ ___ Python-bugs-list mailing list Unsubscribe

[issue5377] Strange behavior when performing int on a Decimal made from -sys.maxint-1

2009-02-26 Thread STINNER Victor
STINNER Victor added the comment: Anyway, the behaviour is correct. But ok, it's "strange" because unexpected. You have to understand the fact the long=>int conversion is manual :-/ Decimal.__int__ might force return int(result) at the end to avoid problem with -sys.maxint, but is it really i

[issue5377] Strange behavior when performing int on a Decimal made from -sys.maxint-1

2009-02-26 Thread STINNER Victor
Changes by STINNER Victor : ___ Python tracker ___ ___ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python

[issue5377] Strange behavior when performing int on a Decimal made from -sys.maxint-1

2009-02-26 Thread STINNER Victor
STINNER Victor added the comment: Anyway, the behaviour in correct. But ok, it's "strange" because unexpected. You have to understand the fact the long=>int conversion is manual :-/ Decimal.__int__ might force return int(result) at the end to avoid problem with -sys.maxint, but is it really i

[issue5377] Strange behavior when performing int on a Decimal made from -sys.maxint-1

2009-02-26 Thread STINNER Victor
STINNER Victor added the comment: > the question is why would the second int() return an int, > if it's indeed a long? Python doesn't convert long to int even if the long can fit in an int. Example: >>> type(1) >>> type(1L) >>> type(1L+1) >>> type(2) Even if 1L and 2L can fit in a int,

[issue5377] Strange behavior when performing int on a Decimal made from -sys.maxint-1

2009-02-26 Thread Gregory Golberg
Gregory Golberg added the comment: Well, yes, the workaround works, but the question is why would the second int() return an int, if it's indeed a long? And why the difference in this behavior between 2.5.1 and 2.5.2. ___ Python tracker

[issue5377] Strange behavior when performing int on a Decimal made from -sys.maxint-1

2009-02-26 Thread STINNER Victor
STINNER Victor added the comment: For a Decimal object (d), int(d) calls d.__int__(). In your example, d has the attributes: * _sign=1 (negative) * _exp=0 (10^0=1) * _int='2147483648' d.__int__() uses s*int(self._int)*10**self._exp <=> -(int('2147483648')). Since int('2147483648') creates a l

[issue5377] Strange behavior when performing int on a Decimal made from -sys.maxint-1

2009-02-26 Thread Gregory Golberg
New submission from Gregory Golberg : On some Python builds (2.5.2 and 2.6.1) the following program: import sys from decimal import Decimal def show(n): print type(n) d = Decimal(str(n)) i = int(d) t = type(i) print t i2 = int(i) t2 = type(i2) print t2 n = - sys