Operator Precedence in C
This blog record how I debugged a problem while I was implementing float subtraction solely based on integer subtraction.
Operator Precedence in C
What is some potential problem of the following code:
This code is a special case when subtracting two float numbers with different sign.
1 |
|
As I mentioned in the title, I was trying to check whether
mantissa_f + mantissa_g
exceeded the 2. If so, I need to
reduce it to 1 point something and change the exponent. Yet the if
statement does not work as I expected. This is because the
==
operator has a higher precedence than
the &
operator.
Thus, the correct way of writing is
if ((mantissa_res & BIT24_MASK) == BIT24_MASK)
or
if (mantissa_res & BIT24_MASK)
Operator Precedence in C
http://blog.slray.com/2023/10/26/Operator-Precedence-in-C/