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:

  1. true ? 1 : 0.5 // (1)
  2. true ? 0.5 : 1 // (2)
  3. false ? 1 : 0.5 // (3)
  4. 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.