large numbers in variable

Moderators: grovkillen, Stuntteam, TD-er

Post Reply
Message
Author
GravityRZ
Normal user
Posts: 206
Joined: 23 Dec 2019, 21:24

large numbers in variable

#1 Post by GravityRZ » 13 Feb 2021, 09:19

i recently discovered %unixtime% and i use this to time things(delta between actions)
to be save i replaced it with %syssec_d% but discovered that this value resets every day(duhh) and that was causing other problems

to keep things simple i want to do this

Let,4,%unixtime%-1613000000

this will give me a 6 digit number which is small enough to write savely to the variable.
It is working great.

my question is:
is espeasy made for these large calculations?

Patou
Normal user
Posts: 106
Joined: 21 May 2018, 10:33

Re: large numbers in variable

#2 Post by Patou » 13 Feb 2021, 10:07

Look at this post there is the answer
viewtopic.php?f=4&t=8149#p48722
Have a good day

GravityRZ
Normal user
Posts: 206
Joined: 23 Dec 2019, 21:24

Re: large numbers in variable

#3 Post by GravityRZ » 13 Feb 2021, 10:18

ok.
that post learns me that when i convert a unixtime value (1607951606) to binary i get around 31 bits so unixtime does not fit a variable if it can only hold 22 bits

my question however was not if it will fit or not but if it can do these large calculations.
i assume that for calculations the ESPeasy software also reserves a certain addressable bit range(i hope 32 bits)

TD-er
Core team member
Posts: 8759
Joined: 01 Sep 2017, 22:13
Location: the Netherlands
Contact:

Re: large numbers in variable

#4 Post by TD-er » 13 Feb 2021, 11:49

Like I said, the recent changes related to variables (also used in calculations) now use double instead of float.
So this allows for storing 32 bit (and even slightly more) int values without loosing decimals.
float is a 32 bit IEEE 754 single precision Floating Point Number1 bit for the sign, (8 bits for the exponent, and 23* for the value), i.e. float has 7 decimal digits of precision.
double is a 64 bit IEEE 754 double precision Floating Point Number (1 bit for the sign, 11 bits for the exponent, and 52* bits for the value), i.e. double has 15 decimal digits of precision.
Source:
Meaning you can even multiply a 30 bit value with a 21 bit value and still not loosing decimals.
So values upto 2^51 - 1 will not loose decimals. (and of course negative values too)

GravityRZ
Normal user
Posts: 206
Joined: 23 Dec 2019, 21:24

Re: large numbers in variable

#5 Post by GravityRZ » 13 Feb 2021, 13:33

thanks TD-er

Post Reply

Who is online

Users browsing this forum: No registered users and 14 guests