Skip to content

Commit

Permalink
bugfix: decimal uses a test variable
Browse files Browse the repository at this point in the history
The patch replaces usage of a test variable DecimalPrecision by
a package-level variable decimalPrecision in the decimal package
code.
  • Loading branch information
oleg-jukovec committed Nov 22, 2022
1 parent 7d4b3cc commit 8c526f0
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 5 deletions.
5 changes: 4 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,9 @@ Versioning](http://semver.org/spec/v2.0.0.html) except to the first release.

### Fixed

- Decimal package uses a test variable DecimalPrecision instead of a
package-level variable decimalPrecision (#233)

## [1.9.0] - 2022-11-02

The release adds support for the latest version of the
Expand All @@ -40,7 +43,7 @@ switching.
- A connection is still opened after ConnectionPool.Close() (#208)
- Future.GetTyped() after Future.Get() does not decode response
correctly (#213)
- Decimal package use a test function GetNumberLength instead of a
- Decimal package uses a test function GetNumberLength instead of a
package-level function getNumberLength (#219)
- Datetime location after encode + decode is unequal (#217)
- Wrong interval arithmetic with timezones (#221)
Expand Down
8 changes: 4 additions & 4 deletions decimal/decimal.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,13 +58,13 @@ func NewDecimalFromString(src string) (result *Decimal, err error) {
// MarshalMsgpack serializes the Decimal into a MessagePack representation.
func (decNum *Decimal) MarshalMsgpack() ([]byte, error) {
one := decimal.NewFromInt(1)
maxSupportedDecimal := decimal.New(1, DecimalPrecision).Sub(one) // 10^DecimalPrecision - 1
minSupportedDecimal := maxSupportedDecimal.Neg().Sub(one) // -10^DecimalPrecision - 1
maxSupportedDecimal := decimal.New(1, decimalPrecision).Sub(one) // 10^decimalPrecision - 1
minSupportedDecimal := maxSupportedDecimal.Neg().Sub(one) // -10^decimalPrecision - 1
if decNum.GreaterThan(maxSupportedDecimal) {
return nil, fmt.Errorf("msgpack: decimal number is bigger than maximum supported number (10^%d - 1)", DecimalPrecision)
return nil, fmt.Errorf("msgpack: decimal number is bigger than maximum supported number (10^%d - 1)", decimalPrecision)
}
if decNum.LessThan(minSupportedDecimal) {
return nil, fmt.Errorf("msgpack: decimal number is lesser than minimum supported number (-10^%d - 1)", DecimalPrecision)
return nil, fmt.Errorf("msgpack: decimal number is lesser than minimum supported number (-10^%d - 1)", decimalPrecision)
}

strBuf := decNum.String()
Expand Down

0 comments on commit 8c526f0

Please sign in to comment.