Replies: 1 comment 2 replies
-
|
The For this, we have type circuit struct {
X, Y frontend.Variable
Input frontend.Variable
Ret frontend.Variable
}
func (c *circuit) Define(api frontend.API) error {
isEqual := api.IsZero(c.X, c.Y)
cmpRes := api.Cmp(c.X, c.Y)
isLess := api.IsZero(api.Add(cmpRes, 1))
isGreater := api.IsZero(api.Sub(cmpRes, 1))
// here now only one of isEqual, isLess or IsGreater is 1
res := api.Select(isEqual, 111, c.Input)
res := api.Select(isLess, 222, res)
res := api.Select(isGreater, 333, res)
api.AssertIsEqual(res, 1)
} |
Beta Was this translation helpful? Give feedback.
2 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
Hi, I'm new to gnark, and I have a question on
api.Cmp()According to comments of
api.Cmp(), its return value is aVariable(which is not a literal integer, e.g, 0, 1, -1). But how can we check the return value inif-elsestatement. Below is my sample code, where I would like to check if Variabledis 0 in if-else, but it doesn't work. It's also infeasible to convertVariableto integers (see #1050)In a nutshell, how to compare
Variablewith integers? Thanks!Comments of
api.Cmp()Beta Was this translation helpful? Give feedback.
All reactions