Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
int vs long
#3
Here is what I got in a python 2 console
Python 2.7.12 (default, Dec  4 2017, 14:50:18) 
[GCC 5.4.0 20160609] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import sys
>>> sys.maxint
9223372036854775807
>>> sys.maxint + 1
9223372036854775808L
>>> sys.maxint + 1 == 2 ** 63
True
>>> - sys.maxint - 1
-9223372036854775808
>>> - sys.maxint - 2
-9223372036854775809L
So a good test seems to be
>>> def int_suffices(n):
...     return - 2 ** 63 <= n < 2 ** 63
...
# OR
>>> def int_suffices(n): return n >> 63 in (-1, 0)
...
Reply


Messages In This Thread
int vs long - by Skaperen - Jan-28-2018, 04:23 AM
RE: int vs long - by Larz60+ - Jan-28-2018, 05:10 AM
RE: int vs long - by Gribouillis - Jan-28-2018, 05:30 AM
RE: int vs long - by Skaperen - Jan-29-2018, 05:56 AM
RE: int vs long - by Gribouillis - Jan-29-2018, 06:29 AM

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020