aad1tyaaaaa opened a new issue, #1695:
URL: https://github.com/apache/arrow-go/issues/1695
### Describe the bug, including details regarding any error messages,
version, and platform.
With a negative scale, the decimal `FromString` functions check the
magnitude of the literal before the scale is applied, so values whose scaled
result fits are rejected:
```go
decimal.Decimal32FromString("5000000000", 2, -9) // stored value would be 5
decimal.Decimal64FromString("3e19", 1, -19) // 3
decimal128.FromString("2e38", 1, -38) // 2
decimal256.FromString("1e77", 1, -77) // 1
// all return "bitlen too large for decimalN"
```
A negative scale is how a decimal stores a large value in few digits, so
these look like inputs it should accept. Decimal64, decimal128 and decimal256
agree with each other until the literal reaches 2^64 / 2^128 / 2^256; Decimal32
already fails from 2^32, e.g. `"71432e+5"` at precision 8, scale -2 (stored as
71432000) is rejected by `Decimal32FromString` but accepted by the wider types.
The check is the `scale < 0` branch of `fromDecimalLiteral`
(`arrow/decimal/decimal.go`, `arrow/decimal128/decimal128.go`,
`arrow/decimal/decimal256.go`), which calls `lit.AtLeastTwoPower(0, nbits)`
instead of passing the scale as the positive-scale branch does. `TestBitLen`
and `TestFromStringScaleOutOfRange` currently assert this behaviour (for
example, 2^127 at scale -1 must fail with "bitlen too large", and `"1e40"` at
scale -39 must report "bitlen too large" rather than the out-of-range scale),
and the comment says the bound was kept to match the earlier `big.Float`
implementation.
Is this intended? If not, passing the scale to `AtLeastTwoPower` (it already
handles negative scales without allocating for huge exponents) accepts these
values; with that change the decimal tests fail only on the assertions above.
I'm happy to send a PR that makes the change and updates those tests.
Found with go1.27.3 on main (Windows/amd64); the code is platform
independent.
### Component(s)
Other
--
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]