mansur-akhmadi opened a new pull request, #1691:
URL: https://github.com/apache/arrow-go/pull/1691

   ### Rationale for this change
   
   Fixes #1690. On arm64, a safe float-to-integer cast of 2^n (the first power 
of two the target can't hold) returned the integer maximum instead of failing: 
float64 2^63 → int64 gave 9223372036854775807. The truncation check converts 
the result back to a float and compares. arm64 saturates out-of-range 
conversions, and the saturated maximum rounds back to 2^n, so the check passed. 
amd64 already rejected these inputs.
   
   ### What changes are included in this PR?
   
   `checkFloatTrunc` now also rejects inputs at or above 2^n for the target 
type (2^(bits-1) for signed, 2^bits for unsigned), computed once per call by 
`intUpperBound` from the existing `SizeOf`/`MinOf` helpers. The round-trip 
comparison still catches fractional values, NaN and values below the minimum. 
`wasTruncMaybeNull` now calls `wasTrunc` instead of repeating its switch.
   
   The float16 branch now does the round trip as float32 instead of comparing 
float16 bits. Before, a float16 `-0.0` failed a safe cast to int32 (`0x0000 != 
0x8000`), while float32 and float64 `-0.0` cast to `0`. Now all three behave 
the same.
   
   Not changed: `scalar.CastTo` for float → int doesn't go through this kernel 
and doesn't check truncation at all (`1.5` → `1`), so that's a separate 
question.
   
   ### Are these changes tested?
   
   Yes. `TestCasts/TestFloatingToIntOutOfRange` covers the boundary for int32 
and uint32 (from float32) and for int64 and uint64 (from float32 and float64), 
with int8, uint8 and int16 (from float16) as controls. It checks each value on 
its own and after a null, and checks that the largest representable in-range 
value and the minimum still cast. It also checks float16 `-0.0` → int32 `0`.
   
   - On main the new test fails on darwin/arm64 for float32→int32, 
float32→uint32, float32→int64, float32→uint64, float64→int64, float64→uint64 
and the float16 `-0.0` case. With `-tags noasm` (plain Go conversions instead 
of the NEON kernel), float32→uint32 already fails on main. With the fix it 
passes in both modes.
   - `go test -short -tags assert,test ./arrow/compute/... ./arrow/scalar/...` 
and the same with `assert,test,noasm`: ok (darwin/arm64)
   - `GOARCH=amd64 go test -short -tags assert,test ./arrow/compute/`: ok 
(under Rosetta)
   - `golangci-lint run ./compute/...` from `arrow/` (v2.13.2): 0 issues
   
   Not checked on a native linux/arm64 runner.
   
   ### Are there any user-facing changes?
   
   Yes, on arm64 a safe cast of these boundary values now returns an error, the 
same as on amd64. Unsafe casts (`AllowFloatTruncate`) are unchanged.
   


-- 
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]

Reply via email to