-
Notifications
You must be signed in to change notification settings - Fork 6.1k
8343829: Unify decimal and hexadecimal parsing in FloatingDecimal #22737
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
Conversation
👋 Welcome back rgiulietti! A progress list of the required criteria for merging this PR into |
@rgiulietti 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 29 new commits pushed to the
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 |
@rgiulietti The following label will be automatically applied to this pull request:
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. |
Webrevs
|
// private static final int BINARY_256_IX = 4; | ||
|
||
/* The precision of the format. */ | ||
private static final int[] P = { |
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.
What about organizing these constants as as a record - something like this:
record FloatFmt(int ix, int p, int epMin, int epMax, int w, int eMin, int eMax, int qMin, int hexCount) {
public static final FloatFmt BINARY_16 = build(0, 11, -8, 6);
public static final FloatFmt BINARY_32 = build(1, 24, -46, 40);
public static final FloatFmt BINARY_64 = build(2, 53, -324, 310);
public static final FloatFmt BINARY_128 = build(3, 113, -4_966, 4934);
public static final FloatFmt BINARY_256 = build(4, 237, -78_985, 78_915);
private static FloatFmt build(int ix, int p, int epMin, int epMax) {
int w = (1 << 4 + ix) - p;
int eMin = (-1 << w - 1) + 2;
int eMax = (1 << w - 1) - 1;
int qMin = eMin - p + 1;
int hexCount = p / 4 + 2;
return new FloatFmt(ix, p, epMin, epMax, w, eMin, eMax, qMin, hexCount);
}
}
Methods could then be parameterized with the static instances rather than integers. I believe these values would inline well as constants.
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 suggestion @j3graham.
I'll consider it for the next commits.
@rgiulietti This pull request has been inactive for more than 4 weeks and will be automatically closed if another 4 weeks passes without any activity. To avoid this, simply add a new comment to the pull request. Feel free to ask for assistance if you need help with progressing this pull request towards integration! |
@rgiulietti This pull request has been inactive for more than 8 weeks and will now be automatically closed. If you would like to continue working on this pull request in the future, feel free to reopen it! This can be done using the |
/open Still in review |
@rgiulietti This pull request is now open |
@rgiulietti This pull request has been inactive for more than 4 weeks and will be automatically closed if another 4 weeks passes without any activity. To avoid this, simply add a new comment to the pull request. Feel free to ask for assistance if you need help with progressing this pull request towards integration! |
Ping |
@rgiulietti This pull request has been inactive for more than 4 weeks and will be automatically closed if another 4 weeks passes without any activity. To avoid this, simply add a new comment to the pull request. Feel free to ask for assistance if you need help with progressing this pull request towards integration! |
Comment added... |
static final int BIG_DECIMAL_EXPONENT = 324; The BIG_DECIMAL_EXPONENT in line 50 is no longer used and can be removed. |
// private static final int BINARY_256_IX = 4; | ||
|
||
/* The precision of the format. */ | ||
private static final int[] P = { |
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.
private static final int[] P
private static final int[] EP_MIN
private static final int[] EP_MAX
private static final int[] W
private static final int[] E_MAX
private static final int[] E_MIN
private static final int[] Q_MIN
private static final int[] HEX_COUNT
These should all be added with @stable
We can do some cleanup before this PR, such as #24999 |
This is just the first step of a planned overhaul of conversions from decimal strings to floating-point values. There are more steps to come. |
Q_MIN -> E_MIN -> E_MAX -> W -> P Five layers of Stable, I don't know if C2 can work correctly, maybe need to confirm |
@wenshao Do you mean that C2 might generate erroneous code (bad situation!), or that it might not take advantage of |
I am worried that too many layers will cause C2 to not be optimized, but I am not sure, and I also hope to learn how to know that |
I'm not worried if C2 cannot optimize too many levels of |
If I understand correctly, we are talking about several (primitive) array type fields having a |
@jaikiran "Levels" in the sense that Q_MIN depends on E_MIN, which depends on E_MAX, which depends on W, which depends on P. |
Generally good cleanup @rgiulietti. I'd like to see some kind of representation of the grammar of strings being recognized included in this file, for example a cut-and-paste of the grammar from Double.valueOf(String) (with leading and trailing spaces):
|
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.
Took a look over the string parsing part. Not professional enough about floating numbers.
src/java.base/share/classes/jdk/internal/math/FloatingDecimal.java
Outdated
Show resolved
Hide resolved
src/java.base/share/classes/jdk/internal/math/FloatingDecimal.java
Outdated
Show resolved
Hide resolved
} | ||
|
||
/* | ||
* In some places the idiom |
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.
Might be easier to read the code if this logic were refactored into a method.
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.
Right.
I'll take this note into account in the next phase of the cleanup.
/integrate |
Going to push as commit d1032d7.
Your commit was automatically rebased without conflicts. |
@rgiulietti Pushed as commit d1032d7. 💡 You may see a message that your pull request was closed with unmerged commits. This can be safely ignored. |
See the JBS bug for some details.
Progress
Issue
Reviewers
Reviewing
Using
git
Checkout this PR locally:
$ git fetch https://git.openjdk.org/jdk.git pull/22737/head:pull/22737
$ git checkout pull/22737
Update a local copy of the PR:
$ git checkout pull/22737
$ git pull https://git.openjdk.org/jdk.git pull/22737/head
Using Skara CLI tools
Checkout this PR locally:
$ git pr checkout 22737
View PR using the GUI difftool:
$ git pr show -t 22737
Using diff file
Download this PR as a diff file:
https://git.openjdk.org/jdk/pull/22737.diff
Using Webrev
Link to Webrev Comment