Turn on suggestions

Auto-suggest helps you quickly narrow down your search results by suggesting possible matches as you type.

Showing results for

- Navigation
- Tecnomatix
- Forums
- Blogs
- Knowledge Bases
- Groups

- Siemens PLM Community
- Tecnomatix
- Plant Simulation
- Basic comparison of two numbers in PlantSimulation...

Options

- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page

Basic comparison of two numbers in PlantSimulation is failing

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content

04-05-2016 09:58 AM

Hi there!

PlantSimulation 11.0.12 is behaving interestingly, when comparing two equal numbers.

In the attached model, I have used a table, where column number 4 provides a real number, while column number 5 provides a result basing on a formula.

Both cells do have the same value, but PlantSimulation is assessing them as unequal (just debug the method). To easen it, I have added a debugger screenshot.

I was already wondering, why my models are not working properly at all.

Beside, I wanted to add the model where the bug can be reproduced. Nicely, this forum portal is rejecting that. Obviously Siemens doesn't want to have bugs posted any more.

Mak

10 REPLIES

Re: Basic comparison of two numbers in PlantSimulation is failing

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content

04-05-2016 10:02 AM

Hi,

At least one spp-file was posted earlier today. Bugs are best reported through GTAC.

Re: Basic comparison of two numbers in PlantSimulation is failing

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content

04-05-2016 10:02 AM

Try these expressions:

tab[5,1] - 0.000125

tab[6,1] - 0.000125

I guess you will see different results.

_________________________________________________________________

Did you like the answer? Then click the Thumbs Up button.

Did the answer solve your problem? Then accept the answer as solution.

Did you like the answer? Then click the Thumbs Up button.

Did the answer solve your problem? Then accept the answer as solution.

Re: Basic comparison of two numbers in PlantSimulation is failing

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content

04-05-2016 10:15 AM

Re: Basic comparison of two numbers in PlantSimulation is failing

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content

04-05-2016 10:32 AM

You can try this to compare the values

is var1,var2:real; do var1:= (0.05*0.05*0.05)*1000000; var2:=tab[1,1]*1000000; if round(var1,0) /= round(var2,0) then debug; end; end;

Re: Basic comparison of two numbers in PlantSimulation is failing

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content

04-05-2016 10:41 AM

You should never compare floating point numbers for an exact match. This problem is not related to Plant Simulation. Floating point numbers are stored in a base 2 representation and not base 10.

This means that 0.1 which looks to you like a number which should be exact has in base 2 endless digits.

But the computer only can store a limited number of places. This makes it difficult to compare numbers which should be the same in base 10 but have a different 'computation history'.

Regards,

Ralf

------------------------------------------------------------------------------------------------------

Did you like the answer? Then click the Thumbs Up button.

Did the answer solve your problem? Then accept the answer as solution.

Ralf

------------------------------------------------------------------------------------------------------

Did you like the answer? Then click the Thumbs Up button.

Did the answer solve your problem? Then accept the answer as solution.

Re: Basic comparison of two numbers in PlantSimulation is failing

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content

04-05-2016 10:44 AM

Just tried to upload a model and it works fine. Please retry.

Regards,

Ralf

------------------------------------------------------------------------------------------------------

Did you like the answer? Then click the Thumbs Up button.

Did the answer solve your problem? Then accept the answer as solution.

Ralf

------------------------------------------------------------------------------------------------------

Did you like the answer? Then click the Thumbs Up button.

Did the answer solve your problem? Then accept the answer as solution.

Re: Basic comparison of two numbers in PlantSimulation is failing

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content

04-05-2016 11:06 AM - edited 04-05-2016 11:10 AM

@Mak,

as Ralf stated you shouldn't directly compare real numbers as you did e.g with "\="

This has nothing to do with Plant Simulation but is a known issue to probably all known high level programming languages !

Now there are of course several solutions to your severe problem with Plant Simulation and - in this case- to all known high level languages I know of.

usually you directly compare real /float numbers like this :

abs ( a -b) <= 1e-7, where a, b are your 2 numbers to compare and 1e-7 is an individually predefined accuracy.

In Plant Simulation you can use "==" to compare and set the accuracy through set/- getepsilon.

the default accuracy for epsilon is set to 0.0000001.

Therefore test this code and see

is do local a: real :=0.05*0.05*0.05; local b :real :=0.000125; if a/=b then print "a not equal b",chr(9),chr(9),a-b; else print "a equals b",chr(9),chr(9),a-b; end; if not(a==b) then print "a not equal b",chr(9),chr(9),a-b; else print "a equals b",chr(9),chr(9),a-b; end; end;

Re: Basic comparison of two numbers in PlantSimulation is failing

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content

04-05-2016 11:18 AM

I know, it's much more easier to defend an impractical solution than to think about an improvement.

I also know about computer numerics and I am aware about the situation, that the computer systems can not handle an infinite amount of digits (behind the comma) in memory, That's the reason why it is needed to be rounded in case of real variates.

In my example - if you are so kind to look and think first instead of immediately replying - I was using rational numbers. They can be representet with fractions containing of integer values:

0.05 = 1/20

0.05 ^3 = 1*1*1/20*20*20 = 0.000125 -> no need for rounding or any other fancy workaround stuff like in case of using PI or exp.

There are quite an amount of computer programs existing that can handle fractions much more accurate than PlantSimulation does.

Re: Basic comparison of two numbers in PlantSimulation is failing

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content

04-05-2016 12:25 PM - edited 04-05-2016 04:44 PM

Apparently you have found you're own individual "solution" for yourself by

just using rational numbers.

BTW

0.05 ^3 -0.000125 =2.71050543121376e-020 ....

Follow Siemens PLM Software

© 2019 Siemens Product Lifecycle Management Software Inc