-
Notifications
You must be signed in to change notification settings - Fork 234
Commit
The lowest value of an int64 is itself when negated, so the rest of the code kind of breaks down. Short circuit it to avoid all the problems. https://play.golang.org/p/AuAGwhJ69d Closes: #45
- Loading branch information
There are no files selected for viewing
Original file line number | Original file line | Diff line number | Diff line change |
---|---|---|---|
|
@@ -2,6 +2,7 @@ package humanize | ||
|
|
||
import ( | import ( | ||
"bytes" | "bytes" | ||
"math" | |||
"math/big" | "math/big" | ||
"strconv" | "strconv" | ||
"strings" | "strings" | ||
|
@@ -13,6 +14,12 @@ import ( | ||
// e.g. Comma(834142) -> 834,142 | // e.g. Comma(834142) -> 834,142 | ||
func Comma(v int64) string { | func Comma(v int64) string { | ||
sign := "" | sign := "" | ||
|
|||
// minin64 can't be negated to a usable value, so it has to be special cased. | |||
if v == math.MinInt64 { | |||
return "-9,223,372,036,854,775,808" | |||
} | |||
This comment has been minimized.
Sorry, something went wrong.
This comment has been minimized.
Sorry, something went wrong.
dustin
via email
Author
Owner
|
|||
|
|||
if v < 0 { | if v < 0 { | ||
sign = "-" | sign = "-" | ||
v = 0 - v | v = 0 - v | ||
|
As an observation, this special case could've been placed above the declaration of
sign
variable since it's unused.There's also a typo in "minin64".