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

Add support for bitwise operators #207

Closed
ShengXiangXiong opened this issue Nov 9, 2021 · 6 comments
Closed

Add support for bitwise operators #207

ShengXiangXiong opened this issue Nov 9, 2021 · 6 comments
Labels

Comments

@ShengXiangXiong
Copy link

val := `1 & 1`
complie, err := expr.Compile(val)
r, err := expr.Run(complie,env)
if err!=nil {
fmt.Printf("%+v", err)
}
if v, ok := r.(int); ok {
fmt.Printf("%+v", v)
}

image

@antonmedv
Copy link
Member

Nope, no bit operators.

@ShengXiangXiong
Copy link
Author

Nope, no bit operators.

Can this feature be added in the future

@antonmedv
Copy link
Member

Maybe.

@antonmedv antonmedv changed the title Does expr support the '&' operator Add support for bitwise operators Nov 5, 2022
@antonmedv
Copy link
Member

I'm thinking to add bit ops with such functions:

  • shl(int, int) – signed shift left
  • shr(int, int) – signed shift right
  • ushr(int, int) – unsigned shift right
  • band(int, int) – bitwise AND
  • bor(int, int) – bitwise OR
  • xor(int) – bitwise XOR
  • inv(int) – bitwise inversion

@lublak
Copy link

lublak commented Sep 4, 2023

@antonmedv i think function is the solution.
The signs | and ^ are already used for something else.
It should not be used twice.

@antonmedv
Copy link
Member

Now Expr supports bit operations. See https://expr-lang.org/docs/language-definition#bitwise-functions

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

No branches or pull requests

3 participants