Jan-28-2018, 04:23 AM
Jan-28-2018, 05:10 AM
but long integers in python 2 are not the same as a double in 'C':
Quote:Long integers have unlimited precision. Floating point numbers are usually implemented using double in Cfrom: https://docs.python.org/2/library/stdtypes.html
Jan-28-2018, 05:30 AM
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 -9223372036854775809LSo 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) ...
Jan-29-2018, 05:56 AM
i guess i have to consider that a Pyton3 implementation might do it all different than a Pythin2 implementation. i was looking to know a limit to run at for speed, but this could vary by implementation, all else being the same, about the only thing i can count on is that the limit won't be less than 127.
Jan-29-2018, 06:29 AM
(Jan-29-2018, 05:56 AM)Skaperen Wrote: [ -> ]this could vary by implementationIn python 3, you could perhaps get a more general result with
import sys BLEN = sys.maxsize.bit_length() def int_suffices(n): return n >> BLEN in (-1, 0)