Issues with uint64 when using in expression
darh opened this issue · 1 comments
darh commented
Hi,
Looks like gval is corrupting and returning float64 instead of uint64 when evaluating simple expression.
I'm probably missing something obvious here :)
func TestGval(t *testing.T) {
tUint64 := uint64(197830758113476796)
fmt.Printf("%d %T \n", tUint64, tUint64)
{
eval, _ := gval.Full().NewEvaluable(`a`)
rval, _ := eval(context.Background(), map[string]interface{}{"a": tUint64})
fmt.Printf("%d %T (as expected, got uint64) \n", rval, rval)
}
{
eval, _ := gval.Full().NewEvaluable(`a+0`)
rval, _ := eval(context.Background(), map[string]interface{}{"a": tUint64})
fmt.Printf("%f %T (got float, not expected...) \n", rval, rval)
}
{
eval, _ := gval.Full().NewEvaluable(`A+0`)
rval, _ := eval(context.Background(), struct{ A uint64 }{A: tUint64})
fmt.Printf("%f %T (got float, not expected...) \n", rval, rval)
}
}
Results:
=== RUN TestGval
197830758113476796 uint64
197830758113476796 uint64 (as expected, got uint64)
197830758113476800.000000 float64 (got float, not expected...)
197830758113476800.000000 float64 (got float, not expected...)
generikvault commented
Yes, this is the behavior as described in the documentation.
If you need uint64 you can replace the arithmetic operators with your own operators.