govaluate icon indicating copy to clipboard operation
govaluate copied to clipboard

Supporting negative values

Open swill opened this issue 6 years ago • 2 comments

I am seeing a lot of my users doing expressions like this which are causing problems 5*-3. What they mean is 5*(-3), but they are expecting the evaluation to work. The same for something like 5*+3, which does not evaluate without error.

I wonder if there is a way to make the expression handling more robust so it can handle -/+ signing of values without requiring brackets?

swill avatar May 24 '18 18:05 swill

Huh, I'm surprised I didn't have a test case for this - this should work. But it looks like I only made test cases for when the prefixed value is on the left-hand side of such an expression (like -1 > foo). This is definitely a bug.

Knetic avatar Jun 17 '18 19:06 Knetic

@Knetic Problem does not been fixed?

expression, _ := govaluate.NewEvaluableExpression("32.9<-10")
result, _ := expression.Evaluate(nil)
log.Println(result)

Not work, Error:

panic: runtime error: invalid memory address or nil pointer dereference [recovered]
	panic: runtime error: invalid memory address or nil pointer dereference

Oh! Looks like <- caused the problem, 32.9 < -10 worked, 32.9 <-10 not.

So, must have space between Logical symbol.

alx696 avatar Jan 31 '19 06:01 alx696