hcrosse commented on code in PR #1515:
URL: https://github.com/apache/arrow-go/pull/1515#discussion_r4530764149


##########
arrow/decimal128/decimal128.go:
##########
@@ -282,14 +283,35 @@ func FromString(v string, prec, scale int32) (n Num, err 
error) {
                        return Num{}, errors.New("bitlen too large for 
decimal128")
                }
                n = FromBigInt(val)
-               n, _ = n.Div(scaleMultipliers[-scale])
+               if scale >= -MaxScale {
+                       n, _ = n.Div(scaleMultipliers[-scale])
+               } else {
+                       // |n| < 2^127 < 10^39, so the quotient is zero.
+                       n = Num{}
+               }
        } else {
                // Since we're going to truncate this to get an integer, we 
need to round
                // the value instead because of edge cases so that we match how 
other implementations
                // (e.g. C++) handles Decimal values. So if we're negative 
we'll subtract 0.5 and if
                // we're positive we'll add 0.5.
-               p := (&big.Float{}).SetInt(scaleMultipliers[scale].BigInt())
-               out.SetPrec(precInBits).Mul(out, p)
+               if scale <= MaxScale {
+                       p := 
(&big.Float{}).SetInt(scaleMultipliers[scale].BigInt())
+                       out.SetPrec(precInBits).Mul(out, p)
+               } else {
+                       pow10.Mul(out.SetPrec(precInBits), int64(scale), 128+64)

Review Comment:
   This is existing behavior, not something the path past the table adds. 
`FromString` parses into a `big.Float` before scaling, so an exact decimal tie 
can land just below one half at any scale. Main already returns 3 for 
`decimal128.FromString("0.35", 38, 1)`. Resolving ties from the decimal text 
would change results inside the tables for all four widths, so it is out of 
scope for this PR.



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