question

Mischa Spelt avatar image
1 Like"
Mischa Spelt asked Phil BoBo commented

Ternary incorrectly deducing type

Hi,

It seems the type of a ternary expression a ? b : c is sometimes determined incorrectly. Consider the following four expressions:

true ? 1 : 0.5   // (1)
true ? 0.5 : 1   // (2)
false ? 1 : 0.5  // (3)
false ? 0.5 : 1  // (4)

I'd expect (1) and (4) to be equivalent and evaluate to 1, and (2) and (3) to be equivalent with a value of 0.5.

That expectation is mostly met, except by number (3): apparently ( false ? 1 : 0.5 ) == 0. It seems the type of the result is determined by the "true" branch: false ? 1.0 : 0.5 does indeed return 0.5.

Is this a bug or just weird? :-)

FlexSim 20.1.0
flexsim 20.1.0ternary operator
5 |100000

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

1 Answer

Phil BoBo avatar image
1 Like"
Phil BoBo answered Phil BoBo commented

Somehow this got overlooked. I'll add a case to the dev list.

Definitely weird. I'd classify it as a bug.

I think (false ? 1 : 0.5) should return 0.5 and not get truncated to 0.

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

Mischa Spelt avatar image Mischa Spelt commented ·

Hi Phil, just checking if this got added to the dev list, because the bug is still there in 21.0b :-)

0 Likes 0 ·
Phil BoBo avatar image Phil BoBo ♦♦ Mischa Spelt commented ·

Yes it is on the dev list. We haven't fix it yet. You should continue to use the workaround of using a floating point number in the first result if you want a floating point number returned by the expression.

0 Likes 0 ·