Big float in Micropython (ESP32)

All ESP32 boards running MicroPython.
Target audience: MicroPython users with an ESP32 board.
Post Reply
MUSQAR
Posts: 8
Joined: Thu Apr 02, 2020 3:10 pm

Big float in Micropython (ESP32)

Post by MUSQAR » Mon Jun 15, 2020 8:51 pm

Hello everyone,


I'm going to use Big Float variable in Micropython(9 numbers after the 0.), after dividing between two numbers I got just 8 numbers in the result.

any information about this topic?

Thanks

User avatar
jimmo
Posts: 2065
Joined: Tue Aug 08, 2017 1:57 am
Location: Sydney, Australia
Contact:

Re: Big float in Micropython (ESP32)

Post by jimmo » Mon Jun 29, 2020 7:13 am

MicroPython uses regular IEEE single (or double in some ports) precision floating point. It's not an easy topic and it's mostly fairly counterintuitive.

This is a site that I see people link to a lot, https://floating-point-gui.de/ but there are lots of tutorials out there.

If you care about precision, you need to work entirely in integers, but for many situations you can get by with floats.

miltmobley
Posts: 29
Joined: Mon Mar 07, 2016 11:44 pm

Re: Big float in Micropython (ESP32)

Post by miltmobley » Sun Jul 26, 2020 3:22 am

In cpython, this appears to require the bigfloat package to be installed. From Python docs, we have:
"The bigfloat package is a Python wrapper for the GNU MPFR library for arbitrary-precision floating-point reliable arithmetic."
If you really need such bigger numbers, you would have to port bigfloat module to micropython and the MPFR library to its C backends.
This could be a large amount of work.

If you only need nine digits instead of eight, a software fp implementation might make sense.
And if your micropython device is normally connected to a pc host, you might be able to implement a remote procedure call to have the
host do the calculations.

miltmobley
Posts: 29
Joined: Mon Mar 07, 2016 11:44 pm

Re: Big float in Micropython (ESP32)

Post by miltmobley » Sun Jul 26, 2020 3:27 am

I just noticed there is also a "decimal" module in cpython which may do what you want, i.e. more than eight decimal places.
But if it's not in micropython,you would have to port it.

Post Reply