Bitwise operations allow only one argument

Create issue
Issue #720 closed
Former user created an issue

Struggling with bitwise AND. For example,

f = bin(and(10,5)) = 0b1010

bin(10) = 0b1010

bin(5) = 0b101

f = bin(or(10,5)) = 0b1010

The OR is correct, but the AND should return zero I believe.

Thanks.

Comments (9)

  1. Tey'

    The function arguments separator is ; not , (which is a decimal or thousand separator). Try bin(and(10;5)) and it should work as expected.

    That said, and(10,5) should fail as there is only 1 argument 10.5 and that does not make sense. Anyone knows if there is a valid reason for bitwise functions like and/or/xor to be able to accept a single argument?

  2. Pol Welter

    Yeah, for and and or it arguably makes sense to fall back to identity when only a single argument is given. Not for xor though IMO. Maybe we should just require >=2 arguments.

  3. Tey'

    Can you elaborate a bit more about why it makes sense for and/or please? I fail to see why a user would only give 1 argument on purpose to any bitwise functions.

    TBH, the first times I used SC, I did the exact same mistake as the reporter, thinking , was used to separate function arguments (like with many programming languages) and it took me quite a while to realize I was wrong, because the bitwise function calls did not fail.

  4. Tey'

    @polwel @heldercorreia may I send a pull request to force bitwise functions to require at least 2 arguments? I'm still not convince any user would use only 1 argument with these functions on purpose (that is, without mistaking decimal separators for argument separators).

  5. Log in to comment