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

8261862: Expand discussion of rationale for BigDecimal equals/compareTo semantics #2804

Closed
wants to merge 3 commits into from

Conversation

@jddarcy
Copy link
Member

@jddarcy jddarcy commented Mar 3, 2021

I considered @stuart-marks previous suggestion during the code review of JDK-8261123 to include a more explicit discussion of why, say, different representations of 2 should not be regarded as equivalent. After contemplating several alternatives, I didn't find anything simpler than Stuart's 2/3 example so I used that as seen in the diff.

A short digression, BigDecimal supports both fixed-point style and floating-point style rounding. Floating-point rounding primarily replies on the number of precision digits, regards of their scale, while fixed-point style rounding prioritizes the scale. The number of digits of eventual output is a function of number number of digits in the inputs and the number of precision digits in a floating-point style rounding. A floating-point style rounding has a preferred scale, rather than a fixed scale based on the inputs. The fixed-point style divide method used in the example has a scale based on the dividend, allowing a relatively simple expression to show a distinction between 2.0 and 2.00.


Progress

  • Change must not contain extraneous whitespace
  • Commit message must refer to an issue
  • Change must be properly reviewed

Issue

  • JDK-8261862: Expand discussion of rationale for BigDecimal equals/compareTo semantics

Reviewers

Download

$ git fetch https://git.openjdk.java.net/jdk pull/2804/head:pull/2804
$ git checkout pull/2804

@bridgekeeper
Copy link

@bridgekeeper bridgekeeper bot commented Mar 3, 2021

👋 Welcome back darcy! A progress list of the required criteria for merging this PR into master will be added to the body of your pull request. There are additional pull request commands available for use with this pull request.

@openjdk openjdk bot added the rfr label Mar 3, 2021
@openjdk
Copy link

@openjdk openjdk bot commented Mar 3, 2021

@jddarcy The following label will be automatically applied to this pull request:

  • core-libs

When this pull request is ready to be reviewed, an "RFR" email will be sent to the corresponding mailing list. If you would like to change these labels, use the /label pull request command.

@openjdk openjdk bot added the core-libs label Mar 3, 2021
@mlbridge
Copy link

@mlbridge mlbridge bot commented Mar 3, 2021

Webrevs

* method.
* method since the former has [{@code BigInteger},
* {@code scale}] components equal to [20, 1] while the latter has
* components equals to [200, 2].
Copy link
Member

@bplb bplb Mar 3, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

s/equals/equal/

Copy link
Member Author

@jddarcy jddarcy Mar 3, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed.

* {@code new BigDecimal("2.0" ).divide(BigDecimal.valueOf(3),
* HALF_UP)} which evaluates to 0.7 and <br>
* {@code new BigDecimal("2.00").divide(BigDecimal.valueOf(3),
* HALF_UP)} which evaluates to 0.<b>6</b>7.
*
Copy link
Member

@stuart-marks stuart-marks Mar 3, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should this be in an @apiNote?

I'm not sure adding the boldface 0.67 is helpful; 0.7 is self-evidently unequal to 0.67.

Copy link
Member Author

@jddarcy jddarcy Mar 3, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Changed as suggested in final version.

@openjdk
Copy link

@openjdk openjdk bot commented Mar 3, 2021

@jddarcy This change now passes all automated pre-integration checks.

ℹ️ This project also has non-automated pre-integration requirements. Please see the file CONTRIBUTING.md for details.

After integration, the commit message for the final commit will be:

8261862: Expand discussion of rationale for BigDecimal equals/compareTo semantics

Reviewed-by: smarks, bpb

You can use pull request commands such as /summary, /contributor and /issue to adjust it as needed.

At the time when this comment was updated there had been no new commits pushed to the master branch. If another commit should be pushed before you perform the /integrate command, your PR will be automatically rebased. If you prefer to avoid any potential automatic rebasing, please check the documentation for the /integrate command for further details.

➡️ To integrate this PR with the above commit message to the master branch, type /integrate in a new comment.

@openjdk openjdk bot added the ready label Mar 3, 2021
bplb
bplb approved these changes Mar 3, 2021
@jddarcy
Copy link
Member Author

@jddarcy jddarcy commented Mar 3, 2021

/integrate

@openjdk openjdk bot closed this Mar 3, 2021
@openjdk openjdk bot added integrated and removed ready rfr labels Mar 3, 2021
@openjdk
Copy link

@openjdk openjdk bot commented Mar 3, 2021

@jddarcy Pushed as commit a118185.

💡 You may see a message that your pull request was closed with unmerged commits. This can be safely ignored.

@jddarcy jddarcy deleted the 8261862 branch Jun 10, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
3 participants