From b1136ef9bc3b1a978f78ac5e2ddb86d21c913e0e Mon Sep 17 00:00:00 2001
From: ko_oler <kooler89@gmail.com>
Date: Wed, 4 Oct 2023 21:10:14 +0300
Subject: [PATCH] =?UTF-8?q?=D0=BF=D1=80=D0=B0=D0=B2=D0=BA=D0=B8=20=D0=BF?=
 =?UTF-8?q?=D0=BE=20=D0=9F=D0=A0:=20=D0=B8=D0=BD=D1=82=D0=B5=D1=80=D0=B2?=
 =?UTF-8?q?=D0=B0=D0=BB=20=D0=BE=D1=82=20-1<<53+1=20=D0=B4=D0=BE=201<<53-1?=
 =?UTF-8?q?.?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

---
 pkg/schema/field/number.go      |  6 ++++--
 pkg/schema/field/number_test.go | 22 ++++++++++++----------
 2 files changed, 16 insertions(+), 12 deletions(-)

diff --git a/pkg/schema/field/number.go b/pkg/schema/field/number.go
index 00c264a2..de96a3f6 100644
--- a/pkg/schema/field/number.go
+++ b/pkg/schema/field/number.go
@@ -10,6 +10,8 @@ import (
 const (
 	NumberFormatInt   = "int"
 	NumberFormatFloat = "float"
+	maxInt            = 1<<53 - 1
+	minInt            = -1<<53 + 1
 )
 
 var numberType = &NumberType{}
@@ -88,8 +90,8 @@ func (NumberType) decode(_ context.Context, field *Field, v interface{}) (interf
 		case uint64:
 			return i, nil
 		case float64:
-			if i >= math.MaxInt64 || i <= math.MinInt64 {
-				return nil, errors.Errorf("the passed value %f must be no more than %d and no less than %d", i, math.MaxInt64, math.MinInt64)
+			if i > maxInt || i < minInt {
+				return nil, errors.Errorf("the passed value %f must be in the range from %d to %d", i, maxInt, minInt)
 			}
 			return int64(math.Round(i)), nil
 		}
diff --git a/pkg/schema/field/number_test.go b/pkg/schema/field/number_test.go
index 82a4c219..907291cc 100644
--- a/pkg/schema/field/number_test.go
+++ b/pkg/schema/field/number_test.go
@@ -22,17 +22,19 @@ func TestNumberField_Decode(t *testing.T) {
 		{"Correct", Number("int"), 2.6, int64(3), false},                                         // #5
 		{"MaxInt64", Number(NumberFormatInt), int64(math.MaxInt64), int64(math.MaxInt64), false}, // #6
 		{"MinInt64", Number(NumberFormatInt), int64(math.MinInt64), int64(math.MinInt64), false}, // #7
-		{"Convert error", Number(NumberFormatInt), math.MaxFloat64, nil, true},                   // #8
-		{"Convert error", Number(NumberFormatInt), -9223372036854776000.0, nil, true},            // #9
-		{"Convert error", Number(NumberFormatInt), 9223372036854776000.0, nil, true},             // #10
-		{"Convert error", Number(NumberFormatInt), float64(math.MaxInt64), nil, true},            // #11
-		{"Convert error", Number(NumberFormatInt), float64(math.MinInt64), nil, true},            // #12
+		{"maxInt in float", Number(NumberFormatInt), float64(maxInt), int64(maxInt), false},      // #8
+		{"minInt in float", Number(NumberFormatInt), float64(minInt), int64(minInt), false},      // #9
+		{"Convert error", Number(NumberFormatInt), math.MaxFloat64, nil, true},                   // #10
+		{"Convert error", Number(NumberFormatInt), -9223372036854776000.0, nil, true},            // #11
+		{"Convert error", Number(NumberFormatInt), 9223372036854776000.0, nil, true},             // #12
+		{"Convert error", Number(NumberFormatInt), float64(math.MaxInt64), nil, true},            // #13
+		{"Convert error", Number(NumberFormatInt), float64(math.MinInt64), nil, true},            // #14
 
-		{"Correct", Number("float"), int8(2), 2.0, false},                    // #13
-		{"Correct", Number("float"), 2.2, 2.2, false},                        // #14
-		{"Correct", Number("float"), 2, 2.0, false},                          // #15
-		{"Correct", Number("float"), float32(2.2), 2.200000047683716, false}, // #16
-		{"Correct", Number("float"), int64(2), 2.0, false},                   // #17
+		{"Correct", Number("float"), int8(2), 2.0, false},                    // #15
+		{"Correct", Number("float"), 2.2, 2.2, false},                        // #16
+		{"Correct", Number("float"), 2, 2.0, false},                          // #17
+		{"Correct", Number("float"), float32(2.2), 2.200000047683716, false}, // #18
+		{"Correct", Number("float"), int64(2), 2.0, false},                   // #19
 
 		{"Wrong data", Number("int"), "", nil, true},         // #0
 		{"Wrong data", Number("int"), []byte(""), nil, true}, // #1
-- 
GitLab