kuerbiskarton opened a new issue, #38395:
URL: https://github.com/apache/arrow/issues/38395

   ### Describe the bug, including details regarding any error messages, 
version, and platform.
   
   There are rounding errors when constructing decimal256 values from string 
and when serializing them to string.
   
   Affected version: main branch, v13 (maybe even older versions).
   
   Similar issues were already reported in the past 
(https://github.com/apache/arrow/issues/35310).
   
   ```
   func TestFromString(t *testing.T) {
        const decStr = 
"11111111111111111111111111111111111111.00000000000000000000000000000000000000"
   
        num, err := decimal256.FromString(decStr, 76, 38)
        if err != nil {
                t.Error(err)
        } else if decStr != num.ToString(38) {
                t.Errorf("expected: %s, actual: %s\n", decStr, num.ToString(38))
   
                actualCoeff := num.BigInt()
                expectedCoeff, _ := 
(&big.Int{}).SetString(strings.Replace(decStr, ".", "", -1), 10)
                t.Errorf("expected(hex): %X, actual(hex): %X\n", 
expectedCoeff.Bytes(), actualCoeff.Bytes())
        }
   }
   ```
   fails with
   ```
   expected: 
11111111111111111111111111111111111111.00000000000000000000000000000000000000
   actual:   
11111111111111110860978869272892669951.88888888888888889139021130727107330048
   
   expected(hex): 
0274DDD9AC9F3B4D00D24CF6A80B3D7F3DCD982490C8B30EE27EDFC000000000
   actual(hex):   
0274DDD9AC9F3B4904B40E1450CD9B8435D513ED4B465C000000000000000000
   ```
   
   The hex numbers show that the error is in the FromString function.
   
   
   However, there are also rounding issues in the ToString function:
   
   ```
   func TestToString(t *testing.T) {
        const decStr = 
"3379334159166193114608287418738414931564221155305735605033949613740461239999"
   
        integer, _ := (&big.Int{}).SetString(decStr, 10)
        dec := decimal256.FromBigInt(integer)
   
        expected := "0." + decStr
        actual := dec.ToString(76)
   
        if expected != actual {
                t.Errorf("expected: %s, actual: %s\n", expected, actual)
        }
   }
   ```
   fails with
   ```
   expected: 
0.3379334159166193114608287418738414931564221155305735605033949613740461239999
   actual:   
0.3379334159166193114608287418738414931564221155305735605033949613740461240000
   ```
   
   
   In case of ToString it seem to be off-by-one errors only.
   
   
   ### Component(s)
   
   Go


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