From eae6d13435116dfc37038a23537ecb24c1a474b8 Mon Sep 17 00:00:00 2001 From: Nathan VanBenschoten Date: Wed, 13 Jan 2016 13:27:32 -0500 Subject: [PATCH] Prevent unnecessary int64 overflow in NewFromFloat --- decimal.go | 2 +- decimal_test.go | 1 + 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/decimal.go b/decimal.go index cbbce7b..9f62fea 100644 --- a/decimal.go +++ b/decimal.go @@ -140,7 +140,7 @@ func NewFromFloat(value float64) Decimal { floor := math.Floor(value) // fast path, where float is an int - if floor == value && !math.IsInf(value, 0) { + if floor == value && value <= math.MaxInt64 && value >= math.MinInt64 { return New(int64(value), 0) } diff --git a/decimal_test.go b/decimal_test.go index e560ffb..f3169f3 100644 --- a/decimal_test.go +++ b/decimal_test.go @@ -31,6 +31,7 @@ var testTable = map[float64]string{ .1000000000000003: "0.1000000000000003", .1000000000000005: "0.1000000000000005", .1000000000000008: "0.1000000000000008", + 1e25: "10000000000000000000000000", } var testTableScientificNotation = map[string]string{