mansur-akhmadi commented on code in PR #1691:
URL: https://github.com/apache/arrow-go/pull/1691#discussion_r4757839766
##########
arrow/compute/cast_test.go:
##########
@@ -733,6 +733,46 @@ func (c *CastSuite) TestFloatingToInt() {
}
}
+func (c *CastSuite) TestFloatingToIntOutOfRange() {
+ // tooLarge is the smallest power of two the target can't hold.
Out-of-range
+ // conversions saturate on arm64, and for 32- and 64-bit targets the
saturated
+ // maximum rounds back to that power of two. The narrower targets are
controls:
+ // their maximum is exact in the input type.
+ tests := []struct {
+ from arrow.DataType
+ to arrow.DataType
+ tooLarge string
+ inRange string
+ expected string
+ }{
+ {arrow.PrimitiveTypes.Float64, arrow.PrimitiveTypes.Int8,
`[128]`, `[127, -128]`, `[127, -128]`},
+ {arrow.PrimitiveTypes.Float64, arrow.PrimitiveTypes.Uint8,
`[256]`, `[255]`, `[255]`},
+ {arrow.PrimitiveTypes.Float32, arrow.PrimitiveTypes.Int32,
`[2147483648]`,
+ `[2147483520, -2147483648]`, `[2147483520,
-2147483648]`},
+ {arrow.PrimitiveTypes.Float32, arrow.PrimitiveTypes.Uint32,
`[4294967296]`, `[4294967040]`, `[4294967040]`},
+ {arrow.PrimitiveTypes.Float32, arrow.PrimitiveTypes.Int64,
`[9223372036854775808]`,
+ `[9223371487098961920, -9223372036854775808]`,
`[9223371487098961920, -9223372036854775808]`},
+ {arrow.PrimitiveTypes.Float64, arrow.PrimitiveTypes.Int64,
`[9223372036854775808]`,
+ `[9223372036854774784, -9223372036854775808]`,
`[9223372036854774784, -9223372036854775808]`},
+ {arrow.PrimitiveTypes.Float32, arrow.PrimitiveTypes.Uint64,
`[18446744073709551616]`,
+ `[18446742974197923840]`, `[18446742974197923840]`},
+ {arrow.PrimitiveTypes.Float64, arrow.PrimitiveTypes.Uint64,
`[18446744073709551616]`,
+ `[18446744073709549568]`, `[18446744073709549568]`},
+ {arrow.FixedWidthTypes.Float16, arrow.PrimitiveTypes.Int16,
`[32768]`, `[32752, -32768]`, `[32752, -32768]`},
+ }
+
+ for _, tt := range tests {
+ c.Run(tt.from.String()+" to "+tt.to.String(), func() {
+ c.checkCastFails(tt.from, tt.tooLarge,
compute.SafeCastOptions(tt.to))
+ c.checkCastFails(tt.from, `[1, null, `+tt.tooLarge[1:],
compute.SafeCastOptions(tt.to))
+ c.checkCast(tt.from, tt.to, tt.inRange, tt.expected)
Review Comment:
Done in eca087f: `tooLarge` is now the bare number, wrapped as `[N]` and
`[1, null, N]`.
##########
arrow/compute/internal/kernels/numeric_cast.go:
##########
@@ -584,30 +585,34 @@ func boolToFloat16(_ *exec.KernelCtx, in []byte, out
[]float16.Num) error {
return nil
}
-func wasTrunc[InT constraints.Float | float16.Num, OutT arrow.IntType |
arrow.UintType](out OutT, in InT) bool {
+func wasTrunc[InT constraints.Float | float16.Num, OutT arrow.IntType |
arrow.UintType](out OutT, in InT, upper float64) bool {
switch v := any(in).(type) {
case float16.Num:
Review Comment:
It's in the branch commit (25f2f99) as its own last paragraph: the float16
branch compares as float32, so -0.0 casts to 0 like float32 and float64. If the
PR is squashed, I can put the same paragraph at the top of the PR description
so it ends up in the merge commit.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]