Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Eclipse Titan » Matching Floating-Point Numbers
Matching Floating-Point Numbers [message #1766521] Thu, 22 June 2017 15:16 Go to next message
Alexander Kaiser is currently offline Alexander KaiserFriend
Messages: 13
Registered: May 2017
Junior Member
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


Re: Matching Floating-Point Numbers [message #1766541 is a reply to message #1766521] Thu, 22 June 2017 19:54 Go to previous messageGo to next message
Elemer Lelik is currently offline Elemer LelikFriend
Messages: 756
Registered: January 2015
Senior Member
Hi Alex,

you can use a template expressed as a range of float values
which could be (value-2.0e-7..value+2.0e-7)

e.g. something like:
template float t_float:=(0.99..1.1);

and a float variable which will store the received value

myPort.receive(float:?) -> value v_float;

and match them as below:

module f_test
{


template float t_float:=(0.99..1.1);

control {

var float v_float:=1.0;
var float v_float1:=0.98;
    if(match(v_float, t_float)) {log("match")}  //this will match
    else {log("no match")}
    if(match(v_float1, t_float)) {log("match1")}
    else {log("no match1")}  //this will not
    }
}



or directly at the receive statement:

myPort.receive(t_float) -> value v_float;  //will match only if the received value is within range




I hope this helps

BR

Elemer

[Updated on: Fri, 23 June 2017 05:56]

Report message to a moderator

Re: Matching Floating-Point Numbers [message #1766575 is a reply to message #1766541] Fri, 23 June 2017 08:34 Go to previous message
Alexander Kaiser is currently offline Alexander KaiserFriend
Messages: 13
Registered: May 2017
Junior Member
Hi Elemer,

that was exactly what I was looking for :)

Thank you very and best regards
Alex
Previous Topic:Add flags to the makefile
Next Topic:Resolve the reference definition in the cygwin of Titan 6.1.0
Goto Forum:
  


Current Time: Wed Jun 20 00:28:46 GMT 2018

Powered by FUDForum. Page generated in 0.02953 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top