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

JDK-8295391: Add discussion of binary <-> decimal conversion issues #16566

Closed
wants to merge 12 commits into from

Conversation

jddarcy
Copy link
Member

@jddarcy jddarcy commented Nov 8, 2023

Add discussion of some of the common pitfalls related to decimal <-> binary conversion.


Progress

  • Change must be properly reviewed (1 review required, with at least 1 Reviewer)
  • Change must not contain extraneous whitespace
  • Commit message must refer to an issue

Issue

  • JDK-8295391: Add discussion of binary <-> decimal conversion issues (Enhancement - P4)

Reviewers

Reviewing

Using git

Checkout this PR locally:
$ git fetch https://git.openjdk.org/jdk.git pull/16566/head:pull/16566
$ git checkout pull/16566

Update a local copy of the PR:
$ git checkout pull/16566
$ git pull https://git.openjdk.org/jdk.git pull/16566/head

Using Skara CLI tools

Checkout this PR locally:
$ git pr checkout 16566

View PR using the GUI difftool:
$ git pr show -t 16566

Using diff file

Download this PR as a diff file:
https://git.openjdk.org/jdk/pull/16566.diff

Webrev

Link to Webrev Comment

@bridgekeeper
Copy link

bridgekeeper bot commented Nov 8, 2023

👋 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
Copy link

openjdk bot commented Nov 8, 2023

@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 core-libs-dev@openjdk.org label Nov 8, 2023
@openjdk openjdk bot added the rfr Pull request is ready for review label Nov 8, 2023
@mlbridge
Copy link

mlbridge bot commented Nov 8, 2023

@rgiulietti
Copy link
Contributor

What about adding a link to this discussion in the doc for j.l.Float? After all, the discussion contains many float examples.

Copy link
Member

@bplb bplb left a comment

Choose a reason for hiding this comment

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

Looks fine.

@openjdk
Copy link

openjdk bot commented Nov 8, 2023

@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:

8295391: Add discussion of binary <-> decimal conversion issues

Reviewed-by: 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 1 new commit pushed to the master branch:

  • 99570fb: 8320258: Refresh building.md

Please see this link for an up-to-date comparison between the source branch of this pull request and the master branch.
As there are no conflicts, your changes will automatically be rebased on top of these commits when integrating. If you prefer to avoid this 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 Pull request is ready to be integrated label Nov 8, 2023
Copy link
Contributor

@eirbjo eirbjo left a comment

Choose a reason for hiding this comment

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

Left some minor proofreading comments. (Not a Reviewer)

Comment on lines 205 to 209
* Many surprising aspects of binary floating-point arithmetic trace
* back to aspects of decimal to binary conversion and binary to
* decimal conversion. While integer values can be exactly represented
* in any base, which fractional values can be exactly represented is
* a function of the base. For example, in base 10, 1/3 is a repeating
Copy link
Contributor

Choose a reason for hiding this comment

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

Could the first sentence be simplified and "de-aspectized"? Suggestion: "..trace back to conversions between binary and decimal representations".

The second sentence has a suspicious while/which pairing and "represented is" should probably be "represented as". Suggestion: "While integer values can be exactly represented in any base, fractional values can only be exactly represented as a function of the base."

Copy link
Member Author

Choose a reason for hiding this comment

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

Thanks for the close reading; I made another few passes over the text based on your comments.

Comment on lines 241 to 243
* double}. Alternatives include using an integer type and storing
* cents or mills or using {@link java.math.BigDecimal BigDecimal} to
* store decimal fraction values exactly.
Copy link
Contributor

@eirbjo eirbjo Nov 8, 2023

Choose a reason for hiding this comment

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

The "and,or,or" sequence makes this sentence somewhat hard to parse. Perhaps a bit of punctuation could help readability?

* store decimal fraction values exactly.
*
* <p>For each finite floating-point value and a given floating-point
* type, there is a contiguous region of the real number line which
Copy link
Contributor

Choose a reason for hiding this comment

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

Neither English nor floating-point are native to me, but would it be better to use "region on the real number line" here?
A quick Google search of the alternatives gives 4 results for "region of.." and 22.000 for "region on.."

* <li>equal to the exact result
* </ul>
*
* A floating-point value doesn't "know" if it was the result of
Copy link
Contributor

Choose a reason for hiding this comment

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

Would it be better to use "whether" in this listing of alternatives? (As recommended by Merriam-Webster: https://www.merriam-webster.com/grammar/if-vs-whether-difference-usage)

* }
*
* should <em>not</em> be expected to be exactly equal to 1.0, but
* only close to 1.0. Consequently the following code is an infinite loop:
Copy link
Contributor

Choose a reason for hiding this comment

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

I think "Consequently" is a conjunctive adverb here, so should be followed by a comma. Or perhaps just drop it, since the previous sentence also starts with "Consequently, "

* Float.valueOf("0.100000005215406417846679687499999"); // rounds down to oneTenthApproxAsFloat
* }
*
* <p>An analogous range can be constructed similarly for the {@code
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
* <p>An analogous range can be constructed similarly for the {@code
* <p>Similarly, an analogous range can be constructed for the {@code

* }
* }
*
* Instead, for counted loops, use an integer loop count:
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
* Instead, for counted loops, use an integer loop count:
* Instead, use integer loop counters for counted loops:

@@ -749,7 +882,7 @@ public static String toHexString(double d) {
* @return a {@code Double} object holding the value
* represented by the {@code String} argument.
* @throws NumberFormatException if the string does not contain a
* parsable number.
Copy link
Member

Choose a reason for hiding this comment

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

Was parsable number supposed to be deleted?

Copy link
Member Author

Choose a reason for hiding this comment

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

My mistake in editing; I'll correct it. Thanks.

@jddarcy
Copy link
Member Author

jddarcy commented Nov 18, 2023

/integrate

@openjdk
Copy link

openjdk bot commented Nov 18, 2023

Going to push as commit 8ff7d6e.
Since your change was applied there has been 1 commit pushed to the master branch:

  • 99570fb: 8320258: Refresh building.md

Your commit was automatically rebased without conflicts.

@openjdk openjdk bot added the integrated Pull request has been integrated label Nov 18, 2023
@openjdk openjdk bot closed this Nov 18, 2023
@openjdk openjdk bot removed ready Pull request is ready to be integrated rfr Pull request is ready for review labels Nov 18, 2023
@openjdk
Copy link

openjdk bot commented Nov 18, 2023

@jddarcy Pushed as commit 8ff7d6e.

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

@jddarcy jddarcy deleted the JDK-8295391 branch October 27, 2024 18:36
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
core-libs core-libs-dev@openjdk.org integrated Pull request has been integrated
Development

Successfully merging this pull request may close these issues.

4 participants