MCPcopy Create free account
hub / github.com/cockroachdb/apd / TestNumDigitsLargeNegative

Function TestNumDigitsLargeNegative

table_test.go:179–200  ·  view source on GitHub ↗

TestNumDigitsLargeNegative is a regression test for a bug where NumDigits would panic with a nil pointer dereference when processing large negative numbers (more than 128 bits). Seen in https://github.com/cockroachdb/cockroach/issues/165525.

(t *testing.T)

Source from the content-addressed store, hash-verified

177// numbers (more than 128 bits). Seen in
178// https://github.com/cockroachdb/cockroach/issues/165525.
179func TestNumDigitsLargeNegative(t *testing.T) {
180 // Create a BigInt directly with more than 128 bits.
181 var b BigInt
182 b.SetInt64(2)
183 exp := NewBigInt(200)
184 b.Exp(&b, exp, nil)
185 b.Neg(&b)
186
187 numDigits := NumDigits(&b)
188 // 2^200 has 61 decimal digits.
189 expectedDigits := int64(61)
190 if numDigits != expectedDigits {
191 t.Errorf("expected %d digits, got %d", expectedDigits, numDigits)
192 }
193
194 // Also test via Decimal.
195 d := NewWithBigInt(&b, 0)
196 numDigits2 := d.NumDigits()
197 if numDigits2 != expectedDigits {
198 t.Errorf("expected %d digits via Decimal, got %d", expectedDigits, numDigits2)
199 }
200}

Callers

nothing calls this directly

Calls 7

SetInt64Method · 0.95
ExpMethod · 0.95
NegMethod · 0.95
NewBigIntFunction · 0.85
NumDigitsFunction · 0.85
NewWithBigIntFunction · 0.85
NumDigitsMethod · 0.80

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…