diff options
author | Damien George <damien.p.george@gmail.com> | 2015-01-07 12:10:47 +0000 |
---|---|---|
committer | Damien George <damien.p.george@gmail.com> | 2015-01-07 12:10:47 +0000 |
commit | ad2307c92c15f0aa90dbd0741fd2538719d0b5e1 (patch) | |
tree | 3082ec3627306b5f674364900f2ede2bceb40a8e /tests/float/float2int.py | |
parent | d8bfd77ad5df1417094f125efa9b97a8d35c03cb (diff) | |
download | micropython-ad2307c92c15f0aa90dbd0741fd2538719d0b5e1.tar.gz micropython-ad2307c92c15f0aa90dbd0741fd2538719d0b5e1.zip |
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.
Diffstat (limited to 'tests/float/float2int.py')
-rw-r--r-- | tests/float/float2int.py | 17 |
1 files changed, 10 insertions, 7 deletions
diff --git a/tests/float/float2int.py b/tests/float/float2int.py index 42210b4413..4629642874 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)) |