I have the following code:
NodePtr bestChild = (diff < 0) ? node->child1 : node->child2;
NodePtr otherChild = (diff < 0) ? node->child2 : node->child1;
Is there any more efficient way to set a bestChild and otherChild variables?
NOTE: diff is float and comparison is quite long operation.
Also I tried the following solution:
NodePtr bestChild = (diff < 0) ? node->child1 : node->child2;
NodePtr otherChild = (bestChild == node->child2) ? node->child1 : node->child2;
In this case I don’t make one comparison, but I’m not sure that it is a best way.
Either:
or
or just leave it as it is because the compiler will probably do this for you.