MCPcopy Create free account
hub / github.com/PolyhedraZK/ExpanderCompilerCollection / Div

Method Div

ecgo/builder/api.go:161–181  ·  view source on GitHub ↗

Div returns the result of i1 divided by i2.

(i1, i2 frontend.Variable)

Source from the content-addressed store, hash-verified

159
160// Div returns the result of i1 divided by i2.
161func (builder *builder) Div(i1, i2 frontend.Variable) frontend.Variable {
162 vars := builder.toVariableIds(i1, i2)
163 v1 := vars[0]
164 v2 := vars[1]
165 c1, ok1 := builder.constantValue(v1)
166 c2, ok2 := builder.constantValue(v2)
167 if ok1 && ok2 {
168 if c2.IsZero() {
169 panic("division by zero")
170 }
171 inv, _ := builder.field.Inverse(c2)
172 return builder.toVariable(builder.field.Mul(c1, inv))
173 }
174 builder.instructions = append(builder.instructions, irsource.Instruction{
175 Type: irsource.Div,
176 X: v1,
177 Y: v2,
178 ExtraId: 0,
179 })
180 return builder.addVar()
181}
182
183// Inverse returns the multiplicative inverse of the given variable.
184func (builder *builder) Inverse(i1 frontend.Variable) frontend.Variable {

Callers 6

InverseMethod · 0.95
randomCircuitMethod · 0.80
fromMyBitFormFunction · 0.80
andFunction · 0.80
fromMyBitFormFunction · 0.80
andFunction · 0.80

Calls 7

toVariableIdsMethod · 0.95
constantValueMethod · 0.95
toVariableMethod · 0.95
addVarMethod · 0.95
IsZeroMethod · 0.80
InverseMethod · 0.45
MulMethod · 0.45

Tested by

no test coverage detected