Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Negation X2 #157

Open
yaronf opened this issue Apr 28, 2024 · 1 comment
Open

Negation X2 #157

yaronf opened this issue Apr 28, 2024 · 1 comment

Comments

@yaronf
Copy link
Contributor

yaronf commented Apr 28, 2024

It's surprising that the language supports bitwise binary operators but not the C "complement" (~) operator. It is very useful when dealing with bit strings that represent flags, value & ~mask == desired. Granted that a workaround exists, XOR with -1.

A more complicated case is simple integer negation, -X. I just found out that the Go implementation does not support negative literal integers (-100) (the Rust code does, I believe). I tried to add them by tweaking the lexer but this results in a parser ambiguity, e.g. when parsing 200-100. One simple solution is for the lexer to only support positive literals and the parser to deal with the minus/negation distinction, but that would necessitate integer negation as a unary operator.

@yaronf
Copy link
Contributor Author

yaronf commented Apr 28, 2024

Re: integer negation, the issue can be resolved within the Go implementation with no change to the language. Having said that, unary negation is indeed a standard arithmetic operator.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant