-
Notifications
You must be signed in to change notification settings - Fork 75
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
BigDecimal equality using compareTo #540
Comments
Hi! Good point, for some reason I've never considered BigDecimal really well. I completely agree with your assessment. And I have to say, I'm impressed with the detail of your proposal. The implementation looks really nice, and you even added a manual page! I wish more people would do that :). I do have a small doubt though: I feel like I think keeping it specific to BigDecimal is fine, at least for now. What do you think? |
Hi :) Making this the default with the option to suppress sounds good to me. I can make the changes and raise a PR for review? Do you need me to enable workflows to get some kind of green build? I actually did it that way to start with but haven't worked on a truly public API or tried contributing before so was more cautious; thinking that adding it as configuration means it won't break anyone's existing tests and maybe few people care if this hasn't come up before. Specific to |
I would very much appreciate a PR, if you're willing to do it! When you open the PR, I have to approve the workflow run for new committers such as yourself, so that might take a little time. If you want to know sooner if it will be green, you can run I always feel bad when someone comes with a PR they've clearly put a lot of work in, to ask for a lot of re-work. I hope you didn't mind :). I'm always open to discussing these things before you actually start putting the work in, though. I think most open source maintainers are. In any event, thanks for doing this, I look forward to your PR! |
Thanks again for the nice PR! Version 3.8 is now syncing with Maven Central. |
Is your feature request related to a problem? Please describe.
BigDecimal
can be used when exact decimal numbers are required rather thanfloat
ordouble
floating point numbers which cannot represent all numbers exactly. When used as fields, if you want1.0
to be considered equal to1
or1.00
then theequals
method of the class containing the field should check equality of these fields usingcompareTo
and ensure the same hashcode is used for all variants. There is currently not support in EqualsVerifier for checking this has been implemented correctly. So using EqualsVerifier alone is not enough for this use case.Describe the solution you'd like
Ability to configure EqualsVerifier to give confidence that
equals
andhashCode
are sufficient for two objects to be equal when any of theirBigDecimal
fields have the same numerical values even if theBigDecimal
representation is unequal (due to number of decimal places).Describe alternatives you've considered
Additional context
usingBigDecimalCompareTo()
.BigDecimalFieldCheck
is quite generic, the part specific toBigDecimal
is this line to mutate the scale. Maybe this is a better approach as would support any other types that have inconsistency betweencompareTo
andequals
. Having said that,BigDecimal
is the only type where I've had this problem.The text was updated successfully, but these errors were encountered: