Skip to content

Commit

Permalink
Don't use math.Pow(...) due to precision loss w/ large scale.
Browse files Browse the repository at this point in the history
  • Loading branch information
Tang8330 committed Jun 17, 2024
1 parent c1190eb commit 5fde6d7
Showing 1 changed file with 2 additions and 3 deletions.
5 changes: 2 additions & 3 deletions lib/debezium/decimal.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package debezium

import (
"fmt"
"math"
"math/big"

"github.com/artie-labs/transfer/lib/typing/decimal"
Expand All @@ -15,8 +14,8 @@ func EncodeDecimal(value string, scale int) ([]byte, error) {
return nil, fmt.Errorf("unable to use %q as a floating-point number", value)
}

scaledValue := big.NewFloat(math.Pow(10, float64(scale)))
bigFloatValue.Mul(bigFloatValue, scaledValue)
scaledValue := new(big.Int).Exp(big.NewInt(10), big.NewInt(int64(scale)), nil)
bigFloatValue.Mul(bigFloatValue, new(big.Float).SetInt(scaledValue))

// Extract the scaled integer value.
bigIntValue := new(big.Int)
Expand Down

0 comments on commit 5fde6d7

Please sign in to comment.