MCPcopy Create free account
hub / github.com/ForestHubAI/edge-agents / parseMulDiv

Method parseMulDiv

go/engine/expr/parser.go:190–242  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

188}
189
190func (p *parser) parseMulDiv() (Value, error) {
191 left, err := p.parseUnary()
192 if err != nil {
193 return Value{}, err
194 }
195 for {
196 ch := p.peek()
197 if ch != '*' && ch != '/' && ch != '%' {
198 break
199 }
200 p.pos++
201 right, err := p.parseUnary()
202 if err != nil {
203 return Value{}, err
204 }
205 if left.Type == workflowapi.Float || right.Type == workflowapi.Float {
206 switch ch {
207 case '*':
208 left = FloatVal(left.AsFloat() * right.AsFloat())
209 case '/':
210 d := right.AsFloat()
211 if d == 0 {
212 return Value{}, fmt.Errorf("division by zero")
213 }
214 left = FloatVal(left.AsFloat() / d)
215 case '%':
216 d := right.AsInt()
217 if d == 0 {
218 return Value{}, fmt.Errorf("modulo by zero")
219 }
220 left = IntVal(left.AsInt() % d)
221 }
222 } else {
223 switch ch {
224 case '*':
225 left = IntVal(left.AsInt() * right.AsInt())
226 case '/':
227 d := right.AsInt()
228 if d == 0 {
229 return Value{}, fmt.Errorf("division by zero")
230 }
231 left = IntVal(left.AsInt() / d)
232 case '%':
233 d := right.AsInt()
234 if d == 0 {
235 return Value{}, fmt.Errorf("modulo by zero")
236 }
237 left = IntVal(left.AsInt() % d)
238 }
239 }
240 }
241 return left, nil
242}
243
244func (p *parser) parseUnary() (Value, error) {
245 ch := p.peek()

Callers 1

parseAddSubMethod · 0.95

Calls 6

parseUnaryMethod · 0.95
peekMethod · 0.95
FloatValFunction · 0.85
IntValFunction · 0.85
AsFloatMethod · 0.80
AsIntMethod · 0.80

Tested by

no test coverage detected