And + or + brackets problem?

I have a very strange problem.
This statement:

const attacks: u64 =
    data.get_rook_attacks(king_sq, occ) & pos.queens_rooks(them) |
    data.get_bishop_attacks(king_sq, occ) & pos.queens_bishops(them);

gives a different result then this one (watch the brackets).

const attacks: u64 =
    (data.get_rook_attacks(king_sq, occ) & pos.queens_rooks(them)) |
    (data.get_bishop_attacks(king_sq, occ) & pos.queens_bishops(them));

The last one gives the correct result.
All the called functions return a u64.
Am I missing something? Has | not lower precedence than &??
Or is the compiler freaking (which I cannot imagine is true).

They have the same precedence, without the brackets the | happens before the second &

2 Likes

Related:

1 Like

Strange! Did not know that.
and and or do have precedence but & and | not while bitwise it is the same operation.

1 Like