Div returns the result of i1 divided by i2.
(i1, i2 frontend.Variable)
| 159 | |
| 160 | // Div returns the result of i1 divided by i2. |
| 161 | func (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. |
| 184 | func (builder *builder) Inverse(i1 frontend.Variable) frontend.Variable { |
no test coverage detected