float/float2int*: Make actually be parsable for MICROPY_LONGINT_IMPL_NONE.
The use of large literal numbers is a big no-no when it comes to writing programs which work with different int representations. Also, some checks are pretty adhoc (e.g using struct module to check for 64-bitness). This change bases entire detection on sys.maxsize and integer operarions, and thus more correct, even if longer. Note that this change doesn't mean that any of these tests can pass with anything but MPZ - even despite checking for various int representations, the tests aren't written to be portable among them.
This commit is contained in:
parent
325c4473a5
commit
121fb88988
@ -5,21 +5,31 @@ try:
|
||||
except:
|
||||
import struct
|
||||
|
||||
import sys
|
||||
|
||||
maxsize_bits = 0
|
||||
maxsize = sys.maxsize
|
||||
while maxsize:
|
||||
maxsize >>= 1
|
||||
maxsize_bits += 1
|
||||
|
||||
# work out configuration values
|
||||
is_64bit = struct.calcsize("P") == 8
|
||||
is_64bit = maxsize_bits > 32
|
||||
# 0 = none, 1 = long long, 2 = mpz
|
||||
try:
|
||||
dummy = 0x7fffffffffffffff
|
||||
try:
|
||||
if (0xffffffffffffffff + 1) > 0:
|
||||
ll_type = 2
|
||||
else:
|
||||
ll_type = 1
|
||||
except:
|
||||
# in case the sum in the if statement above changes to raising an exception on overflow
|
||||
ll_type = None
|
||||
if is_64bit:
|
||||
if maxsize_bits < 63:
|
||||
ll_type = 0
|
||||
else:
|
||||
if maxsize_bits < 31:
|
||||
ll_type = 0
|
||||
if ll_type is None:
|
||||
one = 1
|
||||
if one << 65 < one << 62:
|
||||
ll_type = 1
|
||||
except:
|
||||
ll_type = 0
|
||||
else:
|
||||
ll_type = 2
|
||||
|
||||
|
||||
# basic conversion
|
||||
print(int(14187745.))
|
||||
|
@ -5,21 +5,29 @@ try:
|
||||
except:
|
||||
import struct
|
||||
|
||||
import sys
|
||||
maxsize_bits = 0
|
||||
maxsize = sys.maxsize
|
||||
while maxsize:
|
||||
maxsize >>= 1
|
||||
maxsize_bits += 1
|
||||
|
||||
# work out configuration values
|
||||
is_64bit = struct.calcsize("P") == 8
|
||||
is_64bit = maxsize_bits > 32
|
||||
# 0 = none, 1 = long long, 2 = mpz
|
||||
try:
|
||||
dummy = 0x7fffffffffffffff
|
||||
try:
|
||||
if (0xffffffffffffffff + 1) > 0:
|
||||
ll_type = 2
|
||||
else:
|
||||
ll_type = 1
|
||||
except:
|
||||
# in case the sum in the if statement above changes to raising an exception on overflow
|
||||
ll_type = None
|
||||
if is_64bit:
|
||||
if maxsize_bits < 63:
|
||||
ll_type = 0
|
||||
else:
|
||||
if maxsize_bits < 31:
|
||||
ll_type = 0
|
||||
if ll_type is None:
|
||||
one = 1
|
||||
if one << 65 < one << 62:
|
||||
ll_type = 1
|
||||
except:
|
||||
ll_type = 0
|
||||
else:
|
||||
ll_type = 2
|
||||
|
||||
# This case occurs with time.time() values
|
||||
if ll_type != 0:
|
||||
|
@ -5,21 +5,29 @@ try:
|
||||
except:
|
||||
import struct
|
||||
|
||||
import sys
|
||||
maxsize_bits = 0
|
||||
maxsize = sys.maxsize
|
||||
while maxsize:
|
||||
maxsize >>= 1
|
||||
maxsize_bits += 1
|
||||
|
||||
# work out configuration values
|
||||
is_64bit = struct.calcsize("P") == 8
|
||||
is_64bit = maxsize_bits > 32
|
||||
# 0 = none, 1 = long long, 2 = mpz
|
||||
try:
|
||||
dummy = 0x7fffffffffffffff
|
||||
try:
|
||||
if (0xffffffffffffffff + 1) > 0:
|
||||
ll_type = 2
|
||||
else:
|
||||
ll_type = 1
|
||||
except:
|
||||
# in case the sum in the if statement above changes to raising an exception on overflow
|
||||
ll_type = None
|
||||
if is_64bit:
|
||||
if maxsize_bits < 63:
|
||||
ll_type = 0
|
||||
else:
|
||||
if maxsize_bits < 31:
|
||||
ll_type = 0
|
||||
if ll_type is None:
|
||||
one = 1
|
||||
if one << 65 < one << 62:
|
||||
ll_type = 1
|
||||
except:
|
||||
ll_type = 0
|
||||
else:
|
||||
ll_type = 2
|
||||
|
||||
# basic conversion
|
||||
print(int(14187744.))
|
||||
|
Loading…
Reference in New Issue
Block a user