Mul computes the product of the given variables.
(i1, i2 frontend.Variable, in ...frontend.Variable)
| 109 | |
| 110 | // Mul computes the product of the given variables. |
| 111 | func (builder *builder) Mul(i1, i2 frontend.Variable, in ...frontend.Variable) frontend.Variable { |
| 112 | vars := builder.toVariableIds(append([]frontend.Variable{i1, i2}, in...)...) |
| 113 | allConst := true |
| 114 | if sum, ok := builder.constantValue(vars[0]); ok { |
| 115 | for _, x := range vars[1:] { |
| 116 | if v, ok := builder.constantValue(x); ok { |
| 117 | sum = builder.field.Mul(sum, v) |
| 118 | } else { |
| 119 | allConst = false |
| 120 | break |
| 121 | } |
| 122 | } |
| 123 | if allConst { |
| 124 | return builder.toVariable(sum) |
| 125 | } |
| 126 | } |
| 127 | builder.instructions = append(builder.instructions, irsource.Instruction{ |
| 128 | Type: irsource.Mul, |
| 129 | Inputs: vars, |
| 130 | }) |
| 131 | return builder.addVar() |
| 132 | } |
| 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 { |
no test coverage detected