From ad2307c92c15f0aa90dbd0741fd2538719d0b5e1 Mon Sep 17 00:00:00 2001 From: Damien George Date: Wed, 7 Jan 2015 12:10:47 +0000 Subject: py: Temporary fix for conversion of float to int when fits in small int. Addresses issue #1044 (see also #1040). Could do with a better fix. --- tests/float/float2int.py | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) (limited to 'tests/float/float2int.py') diff --git a/tests/float/float2int.py b/tests/float/float2int.py index 42210b441..462964287 100644 --- a/tests/float/float2int.py +++ b/tests/float/float2int.py @@ -1,22 +1,21 @@ -# This case occurs with time.time() values -print(int(1418774543.)) +# check cases converting float to int, relying only on single precision float +print(int(14187745.)) print(int(2.**100)) - -print("%d" % 1418774543.) - +print("%d" % 14187745.) print("%d" % 2.**100) testpass = True -for i in range(0,1024): +for i in range(0,128): bitcnt = len(bin(int(2.**i))) - 3; if i != bitcnt: print('fail: 2**%u was %u bits long' % (i, bitcnt)); testpass = False print("power of 2 test: %s" % (testpass and 'passed' or 'failed')) +# TODO why does 10**12 fail this test for single precision float? testpass = True -for i in range(0,23): +for i in range(0,12): digcnt = len(str(int(10.**i))) - 1; if i != digcnt: print('fail: 10**%u was %u digits long' % (i, digcnt)); @@ -34,3 +33,7 @@ try: int(float('nan')) except ValueError: print("ValueError") + +# test numbers < 1 (this used to fail; see issue #1044) +import struct +struct.pack('I', int(1/2)) -- cgit v1.2.3