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

Method DivUnchecked

ecgo/builder/api.go:135–158  ·  view source on GitHub ↗

DivUnchecked returns i1 divided by i2 and returns 0 if both i1 and i2 are zero.

(i1, i2 frontend.Variable)

Source from the content-addressed store, hash-verified

133
134// DivUnchecked returns i1 divided by i2 and returns 0 if both i1 and i2 are zero.
135func (builder *builder) DivUnchecked(i1, i2 frontend.Variable) frontend.Variable {
136 vars := builder.toVariableIds(i1, i2)
137 v1 := vars[0]
138 v2 := vars[1]
139 c1, ok1 := builder.constantValue(v1)
140 c2, ok2 := builder.constantValue(v2)
141 if ok1 && ok2 {
142 if c2.IsZero() {
143 if c1.IsZero() {
144 return builder.toVariable(constraint.Element{})
145 }
146 panic("division by zero")
147 }
148 inv, _ := builder.field.Inverse(c2)
149 return builder.toVariable(builder.field.Mul(c1, inv))
150 }
151 builder.instructions = append(builder.instructions, irsource.Instruction{
152 Type: irsource.Div,
153 X: v1,
154 Y: v2,
155 ExtraId: 1,
156 })
157 return builder.addVar()
158}
159
160// Div returns the result of i1 divided by i2.
161func (builder *builder) Div(i1, i2 frontend.Variable) frontend.Variable {

Callers

nothing calls this directly

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