Bitwise operations allow only one argument
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)
-
-
Yeah, for
and
andor
it arguably makes sense to fall back to identity when only a single argument is given. Not forxor
though IMO. Maybe we should just require >=2 arguments. -
- changed title to Bitwise operations with only a single argument
-
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. -
repo owner - changed status to invalid
-
@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).
-
Go ahead.
-
repo owner - changed version to 0.12
-
assigned issue to
- changed component to functions
- changed title to Bitwise operations allow only one argument
- changed milestone to 1.0
-
repo owner - changed status to closed
- Log in to comment
The function arguments separator is
;
not,
(which is a decimal or thousand separator). Trybin(and(10;5))
and it should work as expected.That said,
and(10,5)
should fail as there is only 1 argument10.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?