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

Decimal value of zero obtained from subtraction does not equal to other zero values #10

Closed
mdawar opened this issue Oct 16, 2024 · 0 comments

Comments

@mdawar
Copy link
Contributor

mdawar commented Oct 16, 2024

If we subtract the same values, the result value is not reported as equal to other zero values by the Cmp and Equal methods and the direct == equality operator, this is due to the result having the field neg set to true after the subtraction.

package main

import (
	"fmt"

	"github.com/quagmt/udecimal"
)

func main() {
	zero := udecimal.MustParse("1").Sub(udecimal.MustParse("1"))

	fmt.Println(zero.IsZero())             // true
	fmt.Println(udecimal.Zero == zero)     // false
	fmt.Println(zero.Cmp(udecimal.Zero))   // -1
	fmt.Println(zero.Equal(udecimal.Zero)) // false
}
@mdawar mdawar changed the title Decimal value zero obtained form subtraction does not equal to other zero values Decimal value of zero obtained from subtraction does not equal to other zero values Oct 16, 2024
mdawar added a commit to mdawar/udecimal that referenced this issue Oct 16, 2024
@quagmt quagmt closed this as completed Oct 17, 2024
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

2 participants