Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix NumDigits with ensureInitialized #301

Merged
merged 1 commit into from Dec 31, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 1 addition & 0 deletions decimal.go
Expand Up @@ -815,6 +815,7 @@ func (d Decimal) ExpTaylor(precision int32) (Decimal, error) {
// NumDigits returns the number of digits of the decimal coefficient (d.Value)
// Note: Current implementation is extremely slow for large decimals and/or decimals with large fractional part
func (d Decimal) NumDigits() int {
d.ensureInitialized()
// Note(mwoss): It can be optimized, unnecessary cast of big.Int to string
if d.IsNegative() {
return len(d.value.String()) - 1
Expand Down
1 change: 1 addition & 0 deletions decimal_test.go
Expand Up @@ -2764,6 +2764,7 @@ func TestDecimal_NumDigits(t *testing.T) {
{"-5.26", 3},
{"-5.2663117716", 11},
{"-26.1", 3},
{"", 1},
} {
d, _ := NewFromString(testCase.Dec)

Expand Down