Note: by 'complex' math I mean an equation with many steps involved and a wide mix of operators.
A programmer should know the order that operators are evaluated in an equation. However it can be a royal pain to look at an equation such as:
result = value_1 + value_2 * value_1 + value_3 / value_4 % value_5;
One option is to write out the equation in multiple steps such as:
part1 = value_2 * value_1; part1 += value_1; part2 = value_4 % value_5; part2 = value_3 / part2; result = part1 + part2;
Another option is to format the original equation with parenthesis such as:
result = (value_1 + (value_2 * value_1)) + (value_3 / (value_4 % value_5));
When dealing with complex math in code, how do you typically format it to maximize readability?