06-30-2017 01:56 PM
Hello,
can anybody please throw some light on the "under the hood" of this simple snippet?
If you run the vi repeatedly you can observe that the boolean indicator is sometimes true sometimes false depending on the timestamp from Get Date/Time in Seconds vi. Can you tell what exactly it depends on?
I'd expect that the 'Scan from String' and 'Format Date/Time String' vis would work in a 'inverse' manner one to the other but it doesn't seems so. I see that the difference between the timestamps is of value of the LSB of the time stamp data type - it makes me think of a different way in rounding the value somewhere, but where and why?
Solved! Go to Solution.
06-30-2017 03:43 PM
At the end of the day, you are comparing two timestamps with each other and that is pretty much the same as comparing two floating point numbers. You really can't compare two floating points and expect equality. For one, you are taking through to a string and back. The conversion probably causes just enough change in the value that they aren't exactly equal even though it looks like they are two 19 decimal places.
07-03-2017
07:15 AM
- last edited on
10-21-2025
10:33 AM
by
Content Cleaner
RavensFan, thank you for your input.
Is this really the case of comparing TWO floats? I understand that comparing floating point numbers is tricky: if we say x = 0.1 the physical data stored will not really say that x equals 0.1 which then makes comparing x to other numbers act 'strange'. But the situation described above is more like saying x = 0.1 and then asking if x == x ? which should give true no matter how imprecisely x was stored.
According to this document:https://www.ni.com/en/support/documentation/supplemental/08/labview-timestamp-overview.html the time stamp data type in labview is a 128bit fixed point number. The conversion to/from string of fixed point number should not loose in precision, in my opinion.. so what am i missing?
07-03-2017 07:48 AM
ravyh wrote: so what am i missing?
The conversion To/From string adds error whenever decimal places are involved. It is just a limitation of using bits to define decimal places. Or maybe if you showed 100 decimal places it would be close enough for you (1/2^64 = 5.4210108624275221700372640043497e-20, as accurate as the Windows calculation shows, so good luck figuring out how many fractional seconds places you need in your string)?
07-03-2017 09:21 AM
The conversion To/From string adds error whenever decimal places are involved. It is just a limitation of using bits to define decimal places.
Could you please elaborate on this a bit more?
I (believe that I) understand the limitations of representing decimal places but i think my situation here is one step further this limitation: im not asking the compiler to create a fractional number which cannot be exactly stored in bits - i receive a well representable number from the get date/time vi or don't i?
07-03-2017 09:41 AM
ravyh wrote: im not asking the compiler to create a fractional number which cannot be exactly stored in bits - i receive a well representable number from the get date/time vi or don't i?
With only 19 decimal places, you cannot accurately go between a 64 bit number (the fractional seconds) and the string without losing accuracy. As I stated before, you need to have enough digits to accurately represent 1/(2^64). Unless you can do that, you will never have the conversion to string and back be EXACTLY the same. For 99.9999999999999999999999999999999% of the time, it will be close enough. So instead of equals, you really should be checking if the difference is less than an acceptable value.
07-04-2017 03:57 AM
Thank you!
My mistake was that i was doing the calculations with 2^64 and not 1/2^64
07-04-2017 08:06 AM
@crossrulz wrote:
So instead of equals, you really should be checking if the difference is less than an acceptable value.
Exactly! 🙂
Below is the link to the post which I coded just yesterday.