11-18-2024 07:09 PM
@littlesphaeroid wrote:
Another way to do this comparison is to multiple by some factor (in your case, 1000) to then cast to (signed) integers (both will be -2), and compare those.
That's my quick n dirty favorite method. Really multiply both by 10^x where x is the number of places to compare to and then do your casting. Negative powers give you places on the left e.g., 10^-2 gives you comparisons to the nearest 100. And 10^0 gives you comparisons to the nearest integer.
11-19-2024 04:52 AM
Thank you for the responses. I've realized what I had overlooked. My question now is: what would be the most efficient way to perform this comparison? I tested converting to a String and then back to a Double, and it appears to be the fastest method. Are there any other approaches you would recommend? I also tried GPower's "IsEqualize" function, which gives accurate results as well. Any advice would be greatly appreciated.
11-19-2024 04:57 AM
Number to string and back to number being the fastest method? If you mean fastest in terms of getting some result that works most of the time maybe. But efficient in terms of CPU power it definitely is not!
11-19-2024 05:09 AM
I know it doesn’t seem logical, but that’s what my tests have shown. Beyond finding a solution, I would also appreciate advice on comparing two pieces of code that perform the same operation. Currently, I measure runtime by recording the start and end times and calculating the difference. According to these measurements, the conversion method appears to be the fastest.
11-19-2024 05:24 AM
We learned in engineering college: "Wer misst misst Mist"
That is German and means roughly translated: "When you measure you measure shit"
This is generally true with every form of measurement unless you are extremely careful and understand exactly all the possible inaccuracies, potential pitfalls and measurement errors.
It is double as much true when measuring runtime performance of software code! Our resident specialist on benchmarking software in general and LabVIEW code in special is Christian Altenbach. I haven't seen him reviewing any benchmark VI and not having at least a few remarks about why that benchmark doesn't measure what the original developer thought he was measuring. 😁
11-19-2024 10:15 AM
@maxnoder1995 wrote:
Thank you for the responses. I've realized what I had overlooked. My question now is: what would be the most efficient way to perform this comparison? I tested converting to a String and then back to a Double, and it appears to be the fastest method. Are there any other approaches you would recommend? I also tried GPower's "IsEqualize" function, which gives accurate results as well. Any advice would be greatly appreciated.
See the link in my previous post. That attached code is as peer reviewed and documented as possible (including a trip through a thread on the Champion board to get feedback when I used to be a non-emeritous LabVIEW Champion.) The linked thread also discusses other approaches to floating point comparisons;
The related documentation also links to other sources directly related to floating point comparisons.