question

Michael M11 avatar image
0 Likes"
Michael M11 asked Michael M11 commented

0 as double or int

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.




FlexSim 20.2.2
bugflexsim 20.2.2
· 1
5 |100000

Up to 12 attachments (including images) can be used with a maximum of 23.8 MiB each and 47.7 MiB total.

Benjamin W2 avatar image Benjamin W2 commented ·

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 0 ·

1 Answer

Joerg Vogel avatar image
1 Like"
Joerg Vogel answered Michael M11 commented

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.

· 2
5 |100000

Up to 12 attachments (including images) can be used with a maximum of 23.8 MiB each and 47.7 MiB total.

Phil BoBo avatar image Phil BoBo ♦♦ commented ·

@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.

0 Likes 0 ·
Michael M11 avatar image Michael M11 Phil BoBo ♦♦ commented ·

Thank you!

0 Likes 0 ·