Bignum limitations on ESP8266 boards

All ESP8266 boards running MicroPython.
Official boards are the Adafruit Huzzah and Feather boards.
Target audience: MicroPython users with an ESP8266 board.
Post Reply
ProudPagan
Posts: 35
Joined: Fri Apr 12, 2019 8:55 am

Bignum limitations on ESP8266 boards

Post by ProudPagan » Sun Apr 14, 2019 4:16 am

Hi,

On the ESP8266 MicroPython prompt when I type:

Code: Select all

>>> 3 ** 5000
the board resets itself. This is the output I get on the terminal.

Code: Select all

 ets Jan  8 2013,rst cause:2, boot mode:(3,6)

load 0x40100000, len 31016, room 16
tail 8
chksum 0x9d
load 0x3ffe8000, len 1096, room 0
tail 8
chksum 0x13
load 0x3ffe8450, len 824, room 0
tail 8
chksum 0xcd
csum 0xcd
▒▒▒▒o▒r▒▒g|▒
lldl`b▒|{▒$▒n▒▒o▒l`▒▒s▒l▒l
l`▒▒{▒d▒l▒
d`▒▒r▒l
▒▒▒
dl sd▒▒sl▒▒▒c▒▒c|lc▒▒c|؄▒▒ldc▒▒g▒n▒▒lg▒
▒▒l▒ld▒
▒▒l ▒n▒▒▒▒▒c
l$섇
▒▒▒▒c
d▒b{lsds▒g▒▒▒▒▒oܟ▒▒cpc▒▒▒▒▒▒OSError: [Errno 2] ENOENT
Trying to catch the OSError does not work (board gets reset):

Code: Select all

>>> try:
...     print (3**5000)
... except (OSError):
...     print ("sorry")
...
Any help to root cause the problem is much appreciated.

BTW, can anyone confirm if bignums work on the PyBoard?

I am using the latest official firmware esp8266-20190125-v1.10.bin, connected over PuTTY

User avatar
Roberthh
Posts: 3667
Joined: Sat May 09, 2015 4:13 pm
Location: Rhineland, Europe

Re: Bignum limitations on ESP8266 boards

Post by Roberthh » Sun Apr 14, 2019 7:32 am

In general, big numbers work, e.g. 3**4000 returns a result. However limited memory may cause it to fail for larger numbers.
Edit:
The error happens at converting the number to a string. The calculation itself works up to about higher numer, e.g.:
a=3**30000
terminates well (and comparable fast). And trying larger exponents lead to a proper exception. Just printing it fails. On devices with more memory like the ESP32 the limits are higher.

ProudPagan
Posts: 35
Joined: Fri Apr 12, 2019 8:55 am

Re: Bignum limitations on ESP8266 boards

Post by ProudPagan » Mon Apr 15, 2019 3:12 am

Thanks.

Is there a MicroPython way to catch the exception (OSError in this case?)?
I would much like a more graceful exit than a soft reset.

User avatar
dhylands
Posts: 3821
Joined: Mon Jan 06, 2014 6:08 pm
Location: Peachland, BC, Canada
Contact:

Re: Bignum limitations on ESP8266 boards

Post by dhylands » Mon Apr 15, 2019 4:06 am

You can use python's try:/except: mechanism.
https://docs.python.org/3/tutorial/errors.html

Post Reply