summaryrefslogtreecommitdiffstatshomepage
path: root/tests/float/float2int.py
diff options
context:
space:
mode:
authorDavid Steinberg <david.steinberg.dev@gmail.com>2015-01-02 12:39:22 +0000
committerDamien George <damien.p.george@gmail.com>2015-01-02 22:31:41 +0000
commit6e0b6d02dbe238e6e3d675b51e44b2ac798ddd20 (patch)
treee9d05c0e7b27da54ee3af4fd27ebd7e227c3bf08 /tests/float/float2int.py
parentffc96a901a13f6f114368ad50a1d7189c0826822 (diff)
downloadmicropython-6e0b6d02dbe238e6e3d675b51e44b2ac798ddd20.tar.gz
micropython-6e0b6d02dbe238e6e3d675b51e44b2ac798ddd20.zip
py: Fix float to int conversion for large exponents.
Diffstat (limited to 'tests/float/float2int.py')
-rw-r--r--tests/float/float2int.py22
1 files changed, 18 insertions, 4 deletions
diff --git a/tests/float/float2int.py b/tests/float/float2int.py
index ca2914c01a..b948755de5 100644
--- a/tests/float/float2int.py
+++ b/tests/float/float2int.py
@@ -1,10 +1,24 @@
# This case occurs with time.time() values
print(int(1418774543.))
-# TODO: General case with large exponent
-#print(int(2.**100))
+print(int(2.**100))
print("%d" % 1418774543.)
-# TODO: General case with large exponent
-#print("%d" % 2.**100)
+print("%d" % 2.**100)
+
+testpass = True
+for i in range(0,1024):
+ 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'))
+
+testpass = True
+for i in range(0,23):
+ digcnt = len(str(int(10.**i))) - 1;
+ if i != digcnt:
+ print('fail: 10**%u was %u digits long' % (i, digcnt));
+ testpass = False
+print("power of 10 test: %s" % (testpass and 'passed' or 'failed'))