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

Why is Zero defined not as New(0, 0) but as New(0, 1)? #372

Open
your-diary opened this issue Jun 19, 2024 · 2 comments
Open

Why is Zero defined not as New(0, 0) but as New(0, 1)? #372

your-diary opened this issue Jun 19, 2024 · 2 comments

Comments

@your-diary
Copy link

your-diary commented Jun 19, 2024

I'm interested in the design decision just for curiosity.

Also, if

The zero-value of a Decimal is 0, as you would expect. (source)

, can't it be defined as Decimal{}?

@EVODelavega
Copy link

The exponent doesn't really matter when it comes to zero values, if you look at the implementation of the IsZero method, you'll see that it returns d.Sign() == 0, where sign can either be -1 or +1 for positive/negative numbers, and 0 for zero. As for the question about zero being possibly defined as Decimal{}: the nil value of the Decimal type is zero, which you can easily check like so:

d := shopspring.Decimal{}
fmt.Println(d.IsZero()) // prints true

@arvenil
Copy link

arvenil commented Aug 20, 2024

I also don't understand why Zero is defined as

var Zero = New(0, 1)

instead of

var Zero Decimal

What's the point of Zero if we can (and should?) use Decimal{}?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants