Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

NodeMCU Integer vs. Float Firmware what is different?

Tags:

nodemcu

I was asking myself what are the differences between integer and float firmware and how deal with them. All I've been able to find so far is:

the integer version which supports only integer operations and the float version which contains support for floating point calculations

Ok, so far so good, but wat does this mean in real life?

What happens, when I calculate

a = 3/2

For the float version I'd expect a = 1.5 For the integer version I'd expect a = 1. Or will a equal 2 or does it throw an error or crash or something else? I know, I've could simply flash the integer version and give it a try, but I'd also like to discuss it have it answered here. :)

What other limitations/differences exist? The main reason I am asking: I tried to run some scripts on integer version without any float operations I am aware of and some functionality simply isn't there. With the float version it works as expected.

Update:

Here ist the snippet that produces an unexpected result:

local duration = (now - eventStart)

duration is 0 with integer firmware. I'd guess it is because now an eventStart are too large for integer:

now: 1477651622514913
eventStart: 1477651619238587

So I'd say other limitations are that the integer version only supports integer operations with 31 bit values because when I convert

now = tonumber(now)

now = 2147483647 which is 2^31 - 1

so in integer firmware

1477651622514913 - 1477651619238587 = 0

is the same as

2147483647 - 2147483647

which is obviously 0

like image 875
Michi Avatar asked Oct 27 '16 16:10

Michi


2 Answers

NodeMCU developer FAQ says: "integer builds have a smaller Flash footprint and execute faster, but working in integer also has a number of pitfalls"

You've found some of the pitfalls with the 32-bit signed int number size limits.
No idea what others there might be, individual software modules may have their own.

"smaller": usually around 13kB of difference on custom 1.5.4.1final builds totaling 369-478kB

"faster": here is a comparison of integer and floating point operations, with the benchmark source if you'd like to run your own. Overall: int operations are almost 8 times faster. The difference might be smaller when the floats are whole numbers.

like image 192
kaay Avatar answered Oct 31 '22 06:10

kaay


You gave the answer to your question yourself. The integer version does not support floating point operations nor does it allow non-integer numbers.

In the integer version 3/2 is 1 rather than 1.5.

I've could simply flash the integer version and give it a try, but I'd also like to discuss it. :)

Stack Overflow is a Q&A site and is thus not well suited for discussions. Use the NodeMCU forums on esp8266.com for that.

like image 27
Marcel Stör Avatar answered Oct 31 '22 04:10

Marcel Stör