mirror of
https://github.com/shopspring/decimal.git
synced 2024-11-23 04:40:49 +01:00
Merge pull request #17 from cockroachdb/nvanbenschoten/int_overflow
Prevent unnecessary int64 overflow in NewFromFloat
This commit is contained in:
commit
873b9ea5ed
2 changed files with 2 additions and 1 deletions
|
@ -140,7 +140,7 @@ func NewFromFloat(value float64) Decimal {
|
||||||
floor := math.Floor(value)
|
floor := math.Floor(value)
|
||||||
|
|
||||||
// fast path, where float is an int
|
// 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)
|
return New(int64(value), 0)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -31,6 +31,7 @@ var testTable = map[float64]string{
|
||||||
.1000000000000003: "0.1000000000000003",
|
.1000000000000003: "0.1000000000000003",
|
||||||
.1000000000000005: "0.1000000000000005",
|
.1000000000000005: "0.1000000000000005",
|
||||||
.1000000000000008: "0.1000000000000008",
|
.1000000000000008: "0.1000000000000008",
|
||||||
|
1e25: "10000000000000000000000000",
|
||||||
}
|
}
|
||||||
|
|
||||||
var testTableScientificNotation = map[string]string{
|
var testTableScientificNotation = map[string]string{
|
||||||
|
|
Loading…
Reference in a new issue