BTSJimin's blog

By BTSJimin, history, 7 weeks ago, In English

Sometimes, I use too much '(',')' because of this anxiety:

if( ( ((a+5)/2)  + (c*2))  == ((((b^1)&1) * 2) + 3) ){
    blabla;
}

How to solve this issue?

  • Vote: I like it
  • +39
  • Vote: I do not like it

»
7 weeks ago, # |
  Vote: I like it +1 Vote: I do not like it

lmao same (╥﹏╥)

»
7 weeks ago, # |
  Vote: I like it 0 Vote: I do not like it

Me too lol

»
7 weeks ago, # |
  Vote: I like it +12 Vote: I do not like it

I just use them with bitwise operations

»
7 weeks ago, # |
  Vote: I like it +38 Vote: I do not like it

You needn't (and, shouldn't) solve this issue.

You needn't to spend a lot of time debugging on a few brackets.

»
7 weeks ago, # |
  Vote: I like it 0 Vote: I do not like it

can someone explain it for me?

  • »
    »
    7 weeks ago, # ^ |
    Rev. 3   Vote: I like it +16 Vote: I do not like it

    I think he means this :

    1^0==0 return true

    (1^0)==0 return false

    (I might be wrong)

»
7 weeks ago, # |
  Vote: I like it +3 Vote: I do not like it

same. Also this happens in math when im writing equations lol.

»
7 weeks ago, # |
  Vote: I like it +24 Vote: I do not like it

If you are on Linux, use man operator for your quick reference (online manual of operator(7)).

Generally, I think it's fine to use parentheses for bitwise and logical operators. Precedence of arithmetic operators is easy to remember.

»
7 weeks ago, # |
  Vote: I like it +36 Vote: I do not like it

I try to put intermediate values into temporary variables. It also makes things faster when I get WA and need to debug

»
7 weeks ago, # |
  Vote: I like it -56 Vote: I do not like it

use ChatGPT it's straight forward

»
7 weeks ago, # |
  Vote: I like it +11 Vote: I do not like it

I don’t think this is a problem. In fact, when expressions involve multiple bitwise operations, using extra parentheses is often a good practice as it helps prevent any potential precedence errors. So, this approach can actually make your code clearer and safer.

»
7 weeks ago, # |
  Vote: I like it 0 Vote: I do not like it

For a complete list, check this link.

Here, Operators are arranged from highest to lowest precedence. Operators at the top are evaluated first, while those with the same precedence are evaluated based on their associativity.