Don't mutate big comma parameter
Fixes #130
diff --git a/comma.go b/comma.go
index 9bd66ae..6636340 100644
--- a/comma.go
+++ b/comma.go
@@ -100,7 +100,8 @@
// BigComma produces a string form of the given big.Int in base 10
// with commas after every three orders of magnitude.
-func BigComma(b *big.Int) string {
+func BigComma(bin *big.Int) string {
+ b := new(big.Int).Set(bin)
sign := ""
if b.Sign() < 0 {
sign = "-"
diff --git a/comma_test.go b/comma_test.go
index c37a518..612a242 100644
--- a/comma_test.go
+++ b/comma_test.go
@@ -143,3 +143,14 @@
}
}
}
+
+func TestHumanizeBigIntMutation(t *testing.T) {
+ value := big.NewInt(1000000)
+ value = value.Mul(value, value)
+ expected := BigComma(value)
+ actual := BigComma(value)
+ if expected != actual {
+ t.Log(expected, " != ", actual)
+ t.Fail()
+ }
+}