Ternary incorrectly deducing type

Ternary incorrectly deducing type

mischa_spelt
Advisor Advisor
18 Views
3 Replies
Message 1 of 4

Ternary incorrectly deducing type

mischa_spelt
Advisor
Advisor

[ FlexSim 20.1.0 ]

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? 🙂

Accepted solutions (1)
19 Views
3 Replies
Replies (3)
Message 2 of 4

philboboADSK
Autodesk
Autodesk
Accepted solution

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.



Phil BoBo
Sr. Manager, Software Development
Message 3 of 4

mischa_spelt
Advisor
Advisor

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

0 Likes
Message 4 of 4

philboboADSK
Autodesk
Autodesk

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.



Phil BoBo
Sr. Manager, Software Development
0 Likes