NodeMCU Integer vs. Float 固件有什么不同?
NodeMCU Integer vs. Float Firmware what is different?
我在问自己整数和浮点固件之间的区别是什么以及如何处理它们。到目前为止我能找到的是:
the integer version which supports only integer operations and the float version which contains support for floating point calculations
好的,到目前为止一切顺利,但这在现实生活中意味着什么?
当我计算时会发生什么
a = 3/2
对于浮动版本,我希望 a = 1.5
对于整数版本,我希望 a = 1。或者等于 2 还是会引发错误或崩溃或其他问题?我知道,我可以简单地刷新整数版本并试一试,但我也想 讨论它 在这里得到答案。 :)
还有什么 limitations/differences 存在?我问的主要原因是:我尝试 运行 一些整数版本的脚本,没有任何我知道的浮点操作,并且一些功能根本不存在。对于浮动版本,它按预期工作。
更新:
下面是产生意外结果的片段:
local duration = (now - eventStart)
整数固件的持续时间为 0。我猜这是因为现在 eventStart 对于整数来说太大了:
now: 1477651622514913
eventStart: 1477651619238587
所以我想说其他限制是整数版本仅支持具有 31 位值的整数运算,因为当我转换
now = tonumber(now)
现在 = 2147483647 即 2^31 - 1
因此在整数固件中
1477651622514913 - 1477651619238587 = 0
与
相同
2147483647 - 2147483647
这显然是 0
您自己给出了问题的答案。整数版本不支持浮点运算,也不允许非整数。
在整数版本中 3/2
是 1 而不是 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 是一个问答网站,因此不太适合讨论。为此,请使用 esp8266.com 上的 NodeMCU 论坛。
NodeMCU developer FAQ 说:"integer builds have a smaller Flash footprint and execute faster, but working in integer also has a number of pitfalls"
您发现了 32 位有符号整数 数字大小限制的一些缺陷。
不知道还有什么其他的,个别软件模块可能有自己的。
"smaller":通常 大约 13kB 的差异 custom 1.5.4.1final builds 总计 369-478kB
"更快":here is a comparison of integer and floating point operations,如果您想 运行 自己的基准源。总的来说:int 操作快了几乎 8 倍。当浮点数为整数时,差异可能会更小。
我在问自己整数和浮点固件之间的区别是什么以及如何处理它们。到目前为止我能找到的是:
the integer version which supports only integer operations and the float version which contains support for floating point calculations
好的,到目前为止一切顺利,但这在现实生活中意味着什么?
当我计算时会发生什么
a = 3/2
对于浮动版本,我希望 a = 1.5
对于整数版本,我希望 a = 1。或者等于 2 还是会引发错误或崩溃或其他问题?我知道,我可以简单地刷新整数版本并试一试,但我也想 讨论它 在这里得到答案。 :)
还有什么 limitations/differences 存在?我问的主要原因是:我尝试 运行 一些整数版本的脚本,没有任何我知道的浮点操作,并且一些功能根本不存在。对于浮动版本,它按预期工作。
更新:
下面是产生意外结果的片段:
local duration = (now - eventStart)
整数固件的持续时间为 0。我猜这是因为现在 eventStart 对于整数来说太大了:
now: 1477651622514913
eventStart: 1477651619238587
所以我想说其他限制是整数版本仅支持具有 31 位值的整数运算,因为当我转换
now = tonumber(now)
现在 = 2147483647 即 2^31 - 1
因此在整数固件中
1477651622514913 - 1477651619238587 = 0
与
相同2147483647 - 2147483647
这显然是 0
您自己给出了问题的答案。整数版本不支持浮点运算,也不允许非整数。
在整数版本中 3/2
是 1 而不是 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 是一个问答网站,因此不太适合讨论。为此,请使用 esp8266.com 上的 NodeMCU 论坛。
NodeMCU developer FAQ 说:"integer builds have a smaller Flash footprint and execute faster, but working in integer also has a number of pitfalls"
您发现了 32 位有符号整数 数字大小限制的一些缺陷。
不知道还有什么其他的,个别软件模块可能有自己的。
"smaller":通常 大约 13kB 的差异 custom 1.5.4.1final builds 总计 369-478kB
"更快":here is a comparison of integer and floating point operations,如果您想 运行 自己的基准源。总的来说:int 操作快了几乎 8 倍。当浮点数为整数时,差异可能会更小。