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

Ian Kelly ian.g.kelly at gmail.com
Mon Dec 31 02:34:35 EST 2018


On Sun, Dec 30, 2018 at 10:27 PM Cameron Simpson <cs at cskk.id.au> wrote:
>
> On 30Dec2018 21:14, Christian Seberino <cseberino at gmail.com> 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
> directly into your messages so that others can easily see it.

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:

> 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 greatly appreciated.
>
> cs


More information about the Python-list mailing list