Help understanding ternary statement in py/objcomplex.c
Posted: Fri Feb 03, 2017 10:39 am
I just saw this change in `py/objcomplex.c` (line 225). I have no idea what the ternary statement is supposed to do. Is it a bug or some unusual use of the conditional operator?
Doesn' the first expression `1` always evaluate to true, then the second expression is always executed?
What is the purpose of the third expression `0` ?
Is this equivalent to `lhs_real = true` or `lhs = false`, depending on the value of rhs_real ?
If so, why wouldn't it be written as: `lhs_real = (rhs == 0) ;
Is this some fancy way of assigning a boolean or an integer (by some magic) ?
And I thought I knew C ?[/color]
Code: Select all
- if (rhs_imag == 0) {
- lhs_real = 1;
+ if (rhs_imag == 0 && rhs_real >= 0) {
+ lhs_real = 1 ? rhs_real == 0 : 0;
What is the purpose of the third expression `0` ?
Is this equivalent to `lhs_real = true` or `lhs = false`, depending on the value of rhs_real ?
If so, why wouldn't it be written as: `lhs_real = (rhs == 0) ;
Is this some fancy way of assigning a boolean or an integer (by some magic) ?
And I thought I knew C ?[/color]