arrow icon indicating copy to clipboard operation
arrow copied to clipboard

[Go] compute.Divide results integer value not in range error

Open Yifeng-Sigma opened this issue 3 years ago • 2 comments

Describe the bug, including details regarding any error messages, version, and platform.

func TestDivide (t *testing. T) {
	builder := array.NewInt64Builder(memory.NewGoAllocator())
	builder.Append(12345000000000000)
	arr := builder.NewArray()
	_, err := compute.Divide(context.TODO(), compute.ArithmeticOptions{NoCheckOverflow: false},
		&compute.ArrayDatum{Value: arr.Data()},
		compute.NewDatum(math.Pow10(int(16))))
	if err != nil {
		t.Fatal(err)
	}
}

is giving me invalid: integer value 12345000000000000 not in range: -9007199254740992 to 9007199254740992

Component(s)

Go

Yifeng-Sigma avatar Aug 02 '23 21:08 Yifeng-Sigma

The second argument to the division is compute.NewDatum(math.Pow10(int(16)))) which will be a float64 since that's the type returned by math.Pow10. In the case of an int64 divided by a float64, the integer gets promoted. So it first tries to cast 12345000000000000 to a float64, which is invalid because the largest integer that can be represented by a float64 is 2^53, or 9007199254740992.

If you want to allow the overflow and disable the check, you can change NoCheckOverflow: false to NoCheckOverflow: true.

zeroshade avatar Aug 03 '23 23:08 zeroshade

Closing as it doesn't appear to be a bug or issue on our side. Feel free to reopen if necessary!

zeroshade avatar Sep 14 '23 16:09 zeroshade