-
Notifications
You must be signed in to change notification settings - Fork 5.8k
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
Conversation
👋 Welcome back darcy! A progress list of the required criteria for merging this PR into |
Webrevs
|
What about adding a link to this discussion in the doc for |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks fine.
@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:
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
Please see this link for an up-to-date comparison between the source branch of this pull request and the ➡️ To integrate this PR with the above commit message to the |
There was a problem hiding this 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)
* 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 |
There was a problem hiding this comment.
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."
There was a problem hiding this comment.
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.
* 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. |
There was a problem hiding this comment.
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 |
There was a problem hiding this comment.
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 |
There was a problem hiding this comment.
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: |
There was a problem hiding this comment.
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 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
* <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: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
* 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. |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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.
/integrate |
Add discussion of some of the common pitfalls related to decimal <-> binary conversion.
Progress
Issue
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