0 as double or int

0 as double or int

michael_m11
Not applicable
90 Views
4 Replies
Message 1 of 5

0 as double or int

michael_m11
Not applicable

[ FlexSim 20.2.2 ]

Hello guys,

I have a table cell that has a value of 0.000 as a result of a difference between two equal double values.

How can I query that table where cell_value=0 ? It doesn't return enithing.

Looks like int 0 is not equal with double 0.000. Is this a bug ?


Thank you.




0 Likes
Accepted solutions (1)
91 Views
4 Replies
Replies (4)
Message 2 of 5

benjamin_w2
Not applicable

Hi @michael.m11,

It's hard to know how to help without looking at your model. To receive a more accurate solution, please post your model or a sample model that demonstrates your question.

Proprietary models can be posted as a private question visible only to FlexSim U.S. support staff. You can also contact your local FlexSim distributor for phone or email help.

0 Likes
Message 3 of 5

joerg_vogel_HsH
Mentor
Mentor
Accepted solution

The difference might be zero at the first visible digits. How do you know the two floating values are the same? Have you subtracted A from A and compared it with zero. Floating point values near zero are a bit imprecise if it comes to be exact zero. Maybe you can query to a range near zero like with the clause BETWEEN value1 AND value2.

Message 4 of 5

philboboADSK
Autodesk
Autodesk

@michael.m11

See also https://en.wikipedia.org/wiki/Floating-point_arithmetic#Accuracy_problems

If you set a floating point value (such as a double) directly to 0, then it will compare to 0 just fine. If a double is the result of a mathematical calculation, it is unlikely to be precisely 0 and you shouldn't compare it to 0 using equality.

Instead of comparing a double to 0, compare whether its absolute value is less than a very small number.



Phil BoBo
Sr. Manager, Software Development
0 Likes
Message 5 of 5

michael_m11
Not applicable

Thank you!

0 Likes