Matching Floating-Point Numbers [message #1766521] |
Thu, 22 June 2017 11:16  |
Eclipse User |
|
|
|
Hey everyone,
currently, I'm building a Test System which simply pushes data over MQTT into our cloud, reads them back over HTTP and compares the data subsequently. The basic flow of the data looks as follows
+------------+ +-------------+
| TestSystem | MQTT publish | SUT |
| +--------------------> |
| | | |
| | HTTP GET Request | |
| <--------------------+ |
+------------+ +-------------+
And here my problem begins.
When I publish integers everything is fine and works as intended. But when I publish float values the matching logic does not work anymore.
Because the data is processed in the back-end before I get it back the reason is quite obvious. The difference between the sent and received floats is roughly 2.0e-7.
I'm aware of that comparing floating-point numbers should be done somehow like if(abs(floatA - floatB) < threshold)
But in my case, I'm using the match function to compare templates with the responses coming from the SUT which may or may not contain floating-point numbers.
Is it still possible to use the match function in such cases?
Kind regards,
Alex
|
|
|
|
|
Powered by
FUDForum. Page generated in 0.03724 seconds