vera-rubin opened a new pull request, #1663: URL: https://github.com/apache/arrow-go/pull/1663
### Rationale for this change Converting float64 values to decimal128 or decimal256 scales them with a float64 multiplication before rounding. At large scales that multiplication loses digits, so exact inputs come back changed without an error. For example, `1.0` converted to decimal(24, 23) gives `0.99999999999999991611392`, also through the default safe array cast: ```go n, err := decimal128.FromFloat64(1, 24, 23) fmt.Println(n.BigInt(), err) // want: 100000000000000000000000 <nil> ``` ### What changes are included in this PR? For scales from 0 to the type's maximum scale, `fromPositiveFloat64` (decimal128) and `fromPositiveFloat64_256` (decimal256) now take the exact binary value of the float64 as a `big.Rat`, multiply it by the power of ten with integers, round half to even, and then check the result against the precision. Negative scales keep the existing float path. ### Are these changes tested? Yes. `TestDecimalFromFloat64ExactScaling` checks both widths for values such as ±1 at (24, 23), ±12345678 at (26, 18), 0.125, 0.5 at the maximum scale, half-even rounding at (2, 1) and an overflow at (23, 23). `TestCasts/TestFloatingToDecimal` gets array cast cases for the same inputs. Both fail without the fix and pass with it; the decimal and `./arrow/compute/...` tests pass. One existing cast expectation changes: float64 `1.8446744073709556e+15` is exactly `1844674407370955.5`, so the decimal(20, 4) result is now `1844674407370955.5000` instead of `1844674407370955.5712`, where the extra digits came from the float multiplication. ### Are there any user-facing changes? Yes. Float64 to decimal conversions keep exact values at large scales, which can change the last digits of some existing results to the correctly rounded ones. -- 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]
