Re: Question about slight deviations when using integer division with large integers.

2018-12-31 Thread Christian Seberino
Thanks to all who helped. As was previously pointed out, many other languages use truncation rather than rounding for // division. Getting the behavior you want may be as easy as replacing // with the int() function >>> x = 9 ; y = 2 >>> x // y, -x // y, (-x) // y (4, -5, -5) >>> int(x /

Re: Question about slight deviations when using integer division with large integers.

2018-12-31 Thread Paul Moore
On Mon, 31 Dec 2018 at 09:00, Christian Seberino wrote: > > Thanks. I didn’t post new code. I was just referring back to original > post. I need to duplicate the exact behavior of Java’s BigIntegers. > > I’m guessing difference between Java and Python is that Java BigIntegers do > not switch to

Re: Question about slight deviations when using integer division with large integers.

2018-12-31 Thread Cameron Simpson
On 30Dec2018 23:33, Christian Seberino wrote: Thanks. I didn’t post new code. I was just referring back to original post. I think Ian looked up the first post on Google Groups, where your code was evident. The message was incomplete when it got here (the mailing list); I don't know why.

Re: Question about slight deviations when using integer division with large integers.

2018-12-31 Thread Christian Seberino
Thanks. I didn’t post new code. I was just referring back to original post. I need to duplicate the exact behavior of Java’s BigIntegers. I’m guessing difference between Java and Python is that Java BigIntegers do not switch to floor for negatives. Possible to tweak rounding of Python to be li

Question about slight deviations when using integer division with large integers.

2018-12-31 Thread Christian Seberino
Why are the following two similar prints slightly different and how fix? >>> x = 0x739ad43ed636 >>> print(x + (-x) // 2048) 127046758190683 >>> print(x - x // 2048) 127046758190684 I'm working in an area where such deviations matter. It would nice to understand what is happening. Any help

Re: Question about slight deviations when using integer division with large integers.

2018-12-30 Thread Ian Kelly
On Sun, Dec 30, 2018 at 10:18 PM Christian Seberino wrote: > > What is simplest way to make both those > prints give same values? Any slicker way > than an if statement? Stack Overflow has a few suggestions: https://stackoverflow.com/questions/19919387/in-python-what-is-a-good-way-to-round-towar

Re: Question about slight deviations when using integer division with large integers.

2018-12-30 Thread Chris Angelico
On Mon, Dec 31, 2018 at 6:36 PM Ian Kelly wrote: > > The Google group has an initial post in this thread that didn't make it > through to the mailing list for whatever reason. For posterity, here > it is: Thanks Ian. > > Why are the following two similar prints slightly different and how fix? >

Re: Question about slight deviations when using integer division with large integers.

2018-12-30 Thread Ian Kelly
On Sun, Dec 30, 2018 at 10:27 PM Cameron Simpson wrote: > > On 30Dec2018 21:14, Christian Seberino wrote: > >What is simplest way to make both those > >prints give same values? Any slicker way > >than an if statement? > > If your post had an attachment, be aware that the python-list list drops >

Re: Question about slight deviations when using integer division with large integers.

2018-12-30 Thread Cameron Simpson
On 30Dec2018 21:14, Christian Seberino wrote: What is simplest way to make both those prints give same values? Any slicker way than an if statement? If your post had an attachment, be aware that the python-list list drops all attachments - it is a text only list. Please paste your code dire

Re: Question about slight deviations when using integer division with large integers.

2018-12-30 Thread Christian Seberino
What is simplest way to make both those prints give same values? Any slicker way than an if statement? -- https://mail.python.org/mailman/listinfo/python-list

Re: Question about slight deviations when using integer division with large integers.

2018-12-30 Thread Chris Angelico
On Mon, Dec 31, 2018 at 1:56 PM Christian Seberino wrote: > > Perhaps the "secret" is *not* do integer division with negative numbers? I have no idea what you're replying to, but integer division with negative numbers IS well defined. Python will floor - it will always round down. ChrisA -- htt

Re: Question about slight deviations when using integer division with large integers.

2018-12-30 Thread Christian Seberino
Perhaps the "secret" is *not* do integer division with negative numbers? -- https://mail.python.org/mailman/listinfo/python-list