DivUnchecked returns i1 divided by i2 and returns 0 if both i1 and i2 are zero.
(i1, i2 frontend.Variable)
| 133 | |
| 134 | // DivUnchecked returns i1 divided by i2 and returns 0 if both i1 and i2 are zero. |
| 135 | func (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. |
| 161 | func (builder *builder) Div(i1, i2 frontend.Variable) frontend.Variable { |
nothing calls this directly
no test coverage detected