From 8c526f06d030f44faca5d392ef6ba2ec9b21d398 Mon Sep 17 00:00:00 2001 From: Oleg Jukovec Date: Fri, 18 Nov 2022 17:36:31 +0300 Subject: [PATCH] bugfix: decimal uses a test variable The patch replaces usage of a test variable DecimalPrecision by a package-level variable decimalPrecision in the decimal package code. --- CHANGELOG.md | 5 ++++- decimal/decimal.go | 8 ++++---- 2 files changed, 8 insertions(+), 5 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 4fb75664b..2393216de 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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 @@ -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) diff --git a/decimal/decimal.go b/decimal/decimal.go index 44e192efc..cda08c12e 100644 --- a/decimal/decimal.go +++ b/decimal/decimal.go @@ -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()